Skip to content
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

New test of expandTriples #622

Merged
merged 2 commits into from
May 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion rdflib/plugins/sparql/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def expandTriples(terms):
elif isinstance(t, list):
# BlankNodePropertyList
# is this bnode the object of previous triples?
if (i % 3) == 2:
if (len(res) % 3) == 2:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done for debugging and finding this! I wrote this code, and I had no idea how it worked any more :)

res.append(t[0])
# is this a single [] ?
if len(t) > 1:
Expand All @@ -71,6 +71,11 @@ def expandTriples(terms):
res += t.asList()
elif t != '.':
res.append(t)
if DEBUG:
print len(res), t
if DEBUG:
import json
print json.dumps(res, indent=2)

return res
# print res
Expand Down
10 changes: 10 additions & 0 deletions test/test_sparql.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ def test_sparql_bnodelist():
prepareQuery('select * where { ?s ?p ( [ ?p2 ?o2 ] [] ) . }')
prepareQuery('select * where { ?s ?p ( [] [ ?p2 ?o2 ] [] ) . }')

def test_complex_sparql_construct():

g = Graph()
q = '''select ?subject ?study ?id where {
?s a <urn:Person>;
<urn:partOf> ?c;
<urn:hasParent> ?mother, ?father;
<urn:id> [ a <urn:Identifier>; <urn:has-value> ?id].
}'''
g.query(q)

if __name__ == '__main__':
import nose
Expand Down