I think Weihua Zhou wrote:
> hi, there, I just wonder if you know how to create fact in the following
> case, which I am working on.
>
> (defrule test
> (message ?who ?action ?content)
> =>
> (assert ?content)
> )
>
> this rule doesn't work. basically I am trying to assert message content
> into a rete engine. I try both ?content and $content. but neither of
> them works. do you have any idea how I can construct a fact based on
> that content held by ?content or $?content? what kind of type is the
> variable of ?content here? for your reference, one example of message
> could be like: (message david reply (i_know (fact A in stack 1)). and in
> this case, ?content would be (i_know (fact A in stack 1)).
First of all, be aware that you can only assert well-formed facts;
facts in Jess aren't arbitrary lists. Be sure you've read section 2.7 of
the Jess manual. For (i_know (fact A in stack 1)) to be a valid fact,
you would need to have previously defined a deftemplate like
(deftemplate i_know (multislot fact) ...)
Secondly, note that nested multifield variables are "flattened;" it is
not possible to create (using legal methods, anyway) a variable that
contains (i_know (fact A in stack 1)) - any attempt to create one will
end up creating the flat list (i_know fact A in stack 1). But, as
another correspondent suggested, a string variable could contain a string
rendering of such a nested list.
So, lastly: the arguments to the (assert) function have to be
well-formed facts, and only text parsed as a fact by the Jess parser
qualifies as such. Therefore, this works, because the parser can see
the fact's head and slot names:
(bind $?temp (create$ A in stack 1))
(assert (i_know (fact $?temp)))
but this doesn't, because the parser can't see what kind of fact it is.
(bind $?temp (create$ a b c))
(assert $?temp)
If you have a fact as a string, or the name of a fact or a slot in
variable, and you want to assert it somehow, the trick is to assemble
the command as a string and then run it through the parser using
"eval". For example:
c:/users/root> java jess.Main
Jess, the Java Expert System Shell
Copyright (C) 1998 E.J. Friedman Hill and the Sandia Corporation
Jess Version 5.0 1/28/2000
Jess> (bind $?temp (create$ a b c))
(a b c)
Jess> (bind ?s (str-cat "(assert (" $?temp "))") )
"(assert (a b c))"
Jess> (eval ?s)
<Fact-0>
Jess> (facts)
f-0 (a b c)
For a total of 1 facts.
Jess>
I used the intermediate variable '?s' just so you could see str-cat's
output; you could do the eval and str-cat in one nested function
call, of course. The same technique would work for your example fact,
given the caveats about flat lists and the existence of the deftemplate.
>
> thanks a lot for your information and advice. I look forward to hearing
> from you soon.
>
> David
>
> ---------------------------------------------------------------------
> 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]
> ---------------------------------------------------------------------
>
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
Org. 8920, MS 9012 [EMAIL PROTECTED]
PO Box 969 http://herzberg.ca.sandia.gov
Livermore, CA 94550
---------------------------------------------------------------------
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]
---------------------------------------------------------------------