Path query chaining issue · Issue #715 · RDFLib/rdflib (original) (raw)

Consider the following RDF file example.rdf

<http://example.org/A> <http://example.org/relations/isa> <http://example.org/X> .
<http://example.org/A> <http://example.org/relations/isa> <http://example.org/Y> .
<http://example.org/B> <http://example.org/relations/isa> <http://example.org/X> .

With rdflib 4.2.2 I do

import rdflib
g = rdflib.Graph()
g.parse('example.rdf', format='nt')
g.query('SELECT ?child ?parent WHERE {?child <http://example.org/relations/isa> ?parent .}')

and print the results, and I get the correct relationships:

http://example.org/A http://example.org/Y
http://example.org/B http://example.org/X
http://example.org/A http://example.org/X

However, when changing the query to

g.query('SELECT ?child ?parent WHERE {?child <http://example.org/relations/isa>+ ?parent .}')

I get

http://example.org/A http://example.org/Y
http://example.org/A http://example.org/X
http://example.org/B http://example.org/X
http://example.org/B http://example.org/Y

where the relationship B isa+ Y was incorrectly inferred. Is this a bug or am I misunderstanding the meaning of + in path chaining?