0

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)))

  • Words are not well suited for stating what you really mean. Haven't you got any code demonstrating your problem? – laune Jun 06 '17 at 10:37
  • I will add screenshots ,let me redefine it I mean instance slot values are modified for only 1 instance at a time , If i have i1 and i2 , and I have a jess rule which modifies the slot values of an instance and I mapped the class with the instances only i2's slot value will change while i1 won't – user3379762 Jun 06 '17 at 11:45
  • It seems like you've asked the same question multiple times now, with no responses, because as asked, the question is unanswerable: you need to show some code. – Ernest Friedman-Hill Jun 06 '17 at 13:00
  • As far as the Jess rule engine, by itself, goes, if you write a rule that matches and modifies a fact, and there are ten matching facts, then when you run the engine, all ten facts will be modified, as long as modifying one fact doesn't somehow make the rule no longer match. But that's for Jess itself, and you've got multiple layers of third-party software piled on top of it. You need to show us exactly what you're doing using the simplest possible complete example, and maybe somebody can tell you what you're doing wrong. – Ernest Friedman-Hill Jun 06 '17 at 13:01
  • I editted the questions with detailed example and questions , please help. – user3379762 Jun 07 '17 at 10:02

1 Answers1

0

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.

laune
  • 31,114
  • 3
  • 29
  • 42
  • I don't get the first point what do you mean two different situations, the no -loop attribute does not work in protege it gives an error . I will see what I can do. – user3379762 Jun 07 '17 at 13:38
  • An if statement distinguishes between two situations, according to the condition. - If you cannot use no-loop, add a constraint that is true when the action on the RHS has not been executed. – laune Jun 07 '17 at 14:05
  • I'd be grateful if you gave me an example with a code as I am new to Jess and stuck specially for the 2nd point – user3379762 Jun 08 '17 at 09:10
  • There are plenty of examples in the Jess manual. Have you read it, front to back? – laune Jun 09 '17 at 05:41
  • Nothing targets m problem much specially the protege layer thing but I'll recheck . I edited my question with something , if you can help me decide (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 ?) – user3379762 Jun 09 '17 at 09:07
  • I have another question sorry , the condition you said I should add should be in the LHS right ? a condition which is true if no change/ modification happened to a fact in RHS so if a change happened the rule will no longer fire? – user3379762 Jun 10 '17 at 09:37
  • You cannot modify a fact unless it has been asserted previously, so it becomes a fact in the first place. - Simply put, to keep a rule from firing that modifies `X.setY( "z" )`, use `X( y != "z")`. This constraint is true when the RHS action has not been executed, right? – laune Jun 10 '17 at 12:04
  • I'll add my trials for you to check , I mean the constraint should be added at the LHS of the rule right ? – user3379762 Jun 10 '17 at 14:01
  • please check my updated rule which also gives an infinite loop after i made a constraint on the fact's slot value – user3379762 Jun 10 '17 at 14:13
  • I'd use `modify` and as an argument a variable bound to the fact, not to the slot OBJECT. – laune Jun 10 '17 at 14:29