Skip to content

Commit 56326db

Browse files
committed
1 parent d3ff38c commit 56326db

File tree

3 files changed

+50
-38
lines changed

3 files changed

+50
-38
lines changed

rdflib/plugins/sparql/algebra.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from rdflib.plugins.sparql.operators import (
1818
and_, TrueFilter, simplify as simplifyFilters)
1919
from rdflib.plugins.sparql.paths import (
20-
InvPath, AlternativePath, SequencePath, ModPath, NegatedPath)
20+
InvPath, AlternativePath, SequencePath, MulPath, NegatedPath)
2121

2222
from pyparsing import ParseResults
2323

@@ -171,9 +171,9 @@ def translatePath(p):
171171
if len(p.part) != 1:
172172
raise Exception('Denkfehler!')
173173

174-
return ModPath(p.part[0], p.mod)
174+
return MulPath(p.part[0], p.mod)
175175
else:
176-
return ModPath(p.part, p.mod)
176+
return MulPath(p.part, p.mod)
177177

178178
elif p.name == 'PathEltOrInverse':
179179
if isinstance(p.part, list):

rdflib/plugins/sparql/paths.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@
5454
>>> foaf.name|foaf.firstName
5555
Path(http://xmlns.com/foaf/0.1/name | http://xmlns.com/foaf/0.1/firstName)
5656
57-
Modifiers (?, *, +) are done using % and the strings '*', '?', '+', also
58-
defined as constants in this file
57+
Modifiers (?, *, +) are done using * (the multiplication operator) and
58+
the strings '*', '?', '+', also defined as constants in this file.
5959
60-
>>> foaf.knows%OneOrMore
60+
>>> foaf.knows*OneOrMore
6161
Path(http://xmlns.com/foaf/0.1/knows+)
6262
6363
The path objects can be used with the normal graph methods.
@@ -86,7 +86,7 @@
8686
8787
Graph generator functions, triples, subjects, objects, etc. :
8888
89-
>>> list(g.objects(e.c, (e.p3%OneOrMore)/e.p2)) #doctest: +NORMALIZE_WHITESPACE
89+
>>> list(g.objects(e.c, (e.p3*OneOrMore)/e.p2)) #doctest: +NORMALIZE_WHITESPACE
9090
[rdflib.term.URIRef(
9191
u'ex:j'), rdflib.term.URIRef(u'ex:g'), rdflib.term.URIRef(u'ex:f')]
9292
@@ -98,12 +98,12 @@
9898
True
9999
>>> list(evalPath(g, (e.c, ~e.p1, None))) == [ (e.c, e.a) ]
100100
True
101-
>>> list(evalPath(g, (e.a, e.p1%ZeroOrOne, None))) == [(e.a, e.a), (e.a, e.c)]
101+
>>> list(evalPath(g, (e.a, e.p1*ZeroOrOne, None))) == [(e.a, e.a), (e.a, e.c)]
102102
True
103-
>>> list(evalPath(g, (e.c, e.p3%OneOrMore, None))) == [
103+
>>> list(evalPath(g, (e.c, e.p3*OneOrMore, None))) == [
104104
... (e.c, e.g), (e.c, e.h), (e.c, e.a)]
105105
True
106-
>>> list(evalPath(g, (e.c, e.p3%ZeroOrMore, None))) == [(e.c, e.c),
106+
>>> list(evalPath(g, (e.c, e.p3*ZeroOrMore, None))) == [(e.c, e.c),
107107
... (e.c, e.g), (e.c, e.h), (e.c, e.a)]
108108
True
109109
>>> list(evalPath(g, (e.a, -e.p1, None))) == [(e.a, e.f)]
@@ -117,24 +117,24 @@
117117
>>> list(evalPath(g, (e.a, e.p1/e.p3/e.p3, None))) == [(e.a, e.h)]
118118
True
119119
120-
>>> list(evalPath(g, (e.q, e.px%OneOrMore, None)))
120+
>>> list(evalPath(g, (e.q, e.px*OneOrMore, None)))
121121
[(rdflib.term.URIRef('ex:q'), rdflib.term.URIRef('ex:q'))]
122122
123123
>>> list(evalPath(g, (None, e.p1|e.p2, e.c)))
124124
[(rdflib.term.URIRef('ex:a'), rdflib.term.URIRef('ex:c'))]
125125
126126
>>> list(evalPath(g, (None, ~e.p1, e.a))) == [ (e.c, e.a) ]
127127
True
128-
>>> list(evalPath(g, (None, e.p1%ZeroOrOne, e.c))) # doctest: +NORMALIZE_WHITESPACE
128+
>>> list(evalPath(g, (None, e.p1*ZeroOrOne, e.c))) # doctest: +NORMALIZE_WHITESPACE
129129
[(rdflib.term.URIRef('ex:c'), rdflib.term.URIRef('ex:c')),
130130
(rdflib.term.URIRef('ex:a'), rdflib.term.URIRef('ex:c'))]
131131
132-
>>> list(evalPath(g, (None, e.p3%OneOrMore, e.a))) # doctest: +NORMALIZE_WHITESPACE
132+
>>> list(evalPath(g, (None, e.p3*OneOrMore, e.a))) # doctest: +NORMALIZE_WHITESPACE
133133
[(rdflib.term.URIRef('ex:h'), rdflib.term.URIRef('ex:a')),
134134
(rdflib.term.URIRef('ex:g'), rdflib.term.URIRef('ex:a')),
135135
(rdflib.term.URIRef('ex:c'), rdflib.term.URIRef('ex:a'))]
136136
137-
>>> list(evalPath(g, (None, e.p3%ZeroOrMore, e.a))) # doctest: +NORMALIZE_WHITESPACE
137+
>>> list(evalPath(g, (None, e.p3*ZeroOrMore, e.a))) # doctest: +NORMALIZE_WHITESPACE
138138
[(rdflib.term.URIRef('ex:a'), rdflib.term.URIRef('ex:a')),
139139
(rdflib.term.URIRef('ex:h'), rdflib.term.URIRef('ex:a')),
140140
(rdflib.term.URIRef('ex:g'), rdflib.term.URIRef('ex:a')),
@@ -151,14 +151,14 @@
151151
>>> list(evalPath(g, (None, e.p1/e.p3/e.p3, e.h))) == [(e.a, e.h)]
152152
True
153153
154-
>>> list(evalPath(g, (e.q, e.px%OneOrMore, None))) #doctest: +NORMALIZE_WHITESPACE
154+
>>> list(evalPath(g, (e.q, e.px*OneOrMore, None)))
155155
[(rdflib.term.URIRef('ex:q'), rdflib.term.URIRef('ex:q'))]
156156
157-
>>> list(evalPath(g, (e.c, (e.p2|e.p3)%ZeroOrMore, e.j)))
157+
>>> list(evalPath(g, (e.c, (e.p2|e.p3)*ZeroOrMore, e.j)))
158158
[(rdflib.term.URIRef('ex:c'), rdflib.term.URIRef('ex:j'))]
159159
160160
No vars specified
161-
>>> sorted(list(evalPath(g, (None, e.p3%OneOrMore, None)))) #doctest: +NORMALIZE_WHITESPACE
161+
>>> sorted(list(evalPath(g, (None, e.p3*OneOrMore, None)))) #doctest: +NORMALIZE_WHITESPACE
162162
[(rdflib.term.URIRef('ex:c'), rdflib.term.URIRef('ex:a')),
163163
(rdflib.term.URIRef('ex:c'), rdflib.term.URIRef('ex:g')),
164164
(rdflib.term.URIRef('ex:c'), rdflib.term.URIRef('ex:h')),
@@ -228,10 +228,10 @@
228228
>>> foaf.name|foaf.firstName
229229
Path(http://xmlns.com/foaf/0.1/name | http://xmlns.com/foaf/0.1/firstName)
230230
231-
Modifiers (?, *, +) are done using % and the strings '*', '?', '+', also
232-
defined as constants in this file
231+
Modifiers (?, *, +) are done using * (the multiplication operator) and
232+
the strings '*', '?', '+', also defined as constants in this file.
233233
234-
>>> foaf.knows%OneOrMore
234+
>>> foaf.knows*OneOrMore
235235
Path(http://xmlns.com/foaf/0.1/knows+)
236236
237237
The path objects can be used with the normal graph methods.
@@ -260,7 +260,7 @@
260260
261261
Graph generator functions, triples, subjects, objects, etc. :
262262
263-
>>> list(g.objects(e.c, (e.p3%OneOrMore)/e.p2)) #doctest: +NORMALIZE_WHITESPACE
263+
>>> list(g.objects(e.c, (e.p3*OneOrMore)/e.p2)) #doctest: +NORMALIZE_WHITESPACE
264264
[rdflib.term.URIRef(
265265
u'ex:j'), rdflib.term.URIRef(u'ex:g'), rdflib.term.URIRef(u'ex:f')]
266266
@@ -272,12 +272,12 @@
272272
True
273273
>>> list(evalPath(g, (e.c, ~e.p1, None))) == [ (e.c, e.a) ]
274274
True
275-
>>> list(evalPath(g, (e.a, e.p1%ZeroOrOne, None))) == [(e.a, e.a), (e.a, e.c)]
275+
>>> list(evalPath(g, (e.a, e.p1*ZeroOrOne, None))) == [(e.a, e.a), (e.a, e.c)]
276276
True
277-
>>> list(evalPath(g, (e.c, e.p3%OneOrMore, None))) == [
277+
>>> list(evalPath(g, (e.c, e.p3*OneOrMore, None))) == [
278278
... (e.c, e.g), (e.c, e.h), (e.c, e.a)]
279279
True
280-
>>> list(evalPath(g, (e.c, e.p3%ZeroOrMore, None))) == [(e.c, e.c),
280+
>>> list(evalPath(g, (e.c, e.p3*ZeroOrMore, None))) == [(e.c, e.c),
281281
... (e.c, e.g), (e.c, e.h), (e.c, e.a)]
282282
True
283283
>>> list(evalPath(g, (e.a, -e.p1, None))) == [(e.a, e.f)]
@@ -291,24 +291,24 @@
291291
>>> list(evalPath(g, (e.a, e.p1/e.p3/e.p3, None))) == [(e.a, e.h)]
292292
True
293293
294-
>>> list(evalPath(g, (e.q, e.px%OneOrMore, None)))
294+
>>> list(evalPath(g, (e.q, e.px*OneOrMore, None)))
295295
[(rdflib.term.URIRef(u'ex:q'), rdflib.term.URIRef(u'ex:q'))]
296296
297297
>>> list(evalPath(g, (None, e.p1|e.p2, e.c)))
298298
[(rdflib.term.URIRef(u'ex:a'), rdflib.term.URIRef(u'ex:c'))]
299299
300300
>>> list(evalPath(g, (None, ~e.p1, e.a))) == [ (e.c, e.a) ]
301301
True
302-
>>> list(evalPath(g, (None, e.p1%ZeroOrOne, e.c))) # doctest: +NORMALIZE_WHITESPACE
302+
>>> list(evalPath(g, (None, e.p1*ZeroOrOne, e.c))) # doctest: +NORMALIZE_WHITESPACE
303303
[(rdflib.term.URIRef(u'ex:c'), rdflib.term.URIRef(u'ex:c')),
304304
(rdflib.term.URIRef(u'ex:a'), rdflib.term.URIRef(u'ex:c'))]
305305
306-
>>> list(evalPath(g, (None, e.p3%OneOrMore, e.a))) # doctest: +NORMALIZE_WHITESPACE
306+
>>> list(evalPath(g, (None, e.p3*OneOrMore, e.a))) # doctest: +NORMALIZE_WHITESPACE
307307
[(rdflib.term.URIRef(u'ex:h'), rdflib.term.URIRef(u'ex:a')),
308308
(rdflib.term.URIRef(u'ex:g'), rdflib.term.URIRef(u'ex:a')),
309309
(rdflib.term.URIRef(u'ex:c'), rdflib.term.URIRef(u'ex:a'))]
310310
311-
>>> list(evalPath(g, (None, e.p3%ZeroOrMore, e.a))) # doctest: +NORMALIZE_WHITESPACE
311+
>>> list(evalPath(g, (None, e.p3*ZeroOrMore, e.a))) # doctest: +NORMALIZE_WHITESPACE
312312
[(rdflib.term.URIRef(u'ex:a'), rdflib.term.URIRef(u'ex:a')),
313313
(rdflib.term.URIRef(u'ex:h'), rdflib.term.URIRef(u'ex:a')),
314314
(rdflib.term.URIRef(u'ex:g'), rdflib.term.URIRef(u'ex:a')),
@@ -325,14 +325,14 @@
325325
>>> list(evalPath(g, (None, e.p1/e.p3/e.p3, e.h))) == [(e.a, e.h)]
326326
True
327327
328-
>>> list(evalPath(g, (e.q, e.px%OneOrMore, None))) #doctest: +NORMALIZE_WHITESPACE
328+
>>> list(evalPath(g, (e.q, e.px*OneOrMore, None)))
329329
[(rdflib.term.URIRef(u'ex:q'), rdflib.term.URIRef(u'ex:q'))]
330330
331-
>>> list(evalPath(g, (e.c, (e.p2|e.p3)%ZeroOrMore, e.j)))
331+
>>> list(evalPath(g, (e.c, (e.p2|e.p3)*ZeroOrMore, e.j)))
332332
[(rdflib.term.URIRef(u'ex:c'), rdflib.term.URIRef(u'ex:j'))]
333333
334334
No vars specified
335-
>>> sorted(list(evalPath(g, (None, e.p3%OneOrMore, None)))) #doctest: +NORMALIZE_WHITESPACE
335+
>>> sorted(list(evalPath(g, (None, e.p3*OneOrMore, None)))) #doctest: +NORMALIZE_WHITESPACE
336336
[(rdflib.term.URIRef(u'ex:c'), rdflib.term.URIRef(u'ex:a')),
337337
(rdflib.term.URIRef(u'ex:c'), rdflib.term.URIRef(u'ex:g')),
338338
(rdflib.term.URIRef(u'ex:c'), rdflib.term.URIRef(u'ex:h')),
@@ -433,7 +433,7 @@ def __repr__(self):
433433
return "Path(%s)" % " | ".join(str(x) for x in self.args)
434434

435435

436-
class ModPath(Path):
436+
class MulPath(Path):
437437
def __init__(self, path, mod):
438438
self.path = path
439439
self.mod = mod
@@ -612,11 +612,11 @@ def conjunctive_graph_triples(graph, t, context=None):
612612
raise Exception('I need a URIRef or path as predicate, not %s' % path)
613613

614614

615-
def mod_path(p, mod):
615+
def mul_path(p, mul):
616616
"""
617617
cardinality path
618618
"""
619-
return ModPath(p, mod)
619+
return MulPath(p, mul)
620620

621621

622622
def inv_path(p):
@@ -638,13 +638,13 @@ def neg_path(p):
638638

639639
URIRef.__or__ = path_alternative
640640
URIRef.__div__ = path_sequence
641-
URIRef.__mod__ = mod_path
641+
URIRef.__mul__ = mul_path
642642
URIRef.__invert__ = inv_path
643643
URIRef.__neg__ = neg_path
644644

645645
Path.__invert__ = inv_path
646646
Path.__neg__ = neg_path
647-
Path.__mod__ = mod_path
647+
Path.__mul__ = mul_path
648648
Path.__or__ = path_alternative
649649
Path.__div__ = path_sequence
650650

@@ -656,7 +656,7 @@ def neg_path(p):
656656
if __name__ == '__main__':
657657

658658
# print "---------------------"
659-
# for x in evalPath(g, (e.a, e.p1/(e.p3%ZeroOrMore)/e.p2, None)):
659+
# for x in evalPath(g, (e.a, e.p1/(e.p3*ZeroOrMore)/e.p2, None)):
660660
# print x
661661

662662
# g=Graph()
@@ -673,6 +673,6 @@ def neg_path(p):
673673
# ''', format='n3')
674674

675675
# e=Namespace('ex:')
676-
# print list(evalPath(g, (e.c, (e.p2|e.p3)%ZeroOrMore, e.j)))
676+
# print list(evalPath(g, (e.c, (e.p2|e.p3)*ZeroOrMore, e.j)))
677677
import doctest
678678
doctest.testmod()

rdflib/term.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,18 @@ def __repr__(self):
258258

259259
return """%s(%s)""" % (clsName, super(URIRef, self).__repr__())
260260

261+
def __add__(self, other):
262+
return self.__class__(unicode(self) + other)
263+
264+
def __radd__(self, other):
265+
return self.__class__(other + unicode(self))
266+
267+
def format(self, *args, **kwargs):
268+
return self.__class__(unicode(self).format(*args, **kwargs))
269+
270+
def __mod__(self, other):
271+
return self.__class__(unicode(self) % other)
272+
261273
def md5_term_hash(self):
262274
"""a string of hex that will be the same for two URIRefs that
263275
are the same. It is not a suitable unique id.

0 commit comments

Comments
 (0)