Jess considers the data types RU.STRING, RU.INTEGER and RU.ATOM to be
different, even if they would all be represented by the same string. I have
had a lot of trouble debugging rules that would not fire because I was
inconsistent in using strings versus literals when setting up my data.


In the short example below, Jess will assert two different facts for values
with and without quotes

Jess> (assert (dummy red))
<Fact-4>
Jess> (assert (dummy "red"))
<Fact-5>                    // "red" != red
Jess> (assert (dummy red))
FALSE                       //fact already exists
Jess> (assert (dummy 55))
<Fact-6>
Jess> (assert (dummy "55"))
<Fact-7>                    // "55" != 55
Jess> (assert (dummy "55"))
FALSE                       //fact already exists
Jess> (facts)
f-4   (MAIN::dummy red)
f-5   (MAIN::dummy "red")
f-6   (MAIN::dummy 55)
f-7   (MAIN::dummy "55")


You can use the Jess interpreter prompt to interactively see that the Java
API is able to create any of these three data types. Working from the Java
side, the differences are much more obvious. 

Jess> (deftemplate NA ""
        (slot name) (slot address)
)
TRUE

Jess> (bind ?f (new jess.Fact "NA" (engine)))
<External-Address:jess.Fact>

Jess> (bind ?vs (new jess.Value "55" (get-member jess.RU STRING)))
<External-Address:jess.Value>

Jess> (bind ?vi (new jess.Value 55 (get-member jess.RU INTEGER)))
<External-Address:jess.Value>

Jess> (?f setSlotValue "name" ?vs)
Jess> (?f setSlotValue "address" ?vi)

Jess> (assert ?f)
<Fact-1>

Jess> (facts)
f-0   (MAIN::initial-fact)
f-1   (MAIN::NA (name "55") (address 55))
For a total of 2 facts.

Jess> (assert (NA (name "string") (address notstring)))
<Fact-2>

Jess> (facts)
f-0   (MAIN::initial-fact)
f-1   (MAIN::NA (name "55") (address 55))
f-2   (MAIN::NA (name "string") (address notstring))
For a total of 3 facts.

Jess> (bind ?va (new jess.Value "atom" (get-member jess.RU ATOM)))
<External-Address:jess.Value>

Jess> (?f setSlotValue "address" ?va)

Jess> (assert ?f)
<Fact-3>

Jess> (facts)
f-0   (MAIN::initial-fact)
f-1   (MAIN::NA (name "55") (address 55))
f-2   (MAIN::NA (name "string") (address notstring))
f-3   (MAIN::NA (name "55") (address atom))
For a total of 4 facts.


Note that in your sample code, you set the street_number to a string in
Java, but to a literal when using the Jess Interpreter to assert facts.

numberf.setSlotValue("street_number", new Value("48", RU.STRING) );

That fact would not match one set up as follows:
numberf.setSlotValue("street_number", new Value(48, RU.INTEGER) );

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Matthew Hutchinson
Sent: Friday, April 15, 2005 11:28 AM
To: [email protected]
Subject: JESS: Rule not firing

Hi everyone,

To get used to Jess, I have been executing commands at the Jess
prompt, and then trying the same commands using the API.

After doing all the usual things (new rete engine, creating a
deftemplate, populating the slots and adding the template) everything
works fine when asserting a particular fact using executeCommand - and
my rule fires. However, when I try and assert the fact using the API
(same slot values, head name etc.), the rule does not fire.

This code works:
engine.executeCommand("(assert (conventionalAddress (number_prefix
NIL) (street_number 48) (street_name Marlow) (street_type Street)
(suburb_name Wembley) (city_name Perth) (state_name WA) (post_code
6014) ))");

but the API equivalent does not:
Fact f = new Fact("conventionalAddress", engine);
f.setSlotValue("number_prefix", new Value("", RU.STRING) );
f.setSlotValue("street_number", new Value("48", RU.STRING) );
f.setSlotValue("street_name", new Value("Marlow", RU.STRING) );
f.setSlotValue("street_type", new Value("Street", RU.STRING) );
f.setSlotValue("suburb_name", new Value("Wembley", RU.STRING) );
f.setSlotValue("city_name", new Value("Perth", RU.STRING) );
f.setSlotValue("state_name", new Value("WA", RU.STRING) );
f.setSlotValue("post_code", new Value("6014", RU.STRING) );
engine.assertFact(f);

Regardless of which is used, this is the rule I'm trying to fire:
engine.executeCommand("(defrule find-suburb (conventionalAddress
(post_code 6014) (suburb_name ?s) ) => (store RESULT ?s ) )");

I just can't see how the fact is any different when done via the API!


Thanks, and I hope I haven't been posting the mailing list too much. (!)
Best wishes,
Matt




-- 
Matthew Hutchinson
Ph.D. Candidate

Department of Spatial Sciences
Curtin University of Technology
GPO Box U1987
Perth, Western Australia 6845

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

--------------------------------------------------------------------
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