# Reasoning Problems

**URL:** <https://community.stardog.com/t/reasoning-problems/4910>\
**Category:** Support\
**Created:** [April 23, 2024, 11:39pm UTC](https://community.stardog.com/t/reasoning-problems/4910 "2024-04-23T23:39:29Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![habat](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/habat/32/1762_2.png) [@habat](https://community.stardog.com/u/habat)\
**Post date:** [April 23, 2024, 11:39pm UTC](https://community.stardog.com/t/reasoning-problems/4910/1 "2024-04-23T23:39:29Z")

</div>

Hi I have some problems/questions regarding reasoning with Stardog.

I created a very simple example in Stardog Designer:

There are two classes:  
"Class1" and "Class2".  
There is a relationship "created" with the domain of Class1 and the range of Class2.

I have the "createdBy" relationship from Class2 to Class1.

I use the inference rule within Stardog Designer:

> "IF Class1 created Class2" infer "Class2 createdBy Class1"

I insert the following sample data via SPARQL in Stardog Studio:

> INSERT DATA {  
> testInference:thing1 rdf:type testInference:Class1 .  
> testInference:thing2 rdf:type testInference:Class2 .
> 
> testInference:thing1 testInference:created testInference:thing2  
> }

I can query for and return the asserted data. But when I enable reasoning I get no inferred results.

My SPARQL query for reasoning "createdBy" is:

> SELECT ?thing ?otherThing { ?thing testInference:createdBy ?otherThing }

Similarly I get no results if I query the relationship in explorer.

I have tried creating a user defined rule in Studio and this is returning 0 inference results.

I have tried setting it to "any class" for domain and range and this also returns 0 results.

I have tried setting "createdBy" as an owl:inverseOf "created" and this also doesnt work.

Am I misunderstanding something with how Stardog works?

---

<div class="post-metadata">

**Author:** ![Lars\_Heling](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/lars_heling/32/1657_2.png) [@Lars\_Heling](https://community.stardog.com/u/Lars_Heling)\
**Post date:** [April 24, 2024, 5:27am UTC](https://community.stardog.com/t/reasoning-problems/4910/2 "2024-04-24T05:27:14Z")

</div>

Hi,

I followed the steps you described. Created a Designer project, added two classes, added relationships, and added the rule (find the Designer project attached below). I published the model including the rule to an empty database and insert the data as you suggested. Specifically, in my cases I added

```auto
INSERT DATA {
    :A a <tag:stardog:designer:Test1:model:Class1> .
    :B a <tag:stardog:designer:Test1:model:Class2> .
    :A <tag:stardog:designer:Test1:model:created> :B .
}

```

I enabled reasoning and query the data with:

```auto
SELECT ?thing ?otherThing { ?thing <tag:stardog:designer:Test1:model:createdBy> ?otherThing }

```

The query returns the single expected result.

When you publish your Designer project, make sure to also checke the box "Publish Inference Rules". Or maybe you have a mismatch in the IRIs you are using?

Best regards  
Lars

[Test1.zip](https://community.stardog.com/uploads/short-url/j68HDxIYLnm6aEKbRpQkW5iSL1e.zip) (68.0 KB)

---

<div class="post-metadata">

**Author:** ![habat](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/habat/32/1762_2.png) [@habat](https://community.stardog.com/u/habat)\
**Post date:** [April 24, 2024, 8:29am UTC](https://community.stardog.com/t/reasoning-problems/4910/3 "2024-04-24T08:29:54Z")

</div>

Hi Lars,

I have copied your exact steps and while I can get "B" to display via the "createdBy" relationship in explorer I do not get any results when querying via Stardog Studio.

The inference rules are published when the designer project and model is published to the database.

Is this something related to the context being selected when Inserting data and querying the data?

I have tried every available context in Stardog Studio and I get no results when querying the inferred relationship

---

<div class="post-metadata">

**Author:** ![Lars\_Heling](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/lars_heling/32/1657_2.png) [@Lars\_Heling](https://community.stardog.com/u/Lars_Heling)\
**Post date:** [April 24, 2024, 8:37am UTC](https://community.stardog.com/t/reasoning-problems/4910/4 "2024-04-24T08:37:55Z")

</div>

I don't think it's related to the context/graph. When you execute the `INSERT DATA` query, the data will be added to the default graph and the `SELECT` query also is evaluated over the default graph.  
Can you "Run Profiler" (in the dropdown next to "Show Plan") with your query in Studio and share the profiling results here? Make sure to enable Reasoning in Studio.

Thanks.

---

<div class="post-metadata">

**Author:** ![habat](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/habat/32/1762_2.png) [@habat](https://community.stardog.com/u/habat)\
**Post date:** [April 24, 2024, 8:43am UTC](https://community.stardog.com/t/reasoning-problems/4910/5 "2024-04-24T08:43:46Z")

</div>

Here are is the response from "Run Profiler". for query:

SELECT ?thing ?otherThing { ?thing tag:stardog:designer:example:model:createdBy ?otherThing }

Note the project is named "example" rather than "Test1"

> Profiling results:
> 
> Query executed in 0 ms and returned 0 result(s)
> 
> Pre-execution time: 0 ms (NaN%)
> 
> Post-processing time: 0 ms (NaN%)
> 
> prefix : [http://api.stardog.com/](http://api.stardog.com/)
> 
> prefix rdf: [http://www.w3.org/1999/02/22-rdf-syntax-ns#](http://www.w3.org/1999/02/22-rdf-syntax-ns#)
> 
> prefix rdfs: [http://www.w3.org/2000/01/rdf-schema#](http://www.w3.org/2000/01/rdf-schema#)
> 
> prefix xsd: [http://www.w3.org/2001/XMLSchema#](http://www.w3.org/2001/XMLSchema#)
> 
> prefix owl: [http://www.w3.org/2002/07/owl#](http://www.w3.org/2002/07/owl#)
> 
> prefix stardog: tag:stardog:api:
> 
> prefix so: [https://schema.org/](https://schema.org/)
> 
> From tag:stardog:designer:example:model
> 
> Empty [#1], results: 0, wall time: 0 ms (NaN%)

I have attached the ttl file generated by Stardog for reference.

[example.ttl](https://community.stardog.com/uploads/short-url/3lQNSLuxaV8AlLGdLnW80fR3NDD.ttl) (2.2 KB)

---

<div class="post-metadata">

**Author:** ![Lars\_Heling](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/lars_heling/32/1657_2.png) [@Lars\_Heling](https://community.stardog.com/u/Lars_Heling)\
**Post date:** [April 24, 2024, 8:57am UTC](https://community.stardog.com/t/reasoning-problems/4910/6 "2024-04-24T08:57:46Z")

</div>

As indicated in the `FROM` statement of your profiling results, the query is executed only over the named graph `tag:stardog:designer:example:model` which only contains your model (that is, not the instance data you added).  
Try to either unselect any named graphs in Studio:

 ![Screenshot 2024-04-24 at 10.53.43](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/7/7586adcfccee8d57814f629408cba4f6d74a493a.png)  
Alternatively, you change your query to:

```auto
SELECT ?thing ?otherThing 
FROM stardog:context:local
{ ?thing <tag:stardog:designer:Test1:model:createdBy> ?otherThing }

```

Hope this helps,  
Lars

---

<div class="post-metadata">

**Author:** ![habat](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/habat/32/1762_2.png) [@habat](https://community.stardog.com/u/habat)\
**Post date:** [April 24, 2024, 9:18am UTC](https://community.stardog.com/t/reasoning-problems/4910/7 "2024-04-24T09:18:55Z")

</div>

Removing all named graphs has the same problem. I get no results.

I have this problem with any database I create with any data/ontology I provide so I am unsure what I am doing wrong.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/e0d6659e691c85734d267ace84ced8c7f96dc0ee.png)

> Profiling results:
> 
> Query executed in 0 ms and returned 0 result(s)
> 
> Pre-execution time: 0 ms (NaN%)
> 
> Post-processing time: 0 ms (NaN%)
> 
> prefix : [http://api.stardog.com/](http://api.stardog.com/)
> 
> prefix rdf: [http://www.w3.org/1999/02/22-rdf-syntax-ns#](http://www.w3.org/1999/02/22-rdf-syntax-ns#)
> 
> prefix rdfs: [http://www.w3.org/2000/01/rdf-schema#](http://www.w3.org/2000/01/rdf-schema#)
> 
> prefix xsd: [http://www.w3.org/2001/XMLSchema#](http://www.w3.org/2001/XMLSchema#)
> 
> prefix owl: [http://www.w3.org/2002/07/owl#](http://www.w3.org/2002/07/owl#)
> 
> prefix stardog: tag:stardog:api:
> 
> prefix so: [https://schema.org/](https://schema.org/)
> 
> From local
> 
> Empty [#1], results: 0, wall time: 0 ms (NaN%)

---

<div class="post-metadata">

**Author:** ![Lars\_Heling](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/lars_heling/32/1657_2.png) [@Lars\_Heling](https://community.stardog.com/u/Lars_Heling)\
**Post date:** [April 24, 2024, 9:30am UTC](https://community.stardog.com/t/reasoning-problems/4910/8 "2024-04-24T09:30:43Z")

</div>

That's strange. Do you get any results when you run the query with the body (i.e., `IF` part) of your rule:

```auto
SELECT *
FROM stardog:context:local 
{
    ?obj_0 a <tag:stardog:designer:example:model:Class1> .
    ?obj_1 a <tag:stardog:designer:example:model:Class2> .
    ?obj_0 <tag:stardog:designer:example:model:created> ?obj_1 .
}

```

If this doesn't match any results, then there are not matching instance for which the `createdBy` property can be inferred. This probably means, the data you inserted does not match your model (e.g., IRIs of the classes and properties).  
If this is the case, you can run

```auto
SELECT *
FROM stardog:context:local 
{
    ?s ?p ?o
}

```

to check what the data you inserted looks like.

---

<div class="post-metadata">

**Author:** ![habat](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/habat/32/1762_2.png) [@habat](https://community.stardog.com/u/habat)\
**Post date:** [April 24, 2024, 9:47am UTC](https://community.stardog.com/t/reasoning-problems/4910/9 "2024-04-24T09:47:48Z")

</div>

For the asserted "created" relationship the following returns results:

> SELECT \*  
> FROM stardog:context:local  
> {  
> ?obj\_0 a tag:stardog:designer:example:model:Class1 .  
> ?obj\_1 a tag:stardog:designer:example:model:Class2 .  
> ?obj\_0 tag:stardog:designer:example:model:created ?obj\_1 .  
> }

But for my inferred relationship of "createdBy"

> SELECT \*  
> FROM stardog:context:local  
> {  
> ?obj\_0 a tag:stardog:designer:example:model:Class1 .  
> ?obj\_1 a tag:stardog:designer:example:model:Class2 .  
> ?obj\_1 tag:stardog:designer:example:model:createdBy ?obj\_0 .  
> }

Returns nothing.

Running the following check:

> SELECT \*  
> FROM stardog:context:local  
> {  
> ?s ?p ?o  
> }

Returns the following:

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ef0a9061192722dc419edcf9bed7975c71e89d57.png)

It works fine in Stardog Explorer but I cannot get Reasoning to work in Studio on any database/data which makes it difficult to work with

---

<div class="post-metadata">

**Author:** ![Lars\_Heling](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/lars_heling/32/1657_2.png) [@Lars\_Heling](https://community.stardog.com/u/Lars_Heling)\
**Post date:** [April 24, 2024, 10:00am UTC](https://community.stardog.com/t/reasoning-problems/4910/10 "2024-04-24T10:00:10Z")

</div>

Is your model also set in the `reasoning.schemas` option in the database configuration? E.g.:

 ![Screenshot 2024-04-24 at 11.59.44](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/f/ff09816a6e12dde6ee9979bffb77682b2e44a479.png)

---

<div class="post-metadata">

**Author:** ![habat](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/habat/32/1762_2.png) [@habat](https://community.stardog.com/u/habat)\
**Post date:** [April 24, 2024, 10:03am UTC](https://community.stardog.com/t/reasoning-problems/4910/11 "2024-04-24T10:03:28Z")

</div>

Yes it has been set

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/5/5c946c0404a0b4d8e872fd8afc8ae3d6bf32e7ef.png)

---

<div class="post-metadata">

**Author:** ![Lars\_Heling](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/lars_heling/32/1657_2.png) [@Lars\_Heling](https://community.stardog.com/u/Lars_Heling)\
**Post date:** [April 24, 2024, 10:38am UTC](https://community.stardog.com/t/reasoning-problems/4910/12 "2024-04-24T10:38:32Z")

</div>

Can you try to add your model also to the `reasoning.schema.graphs` option:

 ![Screenshot 2024-04-24 at 12.38.22](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/8/88236c70bc22674910dcb98f073819dd6e018721.png)

---

<div class="post-metadata">

**Author:** ![habat](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/habat/32/1762_2.png) [@habat](https://community.stardog.com/u/habat)\
**Post date:** [April 24, 2024, 11:27pm UTC](https://community.stardog.com/t/reasoning-problems/4910/13 "2024-04-24T23:27:39Z")

</div>

Hi I added the model to the reasoning.schema.graphs option and reasoning still does not work in Studio

---

<div class="post-metadata">

**Author:** ![Lars\_Heling](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/lars_heling/32/1657_2.png) [@Lars\_Heling](https://community.stardog.com/u/Lars_Heling)\
**Post date:** [April 25, 2024, 5:01am UTC](https://community.stardog.com/t/reasoning-problems/4910/14 "2024-04-25T05:01:41Z")

</div>

What is the reasoning type you have set in the database properties? (`reasoning.type`)

---

<div class="post-metadata">

**Author:** ![habat](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/habat/32/1762_2.png) [@habat](https://community.stardog.com/u/habat)\
**Post date:** [April 25, 2024, 10:48am UTC](https://community.stardog.com/t/reasoning-problems/4910/15 "2024-04-25T10:48:51Z")

</div>

It is currently set to SL

---

<div class="post-metadata">

**Author:** ![Lars\_Heling](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/lars_heling/32/1657_2.png) [@Lars\_Heling](https://community.stardog.com/u/Lars_Heling)\
**Post date:** [April 25, 2024, 2:14pm UTC](https://community.stardog.com/t/reasoning-problems/4910/16 "2024-04-25T14:14:42Z")

</div>

Ok, that seems fine. You can use the CLI (which is part of the current release, see [docs](https://docs.stardog.com/install-stardog/install-from-zip)) to verify whether your schema was parsed and is set correctly using the [reasoning command](https://docs.stardog.com/stardog-cli-reference/reasoning/reasoning-schema). For example, if your instance runs of stardog cloud the command would look like as follows:

```auto
stardog reasoning schema https://<instance-url>:5820/<dbname> -u <your-username> -p <your-password>

```

This should print the schema that is used for inference by the query engine.  
If you haven't already, you can set the password for your user in Studio via the Security tab using the three-dot menu at the top right and "Change Password".

Best regards  
Lars

---

<div class="post-metadata">

**Author:** ![habat](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/habat/32/1762_2.png) [@habat](https://community.stardog.com/u/habat)\
**Post date:** [April 27, 2024, 12:00am UTC](https://community.stardog.com/t/reasoning-problems/4910/17 "2024-04-27T00:00:14Z")

</div>

Hi Lars,

Thanks for your time. I managed to resolve the reasoning problem.

I needed to select the specific reasoning schema when running the query rather than using the default configuration. This now works for all my ontologies when I select the schema.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/7/76b437ab581eb570e52f0ab085b8b8240bf6b0b8.png)
