Greetings to everybody on this list.

The general idea of this approach is to use WME references as slot values. Retrieval of one fact will then permit efficient access to one or more related facts, via some (constant) slots. I haven't found any hint that this isn't permitted, but in the Jess distribution there wasn't an example demonstrating this either. Anyway, there are situations when doing this appears to fail during pattern matching, but I've also found a working example. - I'm using Jess Version 7.0p1 12/21/2006.

The following Jess program uses working memory elements as slot values, and this one doesn't fire the rule crossover, although I think it should.

(reset)

(deftemplate bridge
   (slot name  (type STRING))
   (slot occup (type SYMBOL))
   (slot east  (type OBJECT))
   (slot west  (type OBJECT)))

(deftemplate side
   (slot name   (type STRING))
   (slot bridge (type OBJECT))
   (slot occup  (type SYMBOL)))

(defrule crossover
  ?e <- (side (name ?ename) {occup == FALSE})
  ?w <- (side (name ?wname) {occup == TRUE})
  ?br <- (bridge (name ?bname){occup == FALSE}
                (east $east){east == ?e}
                (west $west){west == ?w})
  =>
  (printout t ?bname " " ?ename " " ?wname  crlf)
)

(bind ?east (assert (side (name "East") (occup FALSE))))
(bind ?west (assert (side (name "West") (occup TRUE))))
(bind ?gate  (assert (bridge (name "GoldGate") (occup FALSE)
                    (east ?east) (west ?west))))

(modify ?east (bridge ?gate))
(modify ?west (bridge ?gate))
(facts)
(run)

Jess> (batch aba.clp)
f-0   (MAIN::initial-fact)
f-1   (MAIN::side (name "East") (bridge <Fact-3>) (occup FALSE))
f-2   (MAIN::side (name "West") (bridge <Fact-3>) (occup TRUE))
f-3 (MAIN::bridge (name "GoldGate") (occup FALSE) (east <Fact-1>) (west <Fact-2>))
For a total of 4 facts in module MAIN.
0

Not trying to match two "side" facts in the same rule appears to work, e.g.,

(defrule x
  ?e <- (side (name ?ename) {occup == FALSE})
  ?br <- (bridge (name ?bname){occup == FALSE})
  =>
  (printout t "x: " ?bname " " ?ename crlf)
)

fires, but this one (with or without the third LHS term) doesn't:

(defrule y
  ?e <- (side (name ?ename) {occup == FALSE})
  ?w <- (side (name ?wname) {occup == TRUE})
  ?br <- (bridge (name ?bname){occup == FALSE})
  =>
  (printout t "y: " ?bname " " ?ename " " ?wname crlf)
)

--------------

But a similar example works:

(reset)
(deftemplate person
   (slot name   (type STRING))
   (slot father (type OBJECT))
   (slot mother (type OBJECT)))

(bind ?adam   (assert (person (name Adam))))
(bind ?eve    (assert (person (name Eve ))))
(bind ?cain   (assert (person (name Cain)   (father ?adam) (mother ?eve))))
(bind ?abel   (assert (person (name Abel)   (father ?adam) (mother ?eve))))
(bind ?lilith (assert (person (name Lilith) (father ?adam) (mother ?eve))))

(defrule siblings
  ?p1 <- (person (name ?name1)
                 (father ?f1&:(neq ?f1 nil))
                 (mother ?m1&:(neq ?m1 nil)))
  ?p2 <- (person (name ?name2&:(< ?name1 ?name2))
                 {father == ?f1) {mother == ?m1))
  =>
  (printout t ?name1 " and " ?name2 " are siblings." crlf)
)

(run)

Abel and Lilith are siblings.
Cain and Lilith are siblings.
Abel and Cain are siblings.
3

TIA for any comments, kind regards
Wolfgang


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