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 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