JESS: [EXTERNAL] Matching facts based on a slot, but not the fact's type

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

JESS: [EXTERNAL] Matching facts based on a slot, but not the fact's type

Aurelien Mazurie
Dear Jess users, 
I am still learning the ropes, and cannot find an answer to the following question either online or in the 'Jess in action' book. Is there a way to match facts in a LHS based on the presence of a slot? 

For example, I have two templates: 

(deftemplate A (slot score)) 
(deftemplate B (slot score)) 

I would like my rule to be triggered if any fact (either from template A, B, or others) have a 'score' slot with a specific value. For now I can do it by manually adding references to A and B in the LHS, but this will not scale well. I'm looking for a solution that can just work on any fact, regardless of the template they are defined from. 

Best, 
Aurelien 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: JESS: [EXTERNAL] Matching facts based on a slot, but not the fact's type

Friedman-Hill, Ernest

The short answer is “no”. Templates are like Java classes, and so this is akin to asking if you can write Java code that reads the value of a “score” member variable in any class.

 

But you can use template inheritance to achieve your goal. Templates can extend other templates; just put your “score” slot in a base template, and extend everything else that needs a “score” slot from that common base, and write your patterns to match the base template. Read about the use of “extends” in templates here:

 

http://www.jessrules.com/jess/docs/71/memory.html

 

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Aurelien Mazurie
Sent: Friday, July 26, 2013 4:43 PM
To: jess-users
Subject: JESS: [EXTERNAL] Matching facts based on a slot, but not the fact's type

 

Dear Jess users, 
I am still learning the ropes, and cannot find an answer to the following question either online or in the 'Jess in action' book. Is there a way to match facts in a LHS based on the presence of a slot? 

For example, I have two templates: 

(deftemplate A (slot score)) 
(deftemplate B (slot score)) 

I would like my rule to be triggered if any fact (either from template A, B, or others) have a 'score' slot with a specific value. For now I can do it by manually adding references to A and B in the LHS, but this will not scale well. I'm looking for a solution that can just work on any fact, regardless of the template they are defined from. 

Best, 
Aurelien 

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: JESS: [EXTERNAL] Matching facts based on a slot, but not the fact's type

Wolfgang Laun-2
In reply to this post by Aurelien Mazurie
What you are looking for is the capability of using interface names as
template names in LHS code, which is not available in Jess.

Using "extends" might help you to a certain extent, but that's
restricted to the definition of a hierarchy.

Also, consider that the solution to your problem might be a completely
different approach to structuring your facts.

-W

On 26/07/2013, Aurelien Mazurie <[hidden email]> wrote:

> Dear Jess users,
> I am still learning the ropes, and cannot find an answer to the following
> question either online or in the 'Jess in action' book. Is there a way to
> match facts in a LHS based on the presence of a slot?
>
> For example, I have two templates:
>
> (deftemplate A (slot score))
> (deftemplate B (slot score))
>
> I would like my rule to be triggered if any fact (either from template A,
> B, or others) have a 'score' slot with a specific value. For now I can do
> it by manually adding references to A and B in the LHS, but this will not
> scale well. I'm looking for a solution that can just work on any fact,
> regardless of the template they are defined from.
>
> Best,
> Aurelien
>
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
in the BODY of a message to [hidden email], NOT to the list
(use your own address!) List problems? Notify [hidden email].
--------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: JESS: [EXTERNAL] Matching facts based on a slot, but not the fact's type

Aurelien Mazurie
In reply to this post by Friedman-Hill, Ernest
<base href="x-msg://1/">
Thank you; the template inheritance mechanism was the answer.
Aurélien

On Jul 30, 2013, at 8:11 AM, "Friedman-Hill, Ernest" <[hidden email]> wrote:

The short answer is “no”. Templates are like Java classes, and so this is akin to asking if you can write Java code that reads the value of a “score” member variable in any class.
 
But you can use template inheritance to achieve your goal. Templates can extend other templates; just put your “score” slot in a base template, and extend everything else that needs a “score” slot from that common base, and write your patterns to match the base template. Read about the use of “extends” in templates here:
 
 
 
From: [hidden email] [mailto:owner-[hidden email]] On Behalf Of Aurelien Mazurie
Sent: Friday, July 26, 2013 4:43 PM
To: jess-users
Subject: JESS: [EXTERNAL] Matching facts based on a slot, but not the fact's type
 
Dear Jess users, 
I am still learning the ropes, and cannot find an answer to the following question either online or in the 'Jess in action' book. Is there a way to match facts in a LHS based on the presence of a slot? 

For example, I have two templates: 

(deftemplate A (slot score)) 
(deftemplate B (slot score)) 

I would like my rule to be triggered if any fact (either from template A, B, or others) have a 'score' slot with a specific value. For now I can do it by manually adding references to A and B in the LHS, but this will not scale well. I'm looking for a solution that can just work on any fact, regardless of the template they are defined from. 

Best, 
Aurelien 

Loading...