Thanks!  This is exactly what I need.  As you can see in my follow up email,
I tried to do this transformation, but for some odd reason ­ I think it was
my placement of (watch all) - I didn¹t see all the assertions.  However, I
still have the endless loop issue if I combine this with the
removeTransformation rule.


On 9/7/07 9:40 AM, "Robert Kirby" <[EMAIL PROTECTED]> wrote:

> This can all be combined in a single rule without a "foreach" loop.
> 
> (defrule manage-source-templates
>     "Logically assert or retract templates for source"
>     (logical (source (id ?id) (templates $? ?template $?)))
>     (not (transform (source ?id) (template ?template)))
>     =>
>     (assert (transform (source ?id) (template ?template))))
> 
> Bob Kirby
> 
> At 09:11 AM 9/7/2007, Ernest Friedman-Hill wrote:
>> Same idea:
>> 
>> (defrule removeTransforms
>>     ?t <- (transform (source ?id) (template ?t))
>>     (not (source (id ?id)(templates $? ?t $?))
>> =>
>>     (retract ?t))
>> 
>> 
>> On Sep 7, 2007, at 11:57 AM, Hal Hildebrand wrote:
>>> Doh!  That does work well and I'll certainly replace my cheesy
>>> solution with this, but one of the issues I'm dealing with is that the set
>>> of templates can change and I would like to ensure that as changes to the
>>> list of templates occur, the corresponding transforms are asserted or
>>> retracted.
>>> Sorry, this is an additional constraint I would like to satisfy that I
>>> should have noted.
>>> 
>>> 
>>> On 9/7/07 8:28 AM, "Wolfgang Laun" <[EMAIL PROTECTED]>
>>> wrote:
>>>> Assuming that the absence of any "transform" fact with a "source"
>>>> slot equal to the "id" slot of a new "source" fact is the criterion for
>>>> creating the "transform" facts:
>>>> 
>>>> (defrule makeTransforms
>>>>     ?s <- (source (id ?id)(templates $?templates))
>>>>     (not (transform (source ?id)))
>>>> =>
>>>>     (foreach ?temp $?templates
>>>>         (assert (transform (source ?id) (template ?temp))))
>>>> )
>>>> 
>>>> kr
>>>> Wolfgang
>>>> 
>>>> Hal Hildebrand wrote:
>>>>> I have a system where I need to ensure that for every member of a
>>>>> list, there is a fact which contains that member.  For example, here's
>>>>> my domain:
>>>>> 
>>>>> 
>>>>> (deftemplate source (slot id) (multislot templates))
>>>>> (deftemplate transform (slot source) (slot template))
>>>>> 
>>>>> 
>>>>> What I would like is to write some rules that ensure that for ever member
>>>>> of the templates slot of a "source", I have a corresponding transform.  If
>>>>> I assert:
>>>>> 
>>>>> (assert source (id 1) (templates (create$ a b c)))
>>>>> 
>>>>> I would like to see three facts asserted in response:
>>>>> 
>>>>> (assert transform (source 1) (template a))
>>>>> (assert transform (source 1) (template b))
>>>>> (assert transform (source 1) (template c))
>>>>> 
>>>>> 
>>>>> I have accomplished this by creating an intermediary fact and some rules
>>>>> which essentially cycle through the list of templates in the source,
>>>>> asserting a transform for each.  However, this just feels wrong.  It seems
>>>>> like I should be able to express this without the intermediary facts.
>>>>> 
>>>>> Perhaps this is where backward chaining would be useful?  Or perhaps I can
>>>>> use the new "accumulate" CE?  Or, have I already found the solution using
>>>>> an intermediary fact to cycle through the list of templates?
>>>>> 
>>>>> Any help/suggestions would be appreciated.
>> 
>> ---------------------------------------------------------
>> 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
> 


Reply via email to