Reasoning Problems

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?

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

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:

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 (68.0 KB)

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

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.

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/

prefix rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#

prefix rdfs: http://www.w3.org/2000/01/rdf-schema#

prefix xsd: http://www.w3.org/2001/XMLSchema#

prefix owl: http://www.w3.org/2002/07/owl#

prefix stardog: tag:stardog:api:

prefix so: 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 (2.2 KB)

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:


Alternatively, you change your query to:

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

Hope this helps,
Lars

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.

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/

prefix rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#

prefix rdfs: http://www.w3.org/2000/01/rdf-schema#

prefix xsd: http://www.w3.org/2001/XMLSchema#

prefix owl: http://www.w3.org/2002/07/owl#

prefix stardog: tag:stardog:api:

prefix so: https://schema.org/

From local

Empty [#1], results: 0, wall time: 0 ms (NaN%)

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

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

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

to check what the data you inserted looks like.

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:

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

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

Yes it has been set

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

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

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

It is currently set to SL

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

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

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.