JESS: [EXTERNAL] Matching facts based on a slot, but not the fact's type

2013-07-30 Thread Aurelien Mazurie
Dear Jess users, I am still learning the ropes, and cannot find an answer to the following question either online or in the 'Jess in action' book. Is there a way to match facts in a LHS based on the presence of a slot? For example, I have two templates: (deftemplate A (slot score)) (deftemplate

JESS: [EXTERNAL] Dynamic rule matching in the LHS

2013-07-30 Thread Aurelien Mazurie
Dear Jess users, I am wondering how to write a rule that would dynamically match multiple facts based on their names. Let say I have two types of facts; one representing the information that an item (with a given name) exists, and the other one representing a list of items (e.g., as a list of

RE: JESS: [EXTERNAL] Matching facts based on a slot, but not the fact's type

2013-07-30 Thread Friedman-Hill, Ernest
The short answer is no. Templates are like Java classes, and so this is akin to asking if you can write Java code that reads the value of a score member variable in any class. But you can use template inheritance to achieve your goal. Templates can extend other templates; just put your score

RE: JESS: [EXTERNAL] Dynamic rule matching in the LHS

2013-07-30 Thread Friedman-Hill, Ernest
Not sure what dynamic means in this context. But you can use the forall conditional element to implement this rule. You could read the LHS here as For all values of ?name in bag-of-items, there's a corresponding item fact. (defrule check-bag-valid (forall (bag-of-items (names $?

Re: JESS: [EXTERNAL] Dynamic rule matching in the LHS

2013-07-30 Thread Jason Morris
Another old skool way of doing it using predicate constraints is... (clear) (deftemplate item (slot name)) (deftemplate bag-of-items (multislot item-names)) (defrule fire-for-all-members-in-bag ; If you have a bag of item names ... (bag-of-items (item-names $?item-names)) ; and there is an

Re: JESS: [EXTERNAL] Matching facts based on a slot, but not the fact's type

2013-07-30 Thread Wolfgang Laun
What you are looking for is the capability of using interface names as template names in LHS code, which is not available in Jess. Using extends might help you to a certain extent, but that's restricted to the definition of a hierarchy. Also, consider that the solution to your problem might be a

Re: JESS: [EXTERNAL] Dynamic rule matching in the LHS

2013-07-30 Thread Aurelien Mazurie
Thank you very much for this answer. It seems like 'forall' will fire the rule only if all the 'bag-of-items' facts are validated (i.e., if all of them have 'item' facts with the names listed in their 'names' slot). Is that correct? If yes, then what I am trying to do is slightly different. I

Re: JESS: [EXTERNAL] Matching facts based on a slot, but not the fact's type

2013-07-30 Thread Aurelien Mazurie
Thank you; the template inheritance mechanism was the answer. Aurélien On Jul 30, 2013, at 8:11 AM, Friedman-Hill, Ernest ejfr...@sandia.gov wrote: The short answer is “no”. Templates are like Java classes, and so this is akin to asking if you can write Java code that reads the value of a