# PATH query and reasoning

**URL:** <https://community.stardog.com/t/path-query-and-reasoning/1062>\
**Category:** Support\
**Created:** [May 21, 2018, 6:27pm UTC](https://community.stardog.com/t/path-query-and-reasoning/1062 "2018-05-21T18:27:57Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ikazu](https://avatars.discourse-cdn.com/v4/letter/i/e19adc/32.png) [@ikazu](https://community.stardog.com/u/ikazu)\
**Post date:** [May 21, 2018, 6:27pm UTC](https://community.stardog.com/t/path-query-and-reasoning/1062/1 "2018-05-21T18:27:57Z")

</div>

Hi Stardog team,

I have used PATH queries to find paths and have several questions:

1. I noticed that the PATH queries only work for explicitly defined relationships (single direction: subject -\> predicate -\> object), but it cannot do reasoning on inferred inverse relationships defined in our ontology file. In order for a bidirectional path discovery to work, do relationships need to be defined explicitly in both directions?

2. Do PATH queries work on virtual graph? If yes, is the work being done by pushing SQL to the DB Engine? I noticed that PATH queries are not standard SPARQL, but GraphQL. I also noticed PATH queries can only be operated from command line, not from Stardog web interface.

3. Can I use PATH queries on the ontology schema (not instance) without explicitly converting ontology class to triple format? Currently, I found PATH works on instances, not on ontology itself. Do I need to explicitly convert ontology file into triple format in order to use PATH on abstract schema to facilitate SPARQL query generation?

Any help is much appreciated!

---

<div class="post-metadata">

**Author:** ![pavel](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/pavel/32/18_2.png) [@pavel](https://community.stardog.com/u/pavel)\
**Post date:** [May 21, 2018, 6:47pm UTC](https://community.stardog.com/t/path-query-and-reasoning/1062/2 "2018-05-21T18:47:11Z")

</div>

Hi Ju, here are some answers:

1. PATH queries should work over the inferred graph. Make sure reasoning is enabled for your query. If you can see reasoning working for, say, a SELECT query but not a PATH query, please create a minimal example and we’ll happily take a look.

2. Web interface is deprecated in favour of the new Stardog Studio desktop application. It already supports PATH queries. No, currently PATH queries are not executed live over virtual graphs but it’s on the roadmap. You’re correct that it’s an extension to SPARQL.

3. PATH queries work over the RDF graph. Ontology axioms (assuming we’re talking about OWL) are stored in RDF according to the standardized OWL to RDF mapping, so they’re queryable using the same kind of queries as instance data. You don’t need to convert anything, Stardog handles that transparently. Again, if you feel something isn’t working, just make a precise test case and we’ll provide more specific answers.

Best,  
Pavel

---

<div class="post-metadata">

**Author:** ![ikazu](https://avatars.discourse-cdn.com/v4/letter/i/e19adc/32.png) [@ikazu](https://community.stardog.com/u/ikazu)\
**Post date:** [May 21, 2018, 7:29pm UTC](https://community.stardog.com/t/path-query-and-reasoning/1062/3 "2018-05-21T19:29:38Z")

</div>

Thanks for your prompt reply Pavel.

1. Inference does work on SELECT for me, but not on PATH. For example with the following data:

> :individual\_01 :usesDevice :device\_01 .  
> :individual\_01 :usesDevice :device\_02 .

and I have defined in OWL:

> :usedByIndividual owl:inverseOf :usesDevice .

When I use PATH with start = :device\_01 and end = :device\_02. It cannot find the correct path:

> :device\_01 -\> :usedByIndividual -\> :individual\_01 -\> :usesDevice -\> :device\_02.

Unless I also explicitly declare the following in INSERT statement:

> :device\_01 :usedByIndividual :individual\_01  
> :device\_02 :usedByIndividual :individual\_01

1. My ontology file for class Individual and class Device with predicate usesDevice and usedByIndividual. This format is not recognized by PATH when I tried to use start = :Device and end = :Individual

> :usesDevice rdf:type owl:ObjectProperty ;  
> rdfs:domain :Individual ;  
> rdfs:range :Device .
> 
> :usedByIndividual rdf:type owl:ObjectProperty ;  
> owl:inverseOf :usesDevice ;  
> rdfs:domain :Device ;  
> rdfs:range :Individual .
> 
> :Individual rdf:type owl:Class .  
> :Device rdf:type owl:Class .

And it seems PATH query only applies to following triple format, which is not the OWL format.

> :Individual :usesDevice :Device  
> :Device :usedByIndividual :Individual

---

<div class="post-metadata">

**Author:** ![pavel](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/pavel/32/18_2.png) [@pavel](https://community.stardog.com/u/pavel)\
**Post date:** [May 21, 2018, 8:25pm UTC](https://community.stardog.com/t/path-query-and-reasoning/1062/4 "2018-05-21T20:25:51Z")

</div>

Let’s try to figure out the first issue and then move to the second. Can you share the exact data file which you’re loading? This stuff’s got to work, here’s what I did:

```bash
pavel$ stardog-admin db create -n test
Successfully created database 'test'.
pavel$ stardog query test "insert data { <urn:a> <urn:p> <urn:b> . <urn:a> <urn:p> <urn:c> . <urn:p> <http://www.w3.org/2002/07/owl#inverseOf> <urn:q> . }"
3 triples added in 00:00:00.356
pavel$ stardog query --reasoning test "paths start ?x = <urn:b> end ?y = <urn:c> via ?predicate"
+-------+-----------+-------+
| x | predicate | y |
+-------+-----------+-------+
| urn:b | urn:q | urn:a |
| urn:a | urn:p | urn:c |
+-------+-----------+-------+

Query returned 1 paths in 00:00:01.182

```

Now all we need to do is to figure out what’s different in your case.

Cheers,  
Pavel

PS. Stardog 5.3

---

<div class="post-metadata">

**Author:** ![ikazu](https://avatars.discourse-cdn.com/v4/letter/i/e19adc/32.png) [@ikazu](https://community.stardog.com/u/ikazu)\
**Post date:** [May 22, 2018, 2:53pm UTC](https://community.stardog.com/t/path-query-and-reasoning/1062/5 "2018-05-22T14:53:38Z")

</div>

Thanks Pavel.  
I think the problem is that I did not include the “–reasoning” tag in my command when I ran the query 🙂

Any insights for problem 3?

---

<div class="post-metadata">

**Author:** ![pavel](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/pavel/32/18_2.png) [@pavel](https://community.stardog.com/u/pavel)\
**Post date:** [May 22, 2018, 3:12pm UTC](https://community.stardog.com/t/path-query-and-reasoning/1062/6 "2018-05-22T15:12:15Z")

</div>

I don’t quite understand the problem 3. What’s the path(s) from `:Device` to `:Individual` that you expect to be returned? What’s the full query that you’re using? There’re no directed paths in your schema graph from Device to Individual, you’d need to write a query which traverses edges both ways.

Cheers,  
Pavel

---

<div class="post-metadata">

**Author:** ![ikazu](https://avatars.discourse-cdn.com/v4/letter/i/e19adc/32.png) [@ikazu](https://community.stardog.com/u/ikazu)\
**Post date:** [May 22, 2018, 3:50pm UTC](https://community.stardog.com/t/path-query-and-reasoning/1062/7 "2018-05-22T15:50:48Z")

</div>

Since I defined a predicate `:usedByIndividual` in the ontology file with the range and domain as following, I expect to get a path from `:Device` to `:Individual` with the path `:usedByIndividual.`

> :usedByIndividual rdf:type owl:ObjectProperty ;  
> owl:inverseOf :usesDevice ;  
> rdfs:domain :Device ;  
> rdfs:range :Individual .

---

<div class="post-metadata">

**Author:** ![pavel](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/pavel/32/18_2.png) [@pavel](https://community.stardog.com/u/pavel)\
**Post date:** [May 22, 2018, 4:08pm UTC](https://community.stardog.com/t/path-query-and-reasoning/1062/8 "2018-05-22T16:08:44Z")

</div>

Right, but both Device and Individual only have incoming edges in this sub-graph so you need to traverse edges both ways. Or do you expect some sort of reasoning to happen for this query as well?

Cheers,  
Pavel

---

<div class="post-metadata">

**Author:** ![ikazu](https://avatars.discourse-cdn.com/v4/letter/i/e19adc/32.png) [@ikazu](https://community.stardog.com/u/ikazu)\
**Post date:** [May 22, 2018, 4:16pm UTC](https://community.stardog.com/t/path-query-and-reasoning/1062/9 "2018-05-22T16:16:52Z")

</div>

I do have both way predicates :usesDevice and :usedByIndividual, which means they have both incoming and outgoing edges.

> :usesDevice rdf:type owl:ObjectProperty ;  
> rdfs:domain :Individual ;  
> rdfs:range :Device .
> 
> :usedByIndividual rdf:type owl:ObjectProperty ;  
> owl:inverseOf :usesDevice ;  
> rdfs:domain :Device ;  
> rdfs:range :Individual .

---

<div class="post-metadata">

**Author:** ![pavel](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/pavel/32/18_2.png) [@pavel](https://community.stardog.com/u/pavel)\
**Post date:** [May 22, 2018, 4:39pm UTC](https://community.stardog.com/t/path-query-and-reasoning/1062/10 "2018-05-22T16:39:15Z")

</div>

No, they don’t. We’re talking about pure simple RDF here so in your RDF graph `:Device` has 2 incoming edges only: one `rdfs:range` from `:usesDevice` node and one `rdfs:domain` from `:usedByIndividual` node. Same for `:Individual`. You can draw your graph to see that. There’re no directed paths from `:Device` to `:Individual`. There’re undirected ones though.

The fact that your RDF graph represents RDFS axioms plays no role here. Paths queries (just as any other queries) without reasoning are evaluated over asserted triples regardless of what those triples represent [1].

Cheers,  
Pavel

[1] I’m ignoring here virtual graphs and other enterprise features which we are not discussing at the moment.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [June 5, 2018, 4:39pm UTC](https://community.stardog.com/t/path-query-and-reasoning/1062/11 "2018-06-05T16:39:15Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
