JESS: rule problems

View: New views
7 Messages — Rating Filter:   Alert me  

JESS: rule problems

by Joao Antunes Mourao :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

My question is about if it is possible to assign the same class of
objects several times in the same rule. I mean, let say i have a class
"Area" and I have multiple facts containing objects of the class "Area"
in the working memory. Can I do something like this:

(defrule
(Area {name=="area1"}(OBJECT ?Area1)
(Area {name=="area2"}(OBJECT ?Area2)
...
and then I can work with these objects. I tested and is not working. It
seems that jess refuses to assign two times the same class in the rule.
Of course I had import my class "Area" to jess, it can recognize it. Can
you help me about this?

Thanks,

Joao Mourao

--------------------------------------------
Unclassified email




begin:vcard
fn;quoted-printable:Jo=C3=A3o Mour=C3=A3o
n;quoted-printable;quoted-printable:Mour=C3=A3o;Jo=C3=A3o
org:Thales;Above Water Systems
adr:;;;Hengelo;;;Netherlands
email;internet:joao.mourao@...
title:THALES NETHERLANDS B.V.
tel;work:2640
note:-unclassified mail-
version:2.1
end:vcard


Re: JESS: rule problems

by Ernest Friedman-Hill :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Apr 1, 2008, at 5:39 AM, Joao Antunes Mourao wrote:

>  I tested and is not working. It
> seems that jess refuses to assign two times the same class in the  
> rule.
>

No, there's no such restriction. You can see examples of exactly this  
in the "pricing engine" demo that ships with Jess; look at the rule  
free-cd-rw-disks, for example. More likely the problem is you're  
using the same variable name in both patterns, forcing them to be  
unified, while matching some other slot to distinct values, forcing  
them to be different -- i.e., you may have written patterns that are  
impossible to satisfy.


---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences          Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 ejfried@...
Livermore, CA 94550                 http://www.jessrules.com




--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------


Re: JESS: rule problems

by Joao Antunes Mourao :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

No, I'm using diferent names for the variables. I think the problem can
be because I'm using the OBJECT, but I need to do it, because I need to
call a function defined in the class Area.

Regards,

Joao Mourao

---------------------------------------------
Unclassified email

Ernest Friedman-Hill wrote:

>
> On Apr 1, 2008, at 5:39 AM, Joao Antunes Mourao wrote:
>
>>  I tested and is not working. It
>> seems that jess refuses to assign two times the same class in the  rule.
>>
>
> No, there's no such restriction. You can see examples of exactly this
> in the "pricing engine" demo that ships with Jess; look at the rule
> free-cd-rw-disks, for example. More likely the problem is you're
> using the same variable name in both patterns, forcing them to be
> unified, while matching some other slot to distinct values, forcing
> them to be different -- i.e., you may have written patterns that are
> impossible to satisfy.
>
>
> ---------------------------------------------------------
> Ernest Friedman-Hill
> Informatics & Decision Sciences          Phone: (925) 294-2154
> Sandia National Labs                FAX:   (925) 294-2234
> PO Box 969, MS 9012                 ejfried@...
> Livermore, CA 94550                 http://www.jessrules.com
>
>
>
>
> --------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users you@...'
> in the BODY of a message to majordomo@..., NOT to the list
> (use your own address!) List problems? Notify
> owner-jess-users@....
> --------------------------------------------------------------------
>

begin:vcard
fn;quoted-printable:Jo=C3=A3o Mour=C3=A3o
n;quoted-printable;quoted-printable:Mour=C3=A3o;Jo=C3=A3o
org:Thales;Above Water Systems
adr:;;;Hengelo;;;Netherlands
email;internet:joao.mourao@...
title:THALES NETHERLANDS B.V.
tel;work:2640
note:-unclassified mail-
version:2.1
end:vcard


Re: JESS: rule problems

by Dusan Sormaz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Joao,

can you show the complete rule? Your code snippet is missing a parenthesis at the end of the first Area line.

Also when you say: "it is not working" it is not enough to understand the possible error. show either error messages or explain what is shown, for example, does error show when you load (compile) rules, or when you try to run them.

Dusan Sormaz

At 05:39 AM 4/1/2008, you wrote:
Hello,

My question is about if it is possible to assign the same class of
objects several times in the same rule. I mean, let say i have a class
"Area" and I have multiple facts containing objects of the class "Area"
in the working memory. Can I do something like this:

(defrule
(Area {name=="area1"}(OBJECT ?Area1)
(Area {name=="area2"}(OBJECT ?Area2)
....
and then I can work with these objects. I tested and is not working. It
seems that jess refuses to assign two times the same class in the rule.
Of course I had import my class "Area" to jess, it can recognize it. Can
you help me about this?

Thanks,

Joao Mourao

--------------------------------------------
Unclassified email





*********************************************************************
*
Dusan Sormaz PhD, Associate Professor
* Ohio University
* Department of Industrial and Systems Engineering
* 277 Stocker Center, Athens, OH 45701-2979
* phone: (740) 593-1545
* fax:   (740) 593-0778
* e-mail: sormaz@...
* url: http://www.ent.ohiou.edu/~sormaz
*********************************************************************



Re: JESS: rule problems

by Joao Antunes Mourao :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Very well,

When I say is not working, what I mean is that the rule is never fired
and should fire, because I have facts in the working memory for that.
Anyway, I give you the really code of the rule and the facts that are in
the database.

For a total of 5 facts in module MAIN.
f-0   (MAIN::initial-fact)
f-1   (MAIN::Entity (absoluteSpeed 11.905696218853354) (allRecords
<Java-Object:java.util.Vector>) (class <Java-Object:java.lang.Class>)
(entityType <Java-Object:tools.types.EntityType>) (id 1) (intentionType
<Java-Object:tools.types.IntentionType>) (lastRecord
<Java-Object:engines.InputDataEngine.KinematicsRecord>) (manoeuvre
<Java-Object:tools.types.Manoeuvre>) (name "UNKNOWN") (position
<Java-Object:tools.modules.Position>) (speed
<Java-Object:tools.modules.Speed>) (time 1.2071231184415078E9)
(trackStatus <Java-Object:tools.types.TrackStatus>) (OBJECT
<Java-Object:tools.modules.Entity>))
f-2   (MAIN::Entity (absoluteSpeed 8.979319067861903) (allRecords
<Java-Object:java.util.Vector>) (class <Java-Object:java.lang.Class>)
(entityType <Java-Object:tools.types.EntityType>) (id 3) (intentionType
<Java-Object:tools.types.IntentionType>) (lastRecord
<Java-Object:engines.InputDataEngine.KinematicsRecord>) (manoeuvre
<Java-Object:tools.types.Manoeuvre>) (name "UNKNOWN") (position
<Java-Object:tools.modules.Position>) (speed
<Java-Object:tools.modules.Speed>) (time 1.2071231240553708E9)
(trackStatus <Java-Object:tools.types.TrackStatus>) (OBJECT
<Java-Object:tools.modules.Entity>))
f-3   (MAIN::Area (class <Java-Object:java.lang.Class>) (id 10) (name
"Area_1") (numberOfPoints 4) (polygon <Java-Object:java.awt.Polygon>)
(OBJECT <Java-Object:tools.modules.Area>))
f-4   (MAIN::Area (class <Java-Object:java.lang.Class>) (id 11) (name
"Area_2") (numberOfPoints 4) (polygon <Java-Object:java.awt.Polygon>)
(OBJECT <Java-Object:tools.modules.Area>))
For a total of 5 facts in module MAIN.


*(defrule entity-out-side-lane
    "if the entity is sailing outside ot the sea-lane"
    (Area {name == "Area_1"} (OBJECT ?Area1))
    (Area {name == "Area_2"} (OBJECT ?Area2))
    (Entity (OBJECT ?Entity &:(?Area1 entityIsOutsideArea ?Entity) &:
(?Area2 entityIsOutsideArea ?Entity)))
    =>
    (add (new Anomaly "entity-out-side-lane" 24 ?Entity "if the entity
is sailing outside ot the sea-lane" 1)))
*
Now if you look to the facts f3 and f4, you will see that I have two
areas, one named "Area_1", other "Area_2".  Fact f1 and f2 are two
entities. One of the entities is both outside of "Area_1" and "Area_2",
so I guess the rule should be fired. But don't . Any ideas?

Regards,

Joao

Dusan Sormaz wrote:

> Joao,
>
> can you show the complete rule? Your code snippet is missing a
> parenthesis at the end of the first Area line.
>
> Also when you say: "it is not working" it is not enough to understand
> the possible error. show either error messages or explain what is
> shown, for example, does error show when you load (compile) rules, or
> when you try to run them.
>
> Dusan Sormaz
>
> At 05:39 AM 4/1/2008, you wrote:
>
>> Hello,
>>
>> My question is about if it is possible to assign the same class of
>> objects several times in the same rule. I mean, let say i have a class
>> "Area" and I have multiple facts containing objects of the class "Area"
>> in the working memory. Can I do something like this:
>>
>> (defrule
>> (Area {name=="area1"}(OBJECT ?Area1)
>> (Area {name=="area2"}(OBJECT ?Area2)
>> ....
>> and then I can work with these objects. I tested and is not working. It
>> seems that jess refuses to assign two times the same class in the rule.
>> Of course I had import my class "Area" to jess, it can recognize it. Can
>> you help me about this?
>>
>> Thanks,
>>
>> Joao Mourao
>>
>> --------------------------------------------
>> Unclassified email
>>
>>
>>
>>
>>
> *********************************************************************
> * Dusan Sormaz PhD, Associate Professor
> * Ohio University
> * Department of Industrial and Systems Engineering
> * 277 Stocker Center, Athens, OH 45701-2979
> * phone: (740) 593-1545
> * fax:   (740) 593-0778
> * e-mail: sormaz@...
> * url: http://www.ent.ohiou.edu/~sormaz
> <http://www.ent.ohiou.edu/%7Esormaz>
> *********************************************************************
>

begin:vcard
fn;quoted-printable:Jo=C3=A3o Mour=C3=A3o
n;quoted-printable;quoted-printable:Mour=C3=A3o;Jo=C3=A3o
org:Thales;Above Water Systems
adr:;;;Hengelo;;;Netherlands
email;internet:joao.mourao@...
title:THALES NETHERLANDS B.V.
tel;work:2640
note:-unclassified mail-
version:2.1
end:vcard


Re: JESS: rule problems

by Joao Antunes Mourao :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I discovered the problem. Somehow, jess doesn't like the comparisson
like { name == "Area_1"}, but instead if I use (name /Area_1/) it works.
This sounds very weird because for only one line comparison it works,
but to subsequent lines doesn't. I mean:

(defrule
(Area {name=="area1"}(OBJECT ?Area1))
=>
it works. But if I make this

(defrule
(Area {name=="area1"}(OBJECT ?Area1))
(Area {name=="area2"}(OBJECT ?Area2))
=>
doesn't. Now if I use this

(Area (name /area1/)(OBJECT ?Area1)
(Area (name /area2/)(OBJECT ?Area2)
=>
it works just fine. Strange but it happens.





Dusan Sormaz wrote:

> Joao,
>
> can you show the complete rule? Your code snippet is missing a
> parenthesis at the end of the first Area line.
>
> Also when you say: "it is not working" it is not enough to understand
> the possible error. show either error messages or explain what is
> shown, for example, does error show when you load (compile) rules, or
> when you try to run them.
>
> Dusan Sormaz
>
> At 05:39 AM 4/1/2008, you wrote:
>
>> Hello,
>>
>> My question is about if it is possible to assign the same class of
>> objects several times in the same rule. I mean, let say i have a class
>> "Area" and I have multiple facts containing objects of the class "Area"
>> in the working memory. Can I do something like this:
>>
>> (defrule
>> (Area {name=="area1"}(OBJECT ?Area1)
>> (Area {name=="area2"}(OBJECT ?Area2)
>> ....
>> and then I can work with these objects. I tested and is not working. It
>> seems that jess refuses to assign two times the same class in the rule.
>> Of course I had import my class "Area" to jess, it can recognize it. Can
>> you help me about this?
>>
>> Thanks,
>>
>> Joao Mourao
>>
>> --------------------------------------------
>> Unclassified email
>>
>>
>>
>>
>>
> *********************************************************************
> * Dusan Sormaz PhD, Associate Professor
> * Ohio University
> * Department of Industrial and Systems Engineering
> * 277 Stocker Center, Athens, OH 45701-2979
> * phone: (740) 593-1545
> * fax:   (740) 593-0778
> * e-mail: sormaz@...
> * url: http://www.ent.ohiou.edu/~sormaz
> <http://www.ent.ohiou.edu/%7Esormaz>
> *********************************************************************
>

begin:vcard
fn;quoted-printable:Jo=C3=A3o Mour=C3=A3o
n;quoted-printable;quoted-printable:Mour=C3=A3o;Jo=C3=A3o
org:Thales;Above Water Systems
adr:;;;Hengelo;;;Netherlands
email;internet:joao.mourao@...
title:THALES NETHERLANDS B.V.
tel;work:2640
note:-unclassified mail-
version:2.1
end:vcard


Re: JESS: rule problems

by Ernest Friedman-Hill :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Apr 2, 2008, at 7:58 AM, Joao Antunes Mourao wrote:

> I discovered the problem. Somehow, jess doesn't like the comparisson
> like { name == "Area_1"}, but instead if I use (name /Area_1/) it  
> works.
> This sounds very weird because for only one line comparison it works,
> but to subsequent lines doesn't.


In Jess 7.0,  the "{name == "area1"}" syntax creates a variable named  
"?name" and binds it to the slot's value; that variable is then  
available on the rule's RHS. There's a big problem with that, though:  
what if you want to use that syntax for that slot for two different  
patterns? What happens is that the same variable ?name is used for  
both patterns, unifying them. So you're effectively matching facts  
with a pattern like name&"area1"&"area2" -- and that will never match.

That's why the semantics have changed in Jess 7.1. The variable is no  
longer created. Multiple "java syntax" patterns are completely  
independent.


---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences          Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 ejfried@...
Livermore, CA 94550                 http://www.jessrules.com




--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------