SPARQL Rule with reasoning does not work

Hello All,

I am a newbie to Stardog DB and try to use the Rule and the reasoning feature of Stardog. I expect from enabling the reasoning and using the following simple rule to update values of individuals matching to the IF condition. It does happening. I will truly appreciate if you can help me.
Here is the simple rule that tries to update the state of a ?x based on the state of another object ?p.
I added the rule to the database and the web interface for database browsing shows it as a SPARQLRule. I also enabled reasoning and chose the SL reasoning algorithm.

IF {	?x a :Path.
        ?x   :hasActive  ?p.
	?p  :hasState ?s.
	BIND ( ?s AS ?state).

    }
    THEN {
        ?x  :hasState ?state .
    }

Thanks in advance!

Hi,

Please share the query you are executing, the expected results and the actual results.

Jess

Hi Jess,
Thanks for your reply,
I am not running any query, I am under the impression of this rule will fire whenever any changes in the db are happening and I expect it updates the ?X state with the state of ?P. To test if it works, I simply change the state of the ?P to “Inactive” and expect ?X :hasState "active" changes to ?X :hasState "Inactive" automaticlly.

BR,

Hi,

It sounds like you are expecting the rules to materialize triples and act as sort of a "trigger." Stardog does not perform materialization; we perform Query Rewriting at query runtime.

In short, If you run the query select * where {?x :hasState "active"}, it will give you all of the entities that either explicitly have that triple in the db, or for which the rule applies. Instead of looking for ?X :hasState "Inactive" in the database, try running the query above, changing a state, and running it again. You should see the results you're looking for.

Hi,
Thanks for your reply, I can see the expected results by running the query (1): select * where {?x :hasState “Inactive”}, however, if I run the select * where {?x :hasState “active”} query it also returns the triples supposed to be “Inactive” ! I guess this time it is because of it has explicit value of “active” . It is a preplex behaviour to me, is there anyway that I can get more consistent outputs?
Thanks !

The rule does exactly what’s stated there. It matches the data and produces new data. If a path has both states, indeed this will be inferred.

But to be honest, without seeing the data it’s impossible to help you further. Can you share the sample data please?

Thanks for your reply,
You can find a simplified data set from test-arsham-w-const-2-1.ttl (2.3 KB)
For this data set, if I run the query: SELECT * WHERE {?p a of:Path; of:hasState 'Inactive'} returns Nil if the reasoning is OFF and return the three paths if the reasoning is ON as it should be. However, If I run SELECT * WHERE {?p a of:Path; of:hasState 'active'} it always (with/without reasoning) return the same three defined paths.

If I change the rule to the one mentioned in the previous post, it did not work at all. I have to specify the value for the Dataproperty :hasState to make it work as described.

Many Thanks for help!

Hi,

With your dataset I was able to play around with the rules/queries and sort of get what I think you’re looking for.

I removed ALL of the of:hasState triples from the of:Paths, keeping them just on the of:AvailPaths. I then added the following rule:

[] a <tag:stardog:api:rule:SPARQLRule> ;
	<tag:stardog:api:rule:content> """IF {	
            ?x a of:Path.    
            ?x  of:hasActive/of:hasState \"active\".
          }    
          THEN {        
            ?x  of:hasState \"active\".    
          }""" .

This allows me to query the “active” Paths like so:

> stardog query -r myDb "select ?p {?p a of:Path ; of:hasState \"active\"}"
+---------------------------------------------+
|                      p                      |
+---------------------------------------------+
| of:path_00:00:00:00:00:01_00:00:00:00:00:03 |
+---------------------------------------------+

And the “Inactive” Paths like so:

> stardog query -r myDb "select ?p {?p a of:Path . MINUS {?p of:hasState \"active\"}}"
+---------------------------------------------+
|                      p                      |
+---------------------------------------------+
| of:path_00:00:00:00:00:01_00:00:00:00:00:04 |
| of:path_00:00:00:00:00:01_00:00:00:00:00:02 |
+---------------------------------------------+

While it doesn’t reason out an “Inactive” triple, it does honor the logic of showing you of:Paths that are NOT “active”

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