You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Alan Nguyen <al...@gmail.com> on 2013/11/22 17:55:11 UTC

Adding and Removing statements using Jena Reasoner

Hi,
I'm trying to use the Jena Reasoner to remove an old statement and add a
new statement to my ontology model. I want to change trackStatus from True
to False when waterAcc is greater than 6.  I have the following rule:

    [WaterFail: (?x rdf:type af:Track) (?x af:trackStatus
"true"^^xs:boolean) (?x af:waterAcc ?y)  greaterThan(?y, 6.0) -> remove(1)
(?x af:trackStatus "false"^^xs:boolean)]

When I run the code, the statement gets removed from the model, however the
new "false" statement is not added.  If I get rid of the remove() in the
rule, the "false" statement is added to the model.  Additionally, if I
replace remove(1) with print("test"), the rule executes the print command
and adds the "false" statement.

Am I doing something wrong that is not letting me call remove() and add a
new statement?

Re: Adding and Removing statements using Jena Reasoner

Posted by Dave Reynolds <da...@gmail.com>.
On 22/11/13 16:55, Alan Nguyen wrote:
> Hi,
> I'm trying to use the Jena Reasoner to remove an old statement and add a
> new statement to my ontology model. I want to change trackStatus from True
> to False when waterAcc is greater than 6.  I have the following rule:
>
>      [WaterFail: (?x rdf:type af:Track) (?x af:trackStatus
> "true"^^xs:boolean) (?x af:waterAcc ?y)  greaterThan(?y, 6.0) -> remove(1)
> (?x af:trackStatus "false"^^xs:boolean)]
>
> When I run the code, the statement gets removed from the model, however the
> new "false" statement is not added.  If I get rid of the remove() in the
> rule, the "false" statement is added to the model.  Additionally, if I
> replace remove(1) with print("test"), the rule executes the print command
> and adds the "false" statement.
>
> Am I doing something wrong that is not letting me call remove() and add a
> new statement?

Basically JenaRules are painful for non-monotonic things like remove, 
they were a late addition in response to requests and broke the original 
design goals (pure monotonic closure). They combine with a lack of 
"refraction" and an broken notion of "unfire" to cause weird things to 
happen.

The rule of thumb (apart from don't use JenaRules for retracting things) 
is to ensure there is a non-monotonic guard to block any incorrect 
"unfiring".

If you try changing your rule to:

[WaterFail: (?x rdf:type af:Track)
             (?x af:trackStatus "true"^^xs:boolean)
             noValue(?x af:trackStatus "false"^^xs:boolean)]
             (?x af:waterAcc ?y)  greaterThan(?y, 6.0)
->
             remove(1)
             (?x af:trackStatus "false"^^xs:boolean)]

then it should work.

Dave