Skip to content

Commit

Permalink
Merge pull request #552 from RDFLib/fix-issue-545
Browse files Browse the repository at this point in the history
let paths be comparable against all nodes. Fixes #545
  • Loading branch information
gromgull committed Nov 29, 2015
2 parents ae1f639 + 25bfa5b commit 92aff84
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
31 changes: 26 additions & 5 deletions rdflib/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
""")


from rdflib.term import URIRef
from rdflib.term import URIRef, Node


# property paths
Expand All @@ -198,12 +198,33 @@ class Path(object):
def eval(self, graph, subj=None, obj=None):
raise NotImplementedError()

def __hash__(self):
return hash(repr(self))

def __eq__(self, other):
return repr(self) == repr(other)

def __lt__(self, other):
if not isinstance(other, Path):
if not isinstance(other, (Path, Node)):
raise TypeError('unorderable types: %s() < %s()' % (
repr(self), repr(other)))
return repr(self) < repr(other)

def __le__(self, other):
if not isinstance(other, (Path, Node)):
raise TypeError('unorderable types: %s() < %s()' % (
repr(self), repr(other)))
return repr(self) <= repr(other)

def __ne__(self, other):
return not self == other

def __gt__(self, other):
return not self <= other

def __ge__(self, other):
return not self < other


class InvPath(Path):

Expand All @@ -218,7 +239,7 @@ def __repr__(self):
return "Path(~%s)" % (self.arg,)

def n3(self):
return '^%s'%self.arg.n3()
return '^%s' % self.arg.n3()


class SequencePath(Path):
Expand Down Expand Up @@ -386,7 +407,7 @@ def __repr__(self):
return "Path(%s%s)" % (self.path, self.mod)

def n3(self):
return '%s%s'%(self.path, self.mod)
return '%s%s' % (self.path, self.mod)



Expand Down Expand Up @@ -419,7 +440,7 @@ def __repr__(self):
return "Path(! %s)" % ",".join(str(x) for x in self.args)

def n3(self):
return '!(%s)'%('|'.join(self.args))
return '!(%s)' % ('|'.join(self.args))


class PathList(list):
Expand Down
19 changes: 19 additions & 0 deletions test/test_issue545.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

from rdflib.plugins import sparql
from rdflib.namespace import RDFS, OWL, DC, SKOS

def test_issue():



query = sparql.prepareQuery(
"""
SELECT DISTINCT ?property ?parent
WHERE{
?property a owl:DeprecatedProperty .
?property dc:relation ?relation .
?property rdfs:subPropertyOf ?parent .
?property rdfs:label | skos:altLabel ?label .
}
""",
initNs = {"rdfs":RDFS, "owl":OWL, "dc":DC, "skos":SKOS})

0 comments on commit 92aff84

Please sign in to comment.