From d55529aa497eaa0774939603ce21a74b6f8a8ca4 Mon Sep 17 00:00:00 2001 From: Jim McCusker Date: Mon, 9 May 2016 13:22:06 -0400 Subject: [PATCH 1/2] New test of expandTriples --- test/test_sparql.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/test_sparql.py b/test/test_sparql.py index 7af5ee876..69a67c722 100644 --- a/test/test_sparql.py +++ b/test/test_sparql.py @@ -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 ; + ?c; + ?mother, ?father; + [ a ; ?id]. + }''' + g.query(q) if __name__ == '__main__': import nose From 59dd5525b21a6809f07be3c49699c354424a596e Mon Sep 17 00:00:00 2001 From: Jim McCusker Date: Mon, 9 May 2016 16:23:56 -0400 Subject: [PATCH 2/2] checks for objects should be relative to the result so far, not to the input (which can get really hairy) --- rdflib/plugins/sparql/parser.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rdflib/plugins/sparql/parser.py b/rdflib/plugins/sparql/parser.py index 97ef91eda..93ad1a5d3 100644 --- a/rdflib/plugins/sparql/parser.py +++ b/rdflib/plugins/sparql/parser.py @@ -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: res.append(t[0]) # is this a single [] ? if len(t) > 1: @@ -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