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.
--- [EMAIL PROTECTED] wrote:
> Your basic problem can be stated thusly: you've got two facts:
>
> (pet (type dog) (name rover))
> (pet (type dog) (name rover))
>
> and Jess thinks there's just one. As long as two facts contain
> indistinguishable data, they're indistinguishable to Jess. So you have
> to make them different. The simplest way: add an "object identifier"
> slot to the "pet" template. You can even use "default-dynamic" to set
> the unique IDs automatically:
> (defglobal ?*pet-id* = 0)
> (deftemplate pet (slot type) (slot rover)
> (slot id (default-dynamic
> (bind ?*pet-id* (+ ?*pet-id* 1)))))
>
> Another way to get unique objects is to actually use Java objects as
> working memory elements -- look at the defclass and definstance
> functions.
>
> I think Nik wrote:
> > Hi all,
> >
> > I'm having trouble with my work email account, so I'm sending from this one.....
> >
> > Okay, so I was able to rewrite my code so as to use the functionality from
> > the example below. However, I've come across another problem which I can't
> > seem to find a decent solution to. Without going into too much detail, my
> > basic program is a Java program that is getting fact attributes over a
> > socket and asserts facts into a Rete object that is continually resident.
> > I'll illustrate my problem by extending the code below. Now suppose over
> > the socket I get the fact attributes for Fred whose pets are fluffy the cat,
> > rover the dog, and his toy is the red guitar. Now suppose some time later,
> > I get fact attributes for John who has no toys, but has one pet, who just
> > happens to be a dog and who just happens to be called rover. Basically what
> > I am saying is that some of the facts are going to be the same. Since I am
> > getting the attributes over a socket, I am simply asserting them into the
> > Rete object as soon as I get them. Thus, when I try to assert the fact:
> >
> > (person (name "John") (pets (assert (pet (name "rover") (type dog)))))
> >
> > JESS will return FALSE for the pets multifield, because (pet (name "rover")
> > (type dog)) has already been asserted. The only way I can see to get out of
> > this bind is to pre-process the facts inside of Java and compare them to
> > facts already asserted in JESS. This seems pretty messy, so there has got
> > to be a better way. As always, any help is highly appreciated. Thanks!
> >
> > - Nik.
> >
> >
> > ----- Original Message -----
> > From: <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Tuesday, February 04, 2003 6:44 PM
> > Subject: Re: JESS: creating fact attributes with mulitple sub-attributes
> >
> >
> > > You just have to think about it the right way:
> > >
> > > 1) Jess's working memory is something like a relational database in
> > > "normal form." Each fact is like a single row in one table.
> > >
> > > 2) Think of an "object-relational mapping" in which objects correspond
> > > to table rows.
> > >
> > > 3) Finally, note that Java objects don't have members with submembers
> > > with subsubmembers... they have members. The members themselves have
> > > members. Those members have members, etc.
> > >
> > > OK, so...
> > >
> > > (deftemplate pet (slot name) (slot type))
> > > (deftemplate toy (slot color) (slot type))
> > > (deftemplate person (slot name) (multislot toys) (multislot pets))
> > >
> > > (bind ?r (assert (pet (name "rover") (type dog))))
> > > (bind ?f (assert (pet (name "fluffy") (type cat))))
> > > (bind ?g (assert (toy (color red) (type guitar))))
> > >
> > > (assert (person (name "Fred") (toys ?g) (pets ?r ?f)))
> > >
> > > (defrule people-with-dogs
> > > ?d <- (pet (type dog) (name ?dog-name))
> > > (person (name ?person-name) (pets $? ?d $?))
> > > =>
> > > (printout t ?person-name " has a dog named " ?dog-name crlf))
> > >
> > > You can carry this to an arbitrarily deep level.
> > >
=====
------------------------------------------------------
You gotta dream like you're gonna live forever,
And you gotta live like you're gonna die tomorrow...
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.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]
--------------------------------------------------------------------