-
Notifications
You must be signed in to change notification settings - Fork 564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rdflib under python3 #617
Comments
yupp, rdflib is meant to work in py3... can you provide a few lines of code that lead to that error, so i could try to reproduce with the latest dev version? |
OK. Here is a small file. The first two queries are OK but the last two fail. It appears that the culprit is trying to sort sequence paths so the solution is going to be to implement sorting for them. The error that I get is along the lines of [I'm again having problems uploading.] |
Here is the file, as I can't seem to upload. import rdflib
g = rdflib.Graph()
print("QUERY 0")
query = """
SELECT ?this
WHERE {
?this <http://www.w3.org/ns#p2> ?value1 .
?this <http://www.w3.org/ns#p2> ?value1 .
}
"""
g.query(query)
print("QUERY 1")
query = """
SELECT ?this
WHERE {
?this <http://www.w3.org/ns#p1>/<http://www.w3.org/ns#p2> ?value1 .
}
"""
g.query(query)
print("QUERY 2")
query = """
SELECT ?this
WHERE {
?this <http://www.w3.org/ns#p1> ?value1 .
?this <http://www.w3.org/ns#p2>/<http://www.w3.org/ns#p2> ?value1 .
}
"""
g.query(query)
print("QUERY 3")
query = """
SELECT ?this
WHERE {
?this <http://www.w3.org/ns#p2>/<http://www.w3.org/ns#p2> ?value1 .
?this <http://www.w3.org/ns#p1>/<http://www.w3.org/ns#p2> ?value1 .
}
"""
g.query(query) |
as an alternative to uploading files, just copy & paste short python code snippets into a blocks like this in future (looks better and is easier to access anyhow):
i labelled your reports and reformatted them, so they won't be forgotten... if someone is less busy and searching for some in-depth SPARQL knowledge: dive in ;) |
It's just because rdflib.paths.SequencePath doesn't support sort comparisons. You can make this work in your own code by inserting the following (mickey mouse sort by string comparison): # Egregious hack, the SequencePath object doesn't support compare, this implements the __lt__ method so that algebra.py works on sorting in SPARQL queries on e.g. rdf:List paths
def sequencePathCompareLt(self, other):
return str(self) < str(other)
def sequencePathCompareGt(self, other):
return str(self) < str(other)
setattr(SequencePath, '__lt__', sequencePathCompareLt)
setattr(SequencePath, '__gt__', sequencePathCompareGt)
# End egregious hack It's not particularly meaningful other than making code work, but it could go into class SequencePath(Path):
...
def __lt__ (self, other):
return str(self) < str(other)
def __gt__ (self, other):
return str(self) > str(other)
... I am sure there is a more intelligent sort to implement, but this will work. |
actually - for me the code in #617 (comment) runs without error on HEAD. |
I'm going to @pjohnston-wiley used 4.2.1 where it's broken, and it's now fixed in master :) reopen if I'm wrong! |
Is rdflib supposed to work in python3?
I´m getting one of the canonical non-compatability errors when I run its SPARQL implementation in python3.
Here is an edited version of what I am seeing, with some test printout included:
The query includes SPARQL path expressions and these seem to be involved in
the comparison.
The text was updated successfully, but these errors were encountered: