Reasoning not working with pystardog?

hi,
this is my first attempt to use Stardog rules, so please excuse any lack of understanding. I use pystardog to load a schema file, and then load a. ttl file containing the following:

PREFIX rule: <tag:stardog:api:rule:>
PREFIX : <http://www.pametan.ai/ontologies/Fault#>

:boiler rdf:type :Boiler .
:ahu rdf:type :AHU .
:zone rdf:type :Zone .
:boiler :feedsWater :ahu .
:ahu :feedsAir :zone .

IF {
   ?boiler :feedsWater ?ahu .
   ?ahu :feedsAir ?zone .
   ?zone :State :Cool .
   BIND (?boiler AS ?b)
}
THEN {
       ?b :State :Broken .
     }

In the pystardog code I assert that :zone :State :Cool
But when run a query as follows (with conn.begin(reasoning=True)):

  query = """SELECT * where {<http://www.pametan.ai/ontologies/Fault#boiler> ?p ?o}"""
  results = conn.select(query, reasoning=True)

the :State of :boiler is not inferred to be :Broken

I also loaded the schema and .ttl files manually into Stardog Studio, and (with reasoning turned on)
I get the same result: :boiler is not :Broken

Can you give me some idea of what I'm doing wrong?

Thanks!
arthur

In a further experiment, I created some SWRL rules in Protege, and then imported the schema+rules manually into Stardog using Studio. The rules are present in the OWL file, and show up in Studio as subclasses of Imp, but an rule like:
Boiler(?b)^Zone(?z)^hasState(?z,Cold) -> hasState(?b,Broken)
which works in Protege doesn't seem to work in Studio even when reasoning is turned on and I do an INSERT DATA {...} to assert "hasState" to be "Cold".
Any suggestions very welcome!
Thanks.

I am having trouble following the logic. I loaded your data in the first post, and it obvious that it will not work, since there is no asserted data for ?zone :State :cool

If i use this test data, with a slighly adjusted rule, I think I get what you are looking for

PREFIX rule: <tag:stardog:api:rule:>
PREFIX : <http://www.pametan.ai/ontologies/Fault#>

################################
# Assert test data to test rule
################################
:boiler rdf:type :Boiler .
:ahu rdf:type :AHU .
:zone rdf:type :Zone .
:boiler :feedsWater :ahu .
:ahu :feedsAir :zone .
:zone :hasState :Cool .

#################################
# Rule
#################################

IF {
   ?boiler :feedsWater ?ahu .
   ?ahu :feedsAir ?zone .
   ?zone :hasState :Cool .
}
THEN {
       ?boiler :State :Broken .
     }

Dear Serge,

many thanks for the feedback. I am able to make the .ttl you show in your reply work in Studio.
But originally I had asserted :zone :hasState :Cool in my pystardog code via:
conn.add(stardog.content.Raw('http://www.pametan.ai/ontologies/Fault#zone
http://www.pametan.ai/ontologies/Fault#hasState
http://www.pametan.ai/ontologies/Fault#Cool', 'text/turtle'))
Now it seems, by magic, to work from pystardog as well; I guess the BIND that I had in my original rule wasn't the right thing? Again, thanks.
arthur

BIND is indeed something that is not required, But you also had
?zone :State :Cool .
rather than
?zone :hasState :Cool .
In your rule.

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