On Oct 26, 2007, at 4:44 AM, waschtl34 wrote:

(deftemplate RepositoryProcess "Slot1: id des Process', slot2:
initialElements"
    (slot processId)
    (multislot initialElements))

(deftemplate UserProcess "Slot1: id des Process, Slot2: selectedElements"
  ;;  (slot userProcessId)
    (multislot selectedElements))


if (selectedElements CONTAINS "trans" && initialElements CONTAINS "place")
then printout processId

The exact answer depends on how many RepositoryProcess facts and how many UserProcess facts there are, and whether that userProcessId slot is commented out or not. Let's assume there are many of each, and that slot is *not* commented out, and the task is to find a pair of facts where the processId == userProcessId and the multislots contain the values given. You could write that rule like this:

(defrule rule-1
    (RepositoryProcess (processId ?pid) (initialElements $? place $?))
    (UserProcess (userProcessId ?pid) (selectedElements $? trans $?))
    =>
    (printout t "Process id: " ?pid crlf))

We match two facts and we "unify" them by using the same variable name to match both of the process id slots; this selects only pairs that have the same value in this slot. Then we also select only facts which have the desired values in the multislots. A variable like "$?" is a "blank multifield", and it matches zero or more list elements, then ignores them. So a pattern like "$? place $?" is how you write "contains".


Another interesting rule would be:

If (SIZEOF selectedElements == SIZEOF initialElements)
then do somthing

One way to write this would look like

(defrule rule-2
    (RepositoryProcess (processId ?pid) (initialElements $?ie))
    (UserProcess (userProcessId ?pid) (selectedElements $?se))
    (test (eq (length$ ?ie) (length ?se)))
    =>
    (printout t "Same length: " ?pid crlf))



---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences          Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 [EMAIL PROTECTED]
Livermore, CA 94550                 http://www.jessrules.com

--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------

Reply via email to