I think Emmanuel Shyllon wrote:
> Hi,
> Given the following: 
> Rete engine = new Rete ();
>                         Deftemplate d =
>                         new Deftemplate("Aus-Address", "A Aus-Address",
> engine);
>                         d.addSlot("state-territ-name", Funcall.NIL,  
> "STRING");
>                         d.addSlot("minPostCode", Funcall.NIL, "STRING");
>                         d.addSlot("maxPostCode", Funcall.NIL, "STRING");
>                        d.addMultiSlot("CommonFormState",  Funcall.NILLIST);
>                         engine.addDeftemplate(d);

It absolutely confounds me why anyone would prefer the above to the
absolutely equivalent

engine.executeCommand("(deftemplate Aus-Address \"A Aus-Address\"" +
                      "(slot state-territ-name)" +
                      "(slot minPostCode)" +
                      "(slot maxPostCode)" +
                      "(multislot CommonFormState))");

> //data for WA
>                                     Fact f = new Fact("Aus-Address", engine);
>                                     f.setSlotValue("state-territ-name",
> new Value("Western Australia", RU.STRING));
>                                     f.setSlotValue("minPostCode", new 
> Value("6000", RU.STRING));
>                                     f.setSlotValue("maxPostCode", new 
> Value("6999", RU.STRING));
>                                     ValueVector CommonFormState = new  
> ValueVector();
>                                     CommonFormState.add(new Value("WA",  
>                                     CommonFormState.add(new Value("W
> Australia", RU.STRING));
>                                     CommonFormState.add(new Value("West.
> Australia", RU.STRING));
>                                     f.setSlotValue("CommonFormState",
> new Value(CommonFormState, RU.LIST));
>                                     engine.assertFact(f);

Or for the above, 

engine.assertString("(Aus-Address" +
        "(state-territ-name \"Western Australia\")" +
        "(minPostCode 6000)" +
        "(maxPostCode 6999)" +
        "(CommonFormState \"WA\" \"W Australia\" \"West. Australia\"))");

Far superior to either your code or my code, of course, would be to
define Jess code in a separate file containing only Jess code; then it
can be formatted and edited properly, and decoupling it from your Java
code makes the whole application easier to develop and especially to
maintain over time.

> I have tried to define the following rule, but it did not work as stated
> below:
>    String ruleString = new String();
>    ruleString = "(defrule findProperState (Aus-Address
> (state-territ-name ?x) (CommonFormState \"W Australia\")) => (printout t
> \"result is: \" ?x crlf) )" ;
>                                     engine.executeCommand(ruleString);

This will define a rule, but not fire it; you probably know that, but
in case you don't rules don't fire until you call Rete.run().

But in this case, the rule is wrong. This matches a fact where the
CommonFormState slot contains only the string "W Australia"; you want
to match if it contains that among any other contents. To do that,
include blank multifields before and after the field you're matching,
which means "any number of items, followed by this one item, followed
by any number of other items.

(CommonFormState $? \"W Australia\" $?)

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://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]

Reply via email to