On Mar 28, 2007, at 7:57 PM, [EMAIL PROTECTED] wrote:
Just a quick question on writing a rule where it just requires one
or the
other templates to match. Below is a rule which I want to update
the type
of a cow from "Calve" to "Breeding" if there is another cow (calve)
with
either its dam_id as the mothers cattle_id OR its surrogate_id as the
mothers cattle_id but unsure of how to implement the either/or
part. I saw
another thread using $? but I don't use multishots anywhere in my
"farming-cattle" template. Thanks.
----------------------------------------------
(defrule update-type
(farming-cattle (cattle_id ?mother)(sex "F")(type "Calve"))
(farming-cattle (cattle_id ?child)(type "Calve")(dam_id ?mother))
(farming-cattle (cattle_id ?child)(type "Calve")(surrogate_id ?
mother))
There are two ways to do this, with subtly different meanings. In the
present case, either would work, but in similar rules you might need
one or the other.
To say "there is a child with dam_id ?mother, or a child with
surrogate_id ?mother, you'd write
(defrule update-type
(farming-cattle (cattle_id ?mother)(sex "F")(type "Calve"))
(or (farming-cattle (cattle_id ?child)(type "Calve")(dam_id ?
mother))
(farming-cattle (cattle_id ?child)(type "Calve")
(surrogate_id ?mother)))
To say "there is a child with either dam_id or surrogate_id equal to ?
mother", you'd say something like
(defrule update-type
(farming-cattle (cattle_id ?mother)(sex "F")(type "Calve"))
(farming-cattle (cattle_id ?child) (type "Calve")
(dam_id ?di) (surrogate_id ?si&:(or (eq ?di ?
mother) (eq ?si ?mother))))
or using the new "Java patterns" syntax in Jess 7, you could say
(defrule update-type
(farming-cattle (cattle_id ?mother)(sex "F")(type "Calve"))
(farming-cattle (cattle_id ?child) (type "Calve")
{dam_id == ?mother || ?surrogate_id == ?mother})
Of these three, I'd choose the last one, personally.
---------------------------------------------------------
Ernest Friedman-Hill
Advanced Software Research 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]
--------------------------------------------------------------------