Jess considers only the last mapped instance

118 views Asked by At

I have a question in Jess Tab in Protege,I am building an ontology of 1 class Message and 3 instances :message 1 message2 message 3 , each each 3 datatype properties : category , interests , class .For each message I want to classify it as ham if the category and interests are equal , spam otherwise.The classification should be done using Jess Rules by which the class slot / property should change to ham or spam so I use modify-instance for that , as the interests of a message instance could change by time so it's not a static classification (or I would need to reclassify it) Here is an example for message1 in protege : enter image description here

So I mapped the instances as shown to Jess Engine using Jess Tab : enter image description here

Here are screenshots with my rules the : enter image description here When I type (run) the Jess engine will classify only 1 instance correctly which is message3 the last instance , I mean I thus have to send only 1 instance at a time to the engine else it won't classify all messages correctly.

I tried to otherwise print the classification value and it works correctly( in my example the 3 messages should be classified as ham ) enter image description here enter image description here

and when I added both rules the result was that the "ham/spam" printing enters a for loop . I've asked a question before and I got an answer that infinite loop happens because the rule keeps firing as the "if " in the action (RHS) is always correct : enter image description here

Is this a feature of Jess that it considers the last received instance. And is there a way to force Jess engine to consider more than 1 message at a time ? and why is the infinite loop happening ?

I am really stuck in this part and in desperate need for speed to finalize it for my thesis . So you help is appreciated . (I have implemented these rules in swrl busing SWRL+Jess Tab in Protege and the rules worked fine the problem was the facts were asserted in the ontology and I want them to be modified not asserted so that's why I used Jess Rules , do you think I am on the write track or I should use Sweet Rules for example better ?)

I updated the rule as follows by making constraint on the fact's slot value but no change :

(defrule MAIN::test2 (object (is-a http://www.owl-ontologies.com/Ontology1496039955.owl#Message) (OBJECT ?o)) (object (OBJECT ?o) (http://www.owl-ontologies.com/Ontology1496039955.owl#interests $?i)) (object (OBJECT ?o) (http://www.owl-ontologies.com/Ontology1496039955.owl#category $?c&:(eq (intersection$ $?i $?c) ))) (object (OBJECT ?o) (http://www.owl-ontologies.com/Ontology1496039955.owl#class $?cl&:(neq $?cl "spam"))) => (modify-instance ?o (http://www.owl-ontologies.com/Ontology1496039955.owl#class spam)))

1

There are 1 answers

10
laune On

This may not really be an answer, but you should consider changing your code accordingly, and if your problem continues, edit your question.

Don't use (if) on the right hand side. If there are two different situations due to values in the facts, distinguish them by rules.

Don't use (if) with just a single operand. This will always return true.

To avoid looping, either use the rule attribute no-loop or add a condition that is true unless something has been changed by the right hand side.

I would test rules in plain Jess first, before wrestling with the Protege layer.