SPARQL Path between two nodes
Asked Answered
C

1

2

Given a graph:

@prefix da:    <http://example.com/data/> .
@prefix on:    <http://example.com/on/> .

da:Shenaz  on:husband  da:Javed .

da:Rita  on:friend  da:Noor ;
        on:sister  da:Tom .

da:Noor  on:sister  da:Shenaz .

da:Javed  on:child  da:Jaabir .

da:Tom  on:sister  da:James .

da:Jaabir  on:grandFather  da:Rafick .

There is a path between da:Noor and da:James which is da:Noor ^on:friend/on:sister/on:sister da:James . but the following query is returning false

PREFIX da:    <http://example.com/data/> 
PREFIX on:    <http://example.com/on/> 
ASK {
  da:Noor ((<>|!<>)|^(<>|!<>))* da:James .
}

It is a possible bug in Jena, with RDFLib in Python, True is returned

Condolence answered 10/4, 2017 at 7:55 Comment(3)
By using which API/triple store?Stream
Just as a side note, you should "fix" your prefix declaration of da and on, i.e. append either / or #.Stream
@AKSW, for the seprator, thanks, for the API, it's JenaCondolence
S
4

For some reason the property path is not evaluated as expected. I tried it with the more simple query:

  PREFIX  :     <http://ex.org/>
  PREFIX  da:   <http://example.com/data/>

  SELECT  ?u
  WHERE
    { da:Noor ^(:p1|!:p1) ?u }

The algebra looks ok, i.e. the path is reversed:

(project (?u)
    (path ?u (alt <http://ex.org/p1> (notoneof <http://ex.org/p1>)) <http://example.com/data/Noor>))

Looks like a bug but I might be wrong indeed. I'll ask on the Jena mailing list and later on post the answer here.

Update:

The problem is with negations when the object itself is grounded - which is the case here due to the reverse operator ^. As per @AndyS' comment, this bug will be fixed in Apache Jena 3.3.0. See JENA-1317

Stream answered 10/4, 2017 at 9:45 Comment(2)
yes, i think so too, in RDFLib Python, True is returnedCondolence
Thanks for the details : it'll be fixed in the 3.3.0 release : see issues.apache.org/jira/browse/JENA-1317Terrorize

© 2022 - 2024 — McMap. All rights reserved.