I think Nik wrote:
> First, I just wanted to thank you for all your help.... and now, here is my latest
>issue:
> Extending the example below again, what I am trying to do is to come up with a list
>of
> people that share the same pets. For example, lets say I have the following:
>
> (defglobal ?*pet-id* = 0)
> (deftemplate pet (slot petname) (slot type)
> (slot id (default-dynamic (bind ?*pet-id* (+ ?*pet-id* 1)))))
>
> (deftemplate person (slot name) (multislot pets))
>
> (bind ?r (assert (pet (petname "rover") (type dog))))
> (bind ?f (assert (pet (petname "fluffy") (type cat))))
> (bind ?s (assert (pet (petname "swimmer") (type fish))))
>
> (bind ?f2 (assert (pet (petname "fluffy") (type cat))))
> (bind ?s2 (assert (pet (petname "swimmer") (type fish))))
>
> (assert (person (name "Fred") (pets ?r ?f ?s)))
> (assert (person (name "John") (pets ?f2 ?s2)))
>
>
> Now, I want to write a rule so that I can "glob" together person facts such that one
> person's pet list is a subset of another's. So, in the above example, I want to glob
> John with Fred, since John's pets are a subset of Fred's. However, I can't use
>typical
> intersection$ rules or any kind of rules that does matching on the pets slot, (such
>as
> the rule people-with-dogs below) because each of the pets now has a unique id. I
>can do
> the matching for just one pet, that is, if one pet of one person is a member of
>another
> person's pet list. However, I can't seem to figure out an elegant way to do it for
> multiple pets. The only way I can see seems rather clumsy, and that is to loop
>through
> each of John's pets and see if EACH of them is in Fred's pet list. I hope I'm
>describing
> my problem well.... Anyways, any help would be very much appreciated. Thanks!
>
> - Nik.
I don't know about -elegant-, but -efficient- you can probably
do. Something like this?
;; ?list1 and ?list2 are supposed to be lists of "pet" facts
;; Returns TRUE if, for each pet in list 1, list2 contains a pet with
;; the same name.
(deffunction names-are-subset (?list1 ?list2)
(bind ?set (new java.util.HashSet))
(foreach ?i ?list2
(?set add (fact-slot-value ?i petname)))
(foreach ?i ?list1
(if (not (?set contains (fact-slot-value ?i petname))) then
(return FALSE)))
(return TRUE))
(defrule glob
?p1 <- (person (name ?n1) (pets $?pets1))
?p2 <- (person (name ?n2) (pets $?pets2))
(test (and (neq ?p1 ?p2) (names-are-subset ?pets1 ?pets2)))
=> ...)
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://herzberg.ca.sandia.gov
--------------------------------------------------------------------
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]
--------------------------------------------------------------------