Re: JESS: Getting a handle to the fact that matched given pattern

2004-05-27 Thread ejfried
I think Amit Chopra wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]

   (defrule foo-res
(foo (name ?x)) = (call 'fact that matched' assign))
 
 I want to know how to find 'fact that matched' to be able
 to call assign on it.


OK, two things. First, to get a reference to the actual Fact object
that matches any pattern in any rule, you simply bind that pattern to
a variable in the rule left-hand-side using the - operator:

  (defrule foo-res
?foo - (foo (name ?x))
=
;; the variable ?foo is the matching jess.Fact object
...

But second, as you say this is a shadow fact and you want to call a
method on it I think what you mean is that you want to call a method
on the object that's being shadowed. There's a reference to that
object in the OBJECT slot of the shadow fact, so instead what you
actually want to do is

  (defrule foo-res
(foo (name ?x) (OBJECT ?foo))
=
;; the variable ?foo is the JavaBean and you can call assign



-
Ernest Friedman-Hill  
Science and Engineering PSEsPhone: (925) 294-2154
Sandia National LabsFAX:   (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]




RE: JESS: Getting a handle to the fact that matched given pattern

2004-05-27 Thread Jason Morris
Amit,

I just did something like this yesterday

First I wrote a defquery as you suggested:

(defquery find-foo-by-name
  (declare (variables ?name))
  (foo (name ?name)))

This returns an iterator of all foos with the given name

Now, I added a function to wrap the query:

(deffunction get-foos-by-name (?name)
Returns a foo reference of a given name
(bind ?itt (run-query find-foo-by-name ?name))
(while (?itt hasNext)
(bind ?token (call ?itt next))
(bind ?factRef (call ?token fact 1)))
(return ?factRef)))

Now, from the RHS of a rule, you should be able to write something like:

(defrule foo-res
  (foo (name ?x))
  =
  (call (get-foos-by-name (?name)) assign)))

Hope this works...Ernest will probably have something more elegant!  :-D

Cheers!
-JM

--


Jason Morris
Morris Technical Solutions
[EMAIL PROTECTED]
www.morristechnicalsolutions.com
fax/phone: 503.692.1088





deffunction to wrap the defquery

 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
 Behalf Of Amit Chopra
 Sent: Thursday, May 27, 2004 10:58 AM
 To: [EMAIL PROTECTED]
 Subject: JESS: Getting a handle to the fact that matched given pattern


 Hi all,

 I am trying to find the fact that matches a given pattern in rule.
 I tried something, but it wouldn't work.

 I want to do something like this (this does not work in Jess, its
 pseudocode). foo is a shadow fact of a java object that has a
 method, lets say, 'assign'.

   (defrule foo-res
(foo (name ?x)) = (call 'fact that matched' assign))

 I want to know how to find 'fact that matched' to be able
 to call assign on it.

 I suspect I'll have to use defquery to do this. But then,
 matching and searching are not atomic, in that, they'll
 be two separate operations.

 Help is appreciated.

 Sincerely,
 Amit.

 
 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]




RE: JESS: Getting a handle to the fact that matched given pattern

2004-05-27 Thread Jason Morris
Oops... I may have misunderstood your question.  Sorry... completely mixed
up my code.
Disregard that last suggestion.

 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
 Behalf Of Amit Chopra
 Sent: Thursday, May 27, 2004 10:58 AM
 To: [EMAIL PROTECTED]
 Subject: JESS: Getting a handle to the fact that matched given pattern


 Hi all,

 I am trying to find the fact that matches a given pattern in rule.
 I tried something, but it wouldn't work.

 I want to do something like this (this does not work in Jess, its
 pseudocode). foo is a shadow fact of a java object that has a
 method, lets say, 'assign'.

   (defrule foo-res
(foo (name ?x)) = (call 'fact that matched' assign))

 I want to know how to find 'fact that matched' to be able
 to call assign on it.

 I suspect I'll have to use defquery to do this. But then,
 matching and searching are not atomic, in that, they'll
 be two separate operations.

 Help is appreciated.

 Sincerely,
 Amit.

 
 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]




Re: JESS: Getting a handle to the fact that matched given pattern

2004-05-27 Thread Amit Chopra
Ernest and Jason,
Thanks for replying, that should be adequate.
amit.
[EMAIL PROTECTED] wrote:
I think Amit Chopra wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
 

 (defrule foo-res
  (foo (name ?x)) = (call 'fact that matched' assign))
I want to know how to find 'fact that matched' to be able
to call assign on it.
   


OK, two things. First, to get a reference to the actual Fact object
that matches any pattern in any rule, you simply bind that pattern to
a variable in the rule left-hand-side using the - operator:
 (defrule foo-res
   ?foo - (foo (name ?x))
   =
   ;; the variable ?foo is the matching jess.Fact object
   ...
But second, as you say this is a shadow fact and you want to call a
method on it I think what you mean is that you want to call a method
on the object that's being shadowed. There's a reference to that
object in the OBJECT slot of the shadow fact, so instead what you
actually want to do is
 (defrule foo-res
   (foo (name ?x) (OBJECT ?foo))
   =
   ;; the variable ?foo is the JavaBean and you can call assign

-
Ernest Friedman-Hill  
Science and Engineering PSEsPhone: (925) 294-2154
Sandia National LabsFAX:   (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]

 


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]