Re: JESS: modifying facts

2007-07-19 Thread Ernest Friedman-Hill
If you just want to keep the most current data, then you have two  
choices:


1) When an update comes in, find the old record for that track in  
Jess's working memory, delete it, and add the new data (or modify  
it). That finding step represents some potentially avoidable work  
(although depending on how your data is structured, it may be a fast  
operation in Jess).


- or -

2) Remember ( I want to say keep track of, but that'd be  
confusing!) the association between each track and its working memory  
record(s), and then when an update is available, you can do the  
replacement efficiently.


For version 1), you might use a defquery to find the old facts so you  
can remove them. For version 2), you might use a data structure  
outside of Jess to serve as an adapter.


On Jul 18, 2007, at 3:24 PM, Krasnigor, Scott L (N-AST) wrote:

I have track kinematic data in working memory. When a track’s  
kinematics are updated, I need to modify the associated kinematic  
data in working memory. I tried using the add method, however,  
looking at the watch statements, new facts were being created  
instead of modifying the existing facts. I realized the user is  
creating new kinematic objects for each update instead of using  
existing objects so that I am unable to use add to update existing  
kinematic facts in working memory. I am curious what would be the  
most efficient way to perform this update. Thanks for any assistance.




Scott




-
Ernest Friedman-Hill
Advanced Software Research  Phone: (925) 294-2154
Sandia National LabsFAX:   (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://www.jessrules.com


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]




JESS: modifying facts

2007-07-18 Thread Krasnigor, Scott L (N-AST)
I have track kinematic data in working memory. When a track's kinematics
are updated, I need to modify the associated kinematic data in working
memory. I tried using the add method, however, looking at the watch
statements, new facts were being created instead of modifying the
existing facts. I realized the user is creating new kinematic objects
for each update instead of using existing objects so that I am unable to
use add to update existing kinematic facts in working memory. I am
curious what would be the most efficient way to perform this update.
Thanks for any assistance.

 

Scott



JESS: Modifying facts that are created from a definstance notworking

2002-02-01 Thread Villanueva, Ruben

  When I try to modify a fact created from a definstance of a Java bean that has 
property change support the fact does not get modified right away if the defistance 
function was called with the static parameter. Using the Simple.java bean that comes 
with Jess, here are the steps that I took and the results.


When creating the fact using definstance with the dynamic parameter the modify 
function seems to work

C:\amber\Jess\Jess60java -cp .  jess.Main

Jess, the Java Expert System Shell
Copyright (C) 1998 E.J. Friedman Hill and the Sandia Corporation
Jess Version 6.0 12/7/2001

Jess (defclass simple jess.examples.simple.Simple)
jess.examples.simple.Simple
Jess (ppdeftemplate simple)
(deftemplate MAIN::simple extends MAIN::__fact \$JAVA-OBJECT$ 
jess.examples.simple.Simple\
 (slot class (default External-Address:jess.SerializablePD))
 (slot fraction (default External-Address:jess.SerializablePD))
 (slot name (default External-Address:jess.SerializablePD))
 (slot serial (default External-Address:jess.SerializablePD))
 (slot truth (default External-Address:jess.SerializablePD))
 (slot OBJECT (type 2048)))
Jess  (bind ?sb (new jess.examples.simple.Simple Dave))
External-Address:jess.examples.simple.Simple
Jess (definstance simple ?sb dynamic)
Fact-0
Jess (facts)
f-0   (MAIN::simple (class External-Address:java.lang.Class) (fraction 0.0) (name 
Dave) (serial 0) (truth FALSE) (OBJECT 
External-Address:jess.examples.simple.Simple))
For a total of 1 facts.
Jess (defrule change_name ?f - (simple (name Dave)) = (modify ?f (name Tom)))
TRUE
Jess (rules)
MAIN::change_name
For a total of 1 rules.
Jess (ppdefrule change_name)
(defrule MAIN::change_name
   ?f - (MAIN::simple (name \Dave\))
   =
   (modify ?f (name \Tom\)))
Jess (watch all)
TRUE
Jess (run)
FIRE 1 MAIN::change_name f-0
 == f-0 (MAIN::simple (class External-Address:java.lang.Class) (fraction 0.0) (name 
Dave) (serial 0) (truth FALSE)
(OBJECT External-Address:jess.examples.simple.Simple))
 == f-0 (MAIN::simple (class External-Address:java.lang.Class) (fraction 0.0) (name 
Tom) (serial 0) (truth FALSE) (OBJECT 
External-Address:jess.examples.simple.Simple))
1
Jess (facts)
f-0   (MAIN::simple (class External-Address:java.lang.Class) (fraction 0.0) (name 
Tom) (serial 0) (truth FALSE) (OBJECT 
External-Address:jess.examples.simple.Simple))
For a total of 1 facts.
Jess (jess-version-number)
6.0
Jess

When creating the fact using definstance with the static parameter the modify function 
does not seem to work

C:\amber\Jess\Jess60java -cp .  jess.Main

Jess, the Java Expert System Shell
Copyright (C) 1998 E.J. Friedman Hill and the Sandia Corporation
Jess Version 6.0 12/7/2001

Jess (defclass simple jess.examples.simple.Simple)
jess.examples.simple.Simple
Jess (ppdeftemplate simple)
(deftemplate MAIN::simple extends MAIN::__fact \$JAVA-OBJECT$ 
jess.examples.simple.Simple\
 (slot class (default External-Address:jess.SerializablePD))
 (slot fraction (default External-Address:jess.SerializablePD))
 (slot name (default External-Address:jess.SerializablePD))
 (slot serial (default External-Address:jess.SerializablePD))
 (slot truth (default External-Address:jess.SerializablePD))
 (slot OBJECT (type 2048)))
Jess  (bind ?sb (new jess.examples.simple.Simple Dave))
External-Address:jess.examples.simple.Simple
Jess (definstance simple ?sb static)
Fact-0
Jess (facts)
f-0   (MAIN::simple (class External-Address:java.lang.Class) (fraction 0.0) (name 
Dave) (serial 0) (truth FALSE) (OBJECT 
External-Address:jess.examples.simple.Simple))
For a total of 1 facts.
Jess (defrule change_name ?f - (simple (name Dave)) = (modify ?f (name Tom)))
TRUE
Jess (rules)
MAIN::change_name
For a total of 1 rules.
Jess (ppdefrule change_name)
(defrule MAIN::change_name
   ?f - (MAIN::simple (name \Dave\))
   =
   (modify ?f (name \Tom\)))
Jess (watch all)
TRUE
Jess (run)
FIRE 1 MAIN::change_name f-0
1
Jess (facts)
f-0   (MAIN::simple (class External-Address:java.lang.Class) (fraction 0.0) (name 
Dave) (serial 0) (truth FALSE) (OBJECT 
External-Address:jess.examples.simple.Simple))
For a total of 1 facts.
C:\amber\Jess\Jess60java -cp .  jess.Main

Jess, the Java Expert System Shell
Copyright (C) 1998 E.J. Friedman Hill and the Sandia Corporation
Jess Version 6.0 12/7/2001

Jess (defclass simple jess.examples.simple.Simple)
jess.examples.simple.Simple
Jess (ppdeftemplate simple)
(deftemplate MAIN::simple extends MAIN::__fact \$JAVA-OBJECT$ 
jess.examples.simple.Simple\
 (slot class (default External-Address:jess.SerializablePD))
 (slot fraction (default External-Address:jess.SerializablePD))
 (slot name (default External-Address:jess.SerializablePD))
 (slot serial (default External-Address:jess.SerializablePD))
 (slot truth (default External-Address:jess.SerializablePD))
 (slot OBJECT (type 2048)))
Jess  (bind ?sb (new jess.examples.simple.Simple Dave))
External-Address:jess.examples.simple.Simple
Jess (definstance simple ?sb static)
Fact-0
Jess (facts)
f-0   (MAIN::simple (class 

Re: JESS: Modifying facts that are created from a definstancenot working

2002-02-01 Thread ejfried

I think Villanueva, Ruben wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
   When I try to modify a fact created from a definstance of a Java
 bean that has property change support the fact does not get modified
 right away if the defistance function was called with the static
 parameter.

Yes, by definition. That's how it's supposed to work.


 My understaing is that the modify functionMop is suppose to modify a
  fact directly whether the fact was created with property support or
 not.


Well, no. When you use (modify) on a shadow fact, the properties of
the Bean are changed, and Jess relies on propertyChangeEvents() to
then be sent to modify the fact. If you've used static, then there are
no such events, so the shadow fact isn't updated until you call
(reset).


-
Ernest Friedman-Hill  
Distributed Systems ResearchPhone: (925) 294-2154
Sandia National LabsFAX:   (925) 294-2234
Org. 8920, MS 9012  [EMAIL PROTECTED]
PO Box 969  http://herzberg.ca.sandia.gov
Livermore, CA 94550


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: Modifying facts that are created from a definstancenot working

2002-02-01 Thread Richard Long

We've created a defadvice for the modify function to automatically update
the shadow facts without resetting the engine.

Here it is, for anyone else who may need this behavior:

(defadvice after modify
(if (?retval isShadow)
  then
   (bind ?_object (fact-slot-value ?retval OBJECT))
   (bind ?_bi (call java.beans.Introspector getBeanInfo (?_object
getClass)))
   ;Now, grab the PropertyDescriptors.  We just need to test the first
one for isBound.
   (bind ?_pd (call ?_bi getPropertyDescriptors))
   (if ( (length$ ?_pd) 2) ;No properties still give 1 descriptor.
 then
  (return ?retval)
   )
   ;If so, we definstance dynamic, if not, then static.
   (if (call (nth$ 2 ?_pd) isBound)
 then
;(printout t Bound fact modified)
   (undefinstance ?_object)
   (return (definstance (call (?retval getDeftemplate) getBaseName)
?_object dynamic))
 else
   (undefinstance ?_object)
   (return (definstance (call (?retval getDeftemplate) getBaseName)
?_object static))
   )
)
)
- Original Message -
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, February 01, 2002 1:51 PM
Subject: Re: JESS: Modifying facts that are created from a definstance not
working


 I think Villanueva, Ruben wrote:
 [Charset iso-8859-1 unsupported, filtering to ASCII...]
When I try to modify a fact created from a definstance of a Java
  bean that has property change support the fact does not get modified
  right away if the defistance function was called with the static
  parameter.

 Yes, by definition. That's how it's supposed to work.

 
  My understaing is that the modify functionMop is suppose to modify a
   fact directly whether the fact was created with property support or
  not.
 

 Well, no. When you use (modify) on a shadow fact, the properties of
 the Bean are changed, and Jess relies on propertyChangeEvents() to
 then be sent to modify the fact. If you've used static, then there are
 no such events, so the shadow fact isn't updated until you call
 (reset).


 -
 Ernest Friedman-Hill
 Distributed Systems ResearchPhone: (925) 294-2154
 Sandia National LabsFAX:   (925) 294-2234
 Org. 8920, MS 9012  [EMAIL PROTECTED]
 PO Box 969  http://herzberg.ca.sandia.gov
 Livermore, CA 94550

 
 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: Modifying facts

2001-09-28 Thread ejfried


You're the victim of an optimization.

A brief explanation: when a (modify) function is compiled, Jess can't
tell what kind of fact is going to be bound to the first
argument. Therefore, when the (modify) is later first executed, Jess
has to actually look up the slot name in a table to find the proper
offset at which to store the new slot data. This lookup is slow (not
terribly slow, but nontrivial). The (modify) function call therefore
saves this offset, so that the next time it is called, it can use the
offset directly, which is noticeably faster.

This obviously breaks horribly if, as you've established below, a
single (modify) can be called on different types of facts which just
coincidentally share a slot name. It never would have occurred to me
to do this, and noone's ever complained before, so I think it's a very
original notion on your part.

I'll have to think about it before I decide whether this is a bug that
needs to be addressed, something that needs to be mentioned in the
manual, or what. But you can fix your immediate problem simply by
rearranging your deftemplates such that the button slot is at the
same offset in each one -- i.e., make it the third slot in the exit
template as well as in the room template.


I think [EMAIL PROTECTED] wrote:
 Hello,
 
 I have two templates:
 (deftemplate room
   (slot name)
   (multislot exits)
   (slot button))
 
 (deftemplate exit
   (slot name)
   (multislot rooms)
   (slot x (default 0))
   (slot y (default 0))
   (slot heading);into corridor (from first to last)
   (slot open (default YES))
   (slot found (default NO))
   (slot button)
   (slot id(default 0)))
 
 I read in a fact file of rooms and exits, and I then generate a map of 
 buttons for each.  I try to store the button external reference in the 
 button slot, and I think I am successful, but there is an unexpected side 
 effect.  Just before the suspected modify statement, if I printout the x and 
 y values, the are all zero as they should be.  However, when I check (at 
 ;here) the x values have become external references to buttons.  Why?
 Here's the rule:
 (defrule create-mapPanel (declare (salience 20))
   (mode initialize)
   (map (nodes $?nodes)(width ?w)(height ?h))
   ?fact - (create-map)
   =
   (bind ?*mapPanel* (new Panel))
   (set ?*mapPanel* layout (new GridLayout ?h ?w))
   (foreach ?node $?nodes
 (if (or (eq R (sub-string 1 1 ?node)) (eq H (sub-string 1 1 ?node)) 
 (eq N (sub-string 1 1 ?node)))
   then (bind ?e (run-query get-room-fact ?node))
   else (bind ?e (run-query get-exit-fact ?node)))
 (while (?e hasNext)
   (bind ?token (call ?e next))
   (bind ?factid (call ?token fact 1)))
 (modify ?factid (button (bind ?*b* (new Button ?node
 ;modify that causes unexpected change
 (if (eq D (sub-string 1 1 ?node)) ;here
   then (printout t ?node -)   ;here
(printout t  x= (call ?factid getSlotValue x))   
 ;here
(printout t  y= (call ?factid getSlotValue y) crlf)) 
 ;here
 (if (eq NULL ?node)
   then (?*b* hide)   
   else (?*b* addActionListener (new ActionListener 
 room-prompt-button-handler (engine))) 
(?*b* setBackground (get-member java.awt.Color white)))
 (?*mapPanel* add ?*b*))
   (retract ?fact)
   (assert (need-gui))) 
 
 
 
 -
 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]
 -
 



-
Ernest Friedman-Hill  
Distributed Systems ResearchPhone: (925) 294-2154
Sandia National LabsFAX:   (925) 294-2234
Org. 8920, MS 9012  [EMAIL PROTECTED]
PO Box 969  http://herzberg.ca.sandia.gov
Livermore, CA 94550

-
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: [Modifying facts in deffunction]

2000-02-24 Thread Bruno SINTES

I found a  'solution'   to my problem (well, it's working so far, so I consider it
is a solution !)


(defrule foo
...
?ac - (action yes)
=

(retract ?ac)
)

...

(deffunction menu-handler (?event)
  (assert (action yes))
  (run)
)

Because when the user doesn't do anything (and no rule has to be fired), the
engine stops.
So when there is an action commited, I assert the fact and run the engine. I don't
know if it is clever, but it works.

Bruno SINTES



[EMAIL PROTECTED] wrote:

 Hi,

 There's no neat way to do what you're asking about (at least not in
 the current versions of Jess.) What you could do, though, is use Beans
 instead of facts. Keep a reference to the Bean available someplace,
 and have the item-listener change the properties of the Bean. If the
 Bean is definstanced, then it will be available for matching by rules
 just as the current facts are -- the rules would likely not need to be
 changed.

 I think sintes wrote:
 [Charset ISO-8859-1 unsupported, filtering to ASCII...]
  Hi all !
 
  I'd like to know how to get a fact-id in a
  function. I create a GUI with awt objects,
  I add listeners to those objects and when
  something happens, I'd like to modify the
  fact involved in the control.
 
  Here is my sample
 
  (deffact act (action no))
  ...
 
 
  (defrule foo
  ...
  ?ac - (action yes)
  =
  ...)
 
  ...
 
  (deffunction itemlistener (?event)
 
  ;;I dunno how to modify the fact action, as
  I dunno how to get the fact-id
 
   ?bar-(action no) ;;?
  (modify ?bar (action yes)) ;;?
  )
 
  Thank you,
 
  Bruno SINTES

 -
 Ernest Friedman-Hill
 Distributed Systems ResearchPhone: (925) 294-2154
 Sandia National LabsFAX:   (925) 294-2234
 Org. 8920, MS 9012  [EMAIL PROTECTED]
 PO Box 969  http://herzberg.ca.sandia.gov
 Livermore, CA 94550
 -
 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]
-



JESS: Modifying facts in deffunction

2000-02-24 Thread sintes

Hi all ! 

I'd like to know how to get a fact-id in a 
function. I create a GUI with awt objects, 
I add listeners to those objects and when 
something happens, I'd like to modify the 
fact involved in the control.

Here is my sample

(deffact act (action no))
...


(defrule foo
...
?ac - (action yes)
=
...)
 
...

(deffunction itemlistener (?event)

;;I dunno how to modify the fact action, as 
I dunno how to get the fact-id 

 ?bar-(action no) ;;?
(modify ?bar (action yes)) ;;? 
)

Thank you,

Bruno SINTES