Re: JESS: Checking list equality
Given the precondition (as Henrique wrote) that the lists are sets you don't have to consider the general case. -W Szymon Klarman wrote: Yes but this function won't do the job in general. Consider: list1 = (1 1 2), list2 = (2 2 3), (union$ list1 list2) = (1 2 3) Better to check whether intersection of the two lists have the same length as their union. all best, Szymon - Original Message - From: Wolfgang Laun [EMAIL PROTECTED] To: jess-users@sandia.gov Sent: Wednesday, February 13, 2008 3:16 PM Subject: Re: JESS: Checking list equality You can apply (=) to more than 2 arguments. (= (length$ ?list1) (length$ ?list2) (length$ (union$ ?list1 ?list2))) kr Wolfgang Henrique Lopes Cardoso wrote: Hi, I was trying to test equality for lists seen as sets (elements with any order). Is there any direct function, or any solution simpler than this: (bind ?list1 (list 1 2 3)) (bind ?list2 (list 3 2 1)) (and (= (length$ ?list1) (length$ ?list2)) (= (length$ (union$ ?list1 ?list2)) (length$ ?list1))) Thanks. Henrique 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] 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: Jess Casting/ Inheritance
Gary Napier wrote: I have an alarm deftemplate derived from my Alarm class. I would like jess to analyse these incoming alarms and highlight the important ones. So the output from jess is Super_Alarm. Both classes share many slots / fields. Now the question. If i have *deftemplate* Super_Alarm *from class* Super_Alarm *extends* Alarm : A) Can i cast an alarm to a super alarm and fill in the new fields No. B) What is JESS's mechanism for doing this (in comparison to performance of the solution below) One option would be to have a single class/template: put all the fields required by Super_Alarm into Alarm. If this is undesirable (too many fields in the Super-only-part) then you could use a separate Super object as an add-on for those Alarm objects representing the super-alarms. This would only need one reference field (Super super) in Alarm. These Super objects could be shadowed by jess facts as well, and it would not be too inconvenient to refer to the Super extension in rule LHSs. kr Wolfgang currently i pass the alarm Object slot into the constructor of Super_Alarm which is full of : this.setX(alarm.getX() ); Thanks Gary 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: Floating issue
This is not a Jess problem. Using reals for non-atomic monetary units (e.g., dollar, euro, pound) is a no-no. Absolutely. Don't do it. You might turn to integers representing the subunit (e.g., cent or penny or whatever). Or use java.math.BigDecimal. Kind regards Wolfgang Nara Hari wrote: Hi, We are calculating some pricing information based on Jess rules and some times the results are little fuzzy! e.g. (- 1.1 0.9) == 0.20007 (- 1.1 0.7) == 0.40013 Any idea what the reason is or how can I fix it other than to round-off in the application. I have tested the issue with Jess versions 70p2 as well as 71b1 Thanks. 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: Design check - Tempral Issues
The Jess Wiki contains a Jess User Function that might be useful: http://herzberg.ca.sandia.gov/jesswiki/view?AfterEveryUserFunction Assuming that, at some point in time, you know that Y should fire within the next minute, you can set up a fact that says expecting Y. (In Y's RHS, you retract this fact.) The userfunction might be called |(after 60 (one_minute_isover))| where you do whatever is necessary to detect that expecting Y is still around. Most Java systems aren't real time, so don't use this with rockets ;-) Kind regards Wolfgang Gary Napier wrote: Hi Folks, I'm looking to use JESS in an alarm processor subsystem. I look to your experience to let me know if JESS is the right tools or if there is a better solution. My main question is about handling temporal issues within JESS. Such as rule timeouts. What i think I'm looking for is a implementation of a watchdog timer or similar. Or maybe I've missed something (like backward chaining : not sure I understand that really ) that already accomplishes the following: For example. Rule X fires is rules A, B and C fire. Rule X outputs the message A and B and C fired howeverRule Y fires if rules A and C fire but rule B does not. Rule Y outputs the message A and C fired. But B failed to fire Now in my application the data can be received out of order and sometimes due to faults are never received. I would like rule Y to fire to signal that data has not been received BUT only after an appropriate time out, in case the data is delayed At the moment : (A) fact asserted (i.e. data enters to satisfy rule A) Rule A fires (C) fact asserted Rule C fires Rule Y fires A and C fired. But B failed to fire (B) fact asserted Rule B fires Rule X fires A and B and C fired Net result : the operator sees a problem message where none exists. Since this is output from the JESS engine, the output cannot be recalled or de asserted like facts in working memory. ideal solution : Rule Y modified to fire only if (B) is not received 30 seconds after all other conditions are met (A) fact asserted Rule A fires (C) fact asserted Rule C fires Rule Y fires - but now waits till its timeout expires 16 seconds pass (B) fact asserted Rule B fires Rule Y expires as conditions are not met Rule X fires A and B and C fired reset (A) fact asserted Rule A fires (C) fact asserted Rule C fires Rule Y fires - but now waits till its timeout expires 31 seconds pass Rule Y fires as conditions are now met A and C fired. But B failed to fire PS. I would be willing to write this up for the wiki later if a good JESS solution is hammered out. Thanks Gary 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: Java Vector iterator/Application Design issue
There is no '=' separating the RHS and the LHS in your rule rule_test. Processing slots containing a java.util.Vector (or a multislot) requires you to write rather complicated rules. It seems that a simple fact that associates, say, a category name with a *single* charge code, and is used repeatedly leads to simpler rules than a single object with some container slot. Let's assume that you have (CustCharge (custId Smith)(chargeId c1A)) (CustCharge (custId Smith)(chargeId c3B)) (CustCharge (custId Smith)(chargeId c5C)) which could be easily asserted from your customer object. But I would split the Category objects into a sequence of facts, e.g. (CatCust (catId A)(chargeId c1A)) (CatCust (catId A)(chargeId c2A)) (CatCust (catId B)(chargeId c3B)) (CatCust (catId B)(chargeId c3B)) (CatCust (catId C)(chargeId c5C)) Then you could write the rule (defrule findCat (CustCharge (chargeId ?chargeId)) (CatCust ((catId ?catId)(chargeId ?chargeId)) = (assert (Have (catId ?catId))) ) This would give you a set of Have-facts with the categories Smith has. Then simple rule defining the required combinations could be written as (define ABC (Have (catId A)) (Have (catId B)) (Have (catId C)) = ...) It fires if the charge combination is valid; not firing can be detected by throwing in a fact such as (Failure) which is retracted in ABC. Kind regards Wolfgang JimYates wrote: Purpose: To find customer charges that do not have required matching categories. Matching requirements can change. Example: A charge in category A requires a charge in Category B. Or a charge in category A requires a charge in Category B and Category C. Data structure:Customer object with customer id, a Vector of customer charge objects, Category Object with the category name and a Vector of charge codes, Customer charge object with charge code, charge description, etc . I want to use Jess because the matching rules can be changed and/or added by the application. There will only be 1 customer at a time in working memory, but all the categories will reside in working memory. The matching rules may require multiple categories. If I were to code this in Java I would do something like: while (customer charges) if category_A contains customer_charge then cat_a_flag = TRUE if category_B contains customer_charge then cat_b_flag = TRUE end while if (cat_a_flag and not cat_b_flag) then print charge missing have A without B end while (customer charges) if category_A contains customer_charge then cat_a_flag = TRUE if category_B contains customer_charge then cat_b_flag = TRUE if category_C contains customer_charge then cat_c_flag = TRUE end while if (cat_a_flag and not cat_b_flag and not cat_c_flag) then print charge missing have A without B and without C end I'm having trouble designing/coding this in Jess. Specifically getting the iterator for the vector of customer charges. I'm basically trying to duplicate the pseudo code above. (deftemplate Customer Java Object (declare (from-class com.accuserverx.accucharge.batchprocess.Customer))) (deftemplate ChargeCategory Java Object (declare (from-class com.accuserverx.accucharge.batchprocess.ChargeCategory))) (deftemplate Charges Java Object (declare (from-class com.accuserverx.accucharge.batchprocess.Charges))) (deftemplate flags (slot surgflag (default FALSE)) (slot anestflag (default FALSE))) (defrule rule_test ; get customer charge vector of Charges where the vector is not null (Customer (customerCharges ?chgVect:(neq ?chgVect nil))) ; get the iterator for the charge vector to use in the while (bind ?chgitr (?chgVect iterator)) I get a Bad slot value error on the second parenthesis in the bind. 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: cost/objective function ?
Mohd. Noor wrote: Dear all What is it means by cost or objective function? http://en.wikipedia.org/wiki/Objective_function one more things. How I am going to map (using rules) between two different attributes from users and resources let say user need to run the job and get results in 1 hour but the resource available is represented in another attribute, say, the number of CPU available is 100CPUs This isn't clear to me. Provide more information (deftemplate). krW How I am going to translate and map this two different definition/schema Regards mnoor 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: insert data into database in JESS
And there is the body of the while loop: (while (?result next) (?statement execute insert into test (persen) values (?result getString y))) which looks strange to me, as the string literal contains (presumably) some SQL statement, where the embedded Jess (?result getString y) may be, uh, optimistic. An SQL insert statement would look like insert into test (persen) values ('blue green') and I guess you'd have to compose this, in Jess, as a string (bind ?sql (str-cat insert into test (persen) values (' (?result getString y) ') ) so that you could do the glorious (?statement execute ?sql) inside the while loop. Regards Wolfgang Ernest Friedman-Hill wrote: A QueryResult is like an Iterator. It has a sort of cursor inside, and calling next() advances that cursor. When the cursor gets to the end, then the Iterator can't be used anymore and must be discarded. In your example below, you use the QueryResult to loop over the results and print them out, but then you have a second loop which tries to use the QueryResult again. Because the cursor is now at the end, next immediately returns false and that loop doesn't execute. Remove that first loop and this should work (unless you've made other mistakes that I'm not seeing.) On Dec 17, 2007, at 9:17 AM, Barlianti Vavorita wrote: hello, can i insert data to database through JESS? i want to insert data on working memory to the database. first i used defquery to choose data which i want to insert into database. i have tried to select data in database with JESS and i can do it successfully. but why when i tried to insert data i failed? im using microsoft access 2003. this is the code when i select data : Jess (import java.sql.*) TRUE Jess (call Class forName sun.jdbc.odbc.JdbcOdbcDriver) Java-Object:java.lang.Class Jess (bind ?conn (call DriverManager getConnection jdbc:odbc:databaseTest)) Java-Object:sun.jdbc.odbc.JdbcOdbcConnection Jess (bind ?statement (?conn createStatement)) Java-Object:sun.jdbc.odbc.JdbcOdbcStatement Jess (bind ?rs (?statement executeQuery select * from pakar)) Java-Object:sun.jdbc.odbc.JdbcOdbcResultSet Jess (while (?rs next) do (printout t (?rs getString nama) (?rs getString jabatan) crlf)) java pakar jess pakar test conn pakar hello world pakar john doe pakar tom riddle pakar vivi pakar admin admin FALSE Jess (?statement close) Jess (?conn close)br Jess br Jess and this is when i insert data, if i wrong in syntax, can you help me to fix it. Jess (defquery search (declare (variables ?x)) (color ?x ?y)) TRUE Jess (deffacts data (color blue red) (color blue green) (color blue pink) (color red blue) (color blue blue) (color orange yellow) (warna blue purple)) TRUE Jess (reset) TRUE Jess (facts) f-0 (MAIN::initial-fact) f-1 (MAIN::color blue red) f-2 (MAIN::color blue green) f-3 (MAIN::color blue pink) f-4 (MAIN::color red blue) f-5 (MAIN::color blue blue) f-6 (MAIN::color orange yellow) f-7 (MAIN::warna blue purple) For a total of 8 facts in module MAIN. Jess (bind ?result (run-query* search blue)) Java-Object:jess.QueryResult Jess (while (?result next) (printout t (?result getString x) (?result getString y) crlf)) blue red blue green blue pink blue blue FALSE Jess (import java.sql.*) TRUE Jess (call Class forName sun.jdbc.odbc.JdbcOdbcDriver) Java-Object:java.lang.Class Jess (bind ?conn (call DriverManager getConnection jdbc:odbc:databaseTest)) Java-Object:sun.jdbc.odbc.JdbcOdbcConnection Jess (bind ?statement (?conn createStatement)) Java-Object:sun.jdbc.odbc.JdbcOdbcStatement Jess (bind ?result (run-query* search blue)) Java-Object:jess.QueryResult Jess (while (?result next) (printout t (?result getString x) (?result getString y) crlf)) blue red blue green blue pink blue blue FALSE Jess (facts) f-0 (MAIN::initial-fact) f-1 (MAIN::color blue red) f-2 (MAIN::color blue green) f-3 (MAIN::color blue pink) f-4 (MAIN::color red blue) f-5 (MAIN::color blue blue) f-6 (MAIN::color orange yellow) f-7 (MAIN::warna blue purple) For a total of 8 facts in module MAIN. Jess (while (?result next) (?statement execute insert into test (persen) values (?result getString y))) FALSE Jess and the content in database is still blank. in different way i got this error : Jess (while (?result next) (?statement execute insert into test (persen) values (?result getString z))) Jess reported an error in routine Context.getReturn while executing (call ?statement execute insert into test (persen) valu es (?result getString z)) while executing (while (call ?result next) (call ?statement execute ins ert into test (persen) values (?result getString z))). Message: No such variable statement. Program text: ( while ( ?result next ) ( ?statement execute insert into test (persen) values (?result getString z) ) ) at line 282. please help me to fix it, thank you. regards, vivi
Re: JESS: Updating shadow facts from object copies
Sorry, but I simply fail to understand why the newly arriving object A2 can't be used in a simple method where you copy all its field values into A1, followed by a call to rete.updateObject(). It'd be interesting to learn which strategy is preferable: either a single call to updateObject( Object ) after indiscriminately copying all fields or individual copy operations, for differing fields only, each followed by a call to the two argument form of updateObject(). If you know what changes to expect, then this might also help to decide either way. Regards Wolfgang Will Edwards wrote: That sounds exactly right, we did indeed try and modify the OBJECT slot, and yes it failed in a pretty emphatic way. I'm pretty sure we got it right because other slot modifications using the same mechanism worked correctly. We're currently getting our license and will work on this integration the moment we do. Thanks a lot, Will Edwards -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ernest Friedman-Hill Sent: Tuesday, December 11, 2007 9:46 AM To: jess-users@sandia.gov Subject: Re: JESS: Updating shadow facts from object copies Hi Will, There are three parts of this problem: 1) Given the copied object, identifying the existing object that corresponds to it. This could be tricky unless the objects have some kind of id. You didn't mention this being a problem, so I'm going to assume it's solved. 2) Updating the shadow fact so that it refers to the new object. Technically this shouldn't be hard -- the OBJECT slot could theoretically just be modified like any other slot. Unfortunately there's going to be a problem: if you tried this on a static definstance (which I'll assume yours are), Jess would try to set the OBJECT property of the object itself, and presumably this would fail spectacularly. 3)Besides the OBJECT slot, Jess also keeps a map which associates each definstanced object with its shadow fact; that's so Jess can quickly handle propertyChange events, undefinstance() calls, etc. where you pass in the object and Jess needs to find the fact. There's no public API for changing this map directly. Now, the nice thing is that Jess is licensed in source code form, and you can make your own modifications. Appropriate mods for this would really be pretty simple. To handle (3), you could add a method something like this to jess/ DefinstanceList.java void useNewObject(Rete engine, Object newObject, Object oldObject) { synchronized (engine.getWorkingMemoryLock()) { Fact fact = (Fact) m_definstances.get(oldObject); if (fact != null) { m_definstances.remove(oldObject); m_definstances.put(newObject, fact); } // else maybe throw a JessException } } Also add a package-protected method to Rete which forwarded calls to m_factList. To handle (2), you'd want to add special cases to jess/FactList.java for a property named OBJECT. In modifyDefinstancedFact(), you'd want to call your method on Rete to change the lookup object instead of setting the object's property the way it does now. You'd also want to call modifyRegularFact directly from modifyDefinstanceFact() to change the OBJECT slot itself. On Dec 11, 2007, at 8:38 AM, Will Edwards wrote: Wolfgang is correct, we have a single Rete instance. He is also correct in that we can always obtain a reference to the original object via the shadow fact, or some other way. The problem is that when an update happens to an object a new copy of the updated object is passed. So, we have two physical objects that represent the same logical piece of data, say A1 that is already in Rete as a shadow fact, and A2 the updated version of A1 that has just been passed to us. My question was: what is the best, or simplest, way to update Rete with the new object. Thanks. -Original Message- From: [EMAIL PROTECTED] [mailto:owner-jess- [EMAIL PROTECTED] On Behalf Of Wolfgang Laun Sent: Tuesday, December 11, 2007 4:48 AM To: jess-users@sandia.gov Subject: Re: JESS: Updating shadow facts from object copies I have understood Will's problem to be within a single Rete object. Basically, the Rete.add() method returns a reference to the created jess.Fact. As a shadow fact in good standing it'll have a slot OBJECT containing a reference to the original Java object. Therefore, the original object is always easily available. (The Jess Manual, 5.3.2) Hal Hildebrand wrote: Wouldn't the fact id be (potentially) different in different instances of the rules engine? I believe these are assigned in declaration order, so unless every instance is defining instances in precisely the same order, then you'd end up with the same logical fact having different ids in different VMs. FWIW, there's a good paper by someone who did something remarkably similar: www.waset.org/pwaset/v4/v4-18.pdf Myself, I've
Re: JESS: Updating shadow facts from object copies
I have understood Will's problem to be within a single Rete object. Basically, the Rete.add() method returns a reference to the created jess.Fact. As a shadow fact in good standing it'll have a slot OBJECT containing a reference to the original Java object. Therefore, the original object is always easily available. (The Jess Manual, 5.3.2) Hal Hildebrand wrote: Wouldn't the fact id be (potentially) different in different instances of the rules engine? I believe these are assigned in declaration order, so unless every instance is defining instances in precisely the same order, then you'd end up with the same logical fact having different ids in different VMs. FWIW, there's a good paper by someone who did something remarkably similar: www.waset.org/pwaset/v4/v4-18.pdf Myself, I've taken another route, which is using shadow facts for everything I want distributed. The facts all have generated UUIDs, so there's no issues with locally generated ids in a distributed system. Then it's a fairly simple matter to translate to the local facts when the shadow changes and vice versa. On Dec 10, 2007, at 1:07 PM, Will Edwards wrote: We're attempting to integrate a JavaSpaces implementation with Jess. When an object changes in the JavaSpace we receive a notification that the object has changed and a copy of the changed object which we want to add or modify as a Jess shadow fact in the rules engine. Our problem is that in this environment we do not get a reference to the original object but a new (by value) copy of the object. So, we want to modify the existing Jess fact with the new copy. Assuming we have the FactIDValue (from the original rete.add) is there a reasonably simple way to do this? Currently we are using a FactFilter to get the existing object, call rete.remove() to remove the old copy and then rete.add() with the new copy. This is of course prone to potential race conditions, etc. What we would like to do is use modify() or updateObject() but both of these seem to require that the original object reference be maintained. Thanks in advance. 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] 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: Ranking facts
Maybe this is coming close to what you want. ; your fact template (deftemplate Fact (slot id)(slot a)(slot b)(slot c)) ; supposed to contain the rating functions for the slot values (deftemplate Func (slot fa)(slot fb)(slot fc)) ; the computed ranking for a fact (deftemplate Rank (slot r)(slot f)) ; the collected results (deftemplate Count (slot n)(multislot facts)) ; some facts (deffacts someT (Fact (id A)(a 42)(b 23)(c 17)) (Fact (id B)(a 21)(b 11)(c 7)) (Fact (id C)(a 15)(b 10)(c 12)) (Fact (id D)(a 33)(b 12)(c 9)) ) ; rating functions for the slots (deffacts aFunc (Func (fa (lambda (?a) (return (- ?a 10 (fb (lambda (?b) (return (/ ?b 3 (fc (lambda (?c) (return (* ?c 2) ) ; a rule computing the fact ranking as the sum of the slot rankings (defrule setRank ?fact - (Fact (a ?a) (b ?b) (c ?c)) (Func (fa ?fa)(fb ?fb)(fc ?fc)) = (bind ?rank (+ (call ?fa ?a)(call ?fb ?b)(call ?fc ?c))) (assert (Rank (r ?rank)(f ?fact))) ) (reset) (run) ; getting displaying the n best rankings (defrule getBest ?count - (Count (n ?n : ( ?n 0))(facts $?facts)) ?rank - (Rank (r ?r)(f ?fact)) (not ( Rank (r ?r1 : ( ?r1 ?r = (-- ?n) (modify ?count (n ?n)(facts (list $?facts ?fact))) (retract ?rank) ) (defrule showBest ?count - (Count (n 0)(facts $?facts)) = (retract ?count) (foreach ?f $?facts (printout t (fact-slot-value ?f id) crlf) ) ) ; top 3 (assert (Count (n 3))) (run) Notice that some Rank facts remain, but these can be easily retracted. Kind regards Wolfgang Jan Willem Lokin wrote: Hi, Consider the following situation. I have asserted quite a number of facts, with various values for their slots. Now I want to select a limited number of facts that are most suitable, according to some user-defined criterion. My idea was to set up a defquery and then use Java sorting to order the QuertResult according to my criterion. However, there seems to be no way to transform a QueyResult into a Collection. Note that my problems would be simple if I had fixed limits on my slot values, but I haven't: if i woudl have slot values of 2, 4 and 6 and I would like to have the smallest two, a limit of 5 would do it, but this would not work when the values were 13, 15 and 29. My suspicion is that I am trying to solve the problem in the wrong manner, or even trying to solve the wrong problem. Any suggestions are appreciated. Regards, JW Lokin 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: Forward and Backward chaining
I doubt very much that an approach combining forward and backward chaining would simplify matters. Given that we're still discussing the user/systems/resources application: I'd extend the set of rules (including dynamically created ones) so that the system would come up with the info which resource (combination) is missing whenever the rule(s) determining the applicable system won't fire. Regards Wolfgang On 11/19/07, Mohd. Noor [EMAIL PROTECTED] wrote: Hi All Forward chaining is based on the supplied facts whereas backward chaining based on the goals. How about in the first run during the forward chaining- the rules cannot be fired; could be due to the limited information (of resources), do I have to infer the rules using the backward chaining after that based on the goals approaches ( with refers to complex rules and template that not statically defined) cheers mnoor
Re: JESS: matching problem
Or this one which is subtly different: (deftemplate things (slot Id) (multislot elements)) (deftemplate otherthing (slot one_Element)) (defrule FindIt ?ot - (otherthing (one_Element ?el )) ?th - (things (Id ?Id) (elements $? ?el $?)) = (printout t found ?el in ?Id crlf) ) (deffacts init (things (Id abc) (elements a b c)) (things (Id abb) (elements a b b)) (things (Id xyz) (elements x y z)) (things (Id baa) (elements b a a)) (otherthing (one_Element a))) (reset) (run) The difference becomes apparent with the things fact with (Id baa), where a occurs twice in elements, and therefore the rule fires twice. Wolfgang On Nov 14, 2007 6:15 PM, Jason Morris [EMAIL PROTECTED] wrote: Hi Hans, Try this solution: (clear) (watch all) (deftemplate things (slot Id) (multislot elements)) (deftemplate otherthing (slot one_Element)) (deffacts init (things (Id 1) (elements a b c)) (otherthing (one_Element a))) ;Get all Ids of things ;Where AElement of elements equals one_Element (defrule find_it (things (Id ?pId)(elements $?elements)) (otherthing (one_Element ?foo:(member$ ?foo ?elements))) = (printout t crlf Found it: ?pId crlf crlf)) ; Program (reset) (run) /** OUTPUT MAIN::find_it: +1+1+1+1+2+t == Focus MAIN == f-0 (MAIN::initial-fact) == f-1 (MAIN::things (Id 1) (elements a b c)) == f-2 (MAIN::otherthing (one_Element a)) == Activation: MAIN::find_it : f-1, f-2 FIRE 1 MAIN::find_it f-1, f-2 Found it: 1 == Focus MAIN **/ Cheers, Jason --- Jason Morris Morris Technical Solutions LLC http://www.morris-technical-solutions.com On Nov 14, 2007 10:43 AM, sotski [EMAIL PROTECTED] wrote: Hey all! I have a newbie question. I read the Answers to the matching in two multislots of two different templates post. I have very similiar problem but not the same ;-) I simplify the problem for you: ;;Templates: (deftemplate things (slot Id) (multislot elements)) (deftemplate otherthing (slot one_Element)) now I want to write a rule which does the following: get all Ids of things where AElement of elements equals one_Element I wrote a rule: (defrule find_it (things (Id ?pId)(elements $?elementName)) (otherthing (one_Element ?foo)) (test (eq ($?elementName ?foo)) = (printout t found it: ?pId crlf)) But it doesen't fire. I assert facts from java and they are of type RU.SYMBOL Thx for your help Bye Hans -- View this message in context: http://www.nabble.com/matching-problem-tf4805951.html#a13749159 Sent from the Jess mailing list archive at Nabble.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: The JessEvent trap
Playing around with Jess Event handling, I've just run into this one: I defined a handler in Jess, using JessEventAdapter, to run a simple deffunction whenever a new fact appears. Tested, works fine. Next, I wrote a more general event handler, in Java, to fire whenever something interesting occurs. OK, works fine, too, but only if you don't run them both at the same time, and while becoming too interested in calls of userfunctions. I think you can guess what happens. The root of the problem appears to be the separation of event listeners from the event mask. If the definition of the former were to be coupled with some setting of the latter, so that the Rete could notify a handler according to this handler's very own mask, all would be well (as long as you don't set up a Jess handler for userfunction events!) A proxy taking care of that could be written easily enough, but I think it should be implemented in jess.Rete. Regards Wolfgang
Re: JESS: Pattern matching nested objects
Darrel Davis wrote: I am a real newbie having some difficulty understanding how I would test/access nested Java objects from the LHS of a rule. Given the following declarations: (deftemplate AgreementVO (declare (from-class AgreementVO))) (deftemplate HostVO (declare (from-class HostVO))) A HostVO is contained within an AgreementVO and has firstName and lastName attributes. I can do this: (defrule hostvo (AgreementVO (host ?host:(neq ?host nil))) = (bind ?ln (?host getLastName)) (bind ?fn (?host getFirstName)) ) but this can be problematic if lastName or firstName is null, Why? It'll bind nil to ?ln or ?fn, and you know how to compare a variable with nil. plus I have some objects which are nested 3 deep. I then found example code in the mailling list archives which would define the rule as: (defrule hostvo (AgreementVO (host ?host:(neq ?host nil))) ?host - (HostVO (lastName ?last)(firstName ?first)) = Which doesn't fire at all. First, you don't have to add another condition to get at the HostVO contained within the AgreementVO. Accessing the HostVO's attributes on the LHS or the RHS can be written as (?host getFirstName). E.g.: (defrule hostvo (AgreementVO (host ?host : (neq ?host nil))) = (printout t (?host getFirstName) crlf)) Or: (defrule hostx (AgreementVO (host ?host : (call Smith equals (?host getLastName))) ) = (printout t (?host getFirstName) (?host getFirstName) crlf) ) Note that calling equals on Smith avoids the test for nil/null. But, just to clarify the doesn't fire, let's assume that you'll have to find the embedded object by matching. The important thing to remember in this situation is that any fact (and this includes shadow facts) is of class jess.Fact. The corresponding Java object of some Java class is contained within this jess.Fact object. - Assert or add some facts, and then do this: Jess (bind ?f (fact-id 1)) Fact-1 Jess (printout t ((?f getClass) getName) crlf) jess.Fact The first condition in your rule is (AgreementVO (host ?host:(neq ?host nil))) which says find me an AgreementVO with slot host not equal to nil and assign the contents of this slot to ?host. This, then, will contain some Java object of class HostVO. The second condition tries to find a HostVO fact: ?host - (HostVO (lastName ?last)(firstName ?first)) Since ?host is already bound, ?host - (HostVO... means that the HostVO fact(!) must be equal to whatever was stored in ?host. It should be clear by now that a jess.Fact will never be equal in any sense to a HostVO object. How can this be fixed? There are two ways. First, note that there is an OBJECT slot in each shadow Fact, and this does contain the POJO. (defrule hostvo (AgreementVO (host ?host:(neq ?host nil))) ?hostfact - (HostVO (OBJECT ?host)(lastName ?last)(firstName ?first)) = ... Now the second condition says find me a HostVO fact whose POJO is identical to the one we have in ?host. The fact is now bound to ?hostfact. The other way (not recommended) is this: (defrule find1 (AgreementVO(host ?host :(neq ?host nil))) ?hFact - (HostVO (lastName ?last)) (test (?hFact equals ((engine) getShadowFactForObject ?host))) = The jess.Rete method getShadowFactForObject returns a fact created from some Java object. This may be compared to the fact found in Jess' memory. Note that the result of getShadowFactForObject is a *new* fact, and hence needs to be compared with equals. (The identity comparison eq will not work.) (I admit that even though I'm reading Jess In Action as well as the printed manual, I'm having trouble understanding this syntax ). You are not alone, there :-) In some condition: (SomeTemplate (aSlot ?aVar )...) If variable ?aVar hasn't been bound before then assigns (binds) the value of slot aSlot to variable ?aVar otherwise restricts matches to facts with slots equal to the contents of ?aVar. (aSlot ?aVar : (anExpressionReturningBoolean)) as before, and additionally, anExpressionReturningBoolean must return TRUE The Jess Manual, section 6.3, contains more. HTH Wolfgang So my question is: What is the correct method of accessing attributes of nested objects on the LHS of a rule? Maybe pointers to JIA chapters or manual chapters? Thanks, - Darrel Davis [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] [EMAIL PROTECTED] mailto:[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: multislot and its alternatives
Recently, on this list, there was a question about how to find a pair of facts ?a and ?b (of templates A, B) where multislot ?a.props contains element ex and multislot ?a.props contains element ey. The posting did not include sufficient information about the nature of the values stored in the multislots, and therefore the choice of using a multislot wasn't challenged. This, then, was the proposed solution: ; implement a set as a multislot ; (clear) (deftemplate A (slot id)(multislot props)) (deftemplate B (slot id)(multislot props)) (deffacts ab (A (id a1)(props e1 e5)) (A (id a2)(props e2 e5 e7)) (A (id a3)(props e3 e4 e6 e8 e9)) (B (id b1)(props e3 e7)) (B (id b2)(props e4 e6 e7)) ) (defrule MatchAB ?a - (A (props $? e3 $?)) ?b - (B (props $? e4 $?)) = (printout t match a: ?a.id - b: ?b.id crlf) ) (reset) (run) Updates may be tricky, depending on the assumptions associated with a list, which might be anything besides a set: a bag, a list, an array or whatever. Assuming that it is a set, this isn't the only way for implementation. Comparing deftemplates and facts to relational database tables and entities, and considering the guidelines for achieving some Normal Form, multislots or lists aren't necessarily best choice for a deftemplate. You might consider having an individual fact for each property. ; implement a set as a list of facts ; (clear) (deftemplate A (slot id)(slot prop)) (deftemplate B (slot id)(slot prop)) (deffacts ab (A (id a1)(prop e1)) (A (id a1)(prop e5)) (A (id a2)(prop e2)) (A (id a2)(prop e5)) (A (id a2)(prop e7)) (A (id a3)(prop e3)) (A (id a3)(prop e4)) (A (id a3)(prop e6)) (A (id a3)(prop e8)) (A (id a3)(prop e9)) (B (id b1)(prop e3)) (B (id b1)(prop e7)) (B (id b2)(prop e4)) (B (id b2)(prop e6)) (B (id b2)(prop e7)) ) (defrule MatchAB ?a - (A (prop e3)) ?b - (B (prop e4)) = (printout t match a: ?a.id - b: ?b.id crlf) ) (reset) (run) There are more facts, but handling these (including updates) is simpler, in Jess as well as in Java. And the rule is simpler, too! It is also quite simple to avoid a multislot by using a slot that contains a POJO, using some Java Set implementation. ; implement a set as a Java Set ; (clear) (deftemplate A (slot id)(slot props)) (deftemplate B (slot id)(slot props)) (deffunction setOf ($?elems) (bind ?s (new java.util.HashSet)) (foreach ?e $?elems (?s add ?e)) (return ?s) ) (deffacts ab (A (id a1)(props (setOf e1 e5))) (A (id a2)(props (setOf e2 e5 e7))) (A (id a3)(props (setOf e3 e4 e6 e8 e9))) (B (id b1)(props (setOf e3 e7))) (B (id b2)(props (setOf e4 e6 e7))) ) (defrule MatchAB ?a - (A (props ?pa :(?pa contains e3))) ?b - (B (props ?pb :(?pb contains e4))) = (printout t match a: ?a.id - b: ?b.id crlf) ) (reset) (run) More code is required (the setOf deffunction), but we have a simple deftemplate, and updates can rely on the methods of java.util.Set. Similar solutions are possible with other classes from java.util. I feel (and I freely admit that this is just a gut feeling) that the single-slot solutions are, in general, to be preferred to the multislot solution. Does anyone have data to confirm or contradict this? Kind regards Wolfgang 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: Avoiding slot class in shadow facts
Deriving a deftemplate from a Java class with, e.g., (deftemplate Account (declare (from-class Account))) invariably adds a slot class, due to getClass() inherited from java.lang.Object. If you want to get rid of this, see the Jess userfunction I've added to the Jess Wiki: http://herzberg.ca.sandia.gov/jesswiki/view?NoClassSlotUserFunction Cheers, Wolfgang
Re: JESS: Avoiding slot class in shadow facts
Can you rely on Jess ClassResearcher and whatever is used under Eclipse to always produce the same result? Granted (and I do assume) that you can: What is the benefit of using some JDE library function as compared to the ClassResearcher? It can't be a performance issue, because obtaining the template definition from a Java class is highly unlikely to be required frequently. Which classes, exaclty, are your classes which won't be loaded under the JessDE? Thanks Wolfgang On 10/25/07, Ernest Friedman-Hill [EMAIL PROTECTED] wrote: Interesting idea! I hadn't thought about ClassResearcher as a user hook; It was introduced as a way to let Jess use reflection most of the time, but use Eclipse's JDE libraries inside the JessDE so that the JessDE doesn't actually load your classes. Therefore this must be used cautiously because at some point it will break inside Eclipse (although of course an Eclipse-specific version would also be possible.) On Oct 25, 2007, at 12:01 PM, Wolfgang Laun wrote: Deriving a deftemplate from a Java class with, e.g., (deftemplate Account (declare (from-class Account))) invariably adds a slot class, due to getClass() inherited from java.lang.Object. If you want to get rid of this, see the Jess userfunction I've added to the Jess Wiki: http://herzberg.ca.sandia.gov/jesswiki/view? NoClassSlotUserFunction Cheers, Wolfgang - Ernest Friedman-Hill Informatics Decision Sciences 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]
Re: JESS: Is this feature available in Jess?
The first way proposed by Ernest can be implemented in a Userfunction. See http://herzberg.ca.sandia.gov/jesswiki/edit?FactOnFiring With some rule A and a deftemplate FiredA you call the function (fact-on-firing A FiredA) Using FiredA in some other rule should give you the desired behavior. Additional features include: - automatic retracting of generated facts - providing of the rule in a slot of the generated fact - saving the facts causing the rule to fire in a multislot of the generated fact. kr Wolfgang On 10/24/07, Ernest Friedman-Hill [EMAIL PROTECTED] wrote: There are a couple of ways you could do this now. One would be to use JessEvents. Register a JessListener and let it handle DEFULE_FIRED events by invoking a function you specify, under conditions you specify. I've attached a short Jess-language program which demonstrates something like this. Another way would be to extend jess.Rete and override aboutToFire() or justFired(); these hooks are provided to let you do per-rule processing like this. On Oct 23, 2007, at 4:13 PM, Shi Paul wrote: Hi Ernest or others, Here is the situation, say there are 2 rules A and B, I want whenever A fires B fires as well(or less frequently based on some other conditions) and I don't want to just copy A's conditions into B since that way I have to maintain 2 places. What I'd like to see in Jess is some kind of instructional command (for example (follow- rule A) in B's LHS), or better yet if Jess can hook up with some rules before or after A fires (which resembles AspectJ programming). I think it'd be a great feature if Jess allows that. Thanks, Paul - Ernest Friedman-Hill Informatics Decision Sciences Phone: (925) 294-2154 Sandia National LabsFAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] Livermore, CA 94550 http://www.jessrules.com
Re: JESS: Is this feature available in Jess?
The better link to the Userfunction is http://herzberg.ca.sandia.gov/jesswiki/view?FactOnFiring Sorry -W On 10/24/07, Wolfgang Laun [EMAIL PROTECTED] wrote: The first way proposed by Ernest can be implemented in a Userfunction. See http://herzberg.ca.sandia.gov/jesswiki/edit?FactOnFiring With some rule A and a deftemplate FiredA you call the function (fact-on-firing A FiredA) Using FiredA in some other rule should give you the desired behavior. Additional features include: - automatic retracting of generated facts - providing of the rule in a slot of the generated fact - saving the facts causing the rule to fire in a multislot of the generated fact. kr Wolfgang On 10/24/07, Ernest Friedman-Hill [EMAIL PROTECTED] wrote: There are a couple of ways you could do this now. One would be to use JessEvents. Register a JessListener and let it handle DEFULE_FIRED events by invoking a function you specify, under conditions you specify. I've attached a short Jess-language program which demonstrates something like this. Another way would be to extend jess.Rete and override aboutToFire() or justFired(); these hooks are provided to let you do per-rule processing like this. On Oct 23, 2007, at 4:13 PM, Shi Paul wrote: Hi Ernest or others, Here is the situation, say there are 2 rules A and B, I want whenever A fires B fires as well(or less frequently based on some other conditions) and I don't want to just copy A's conditions into B since that way I have to maintain 2 places. What I'd like to see in Jess is some kind of instructional command (for example (follow- rule A) in B's LHS), or better yet if Jess can hook up with some rules before or after A fires (which resembles AspectJ programming). I think it'd be a great feature if Jess allows that. Thanks, Paul - Ernest Friedman-Hill Informatics Decision Sciences Phone: (925) 294-2154 Sandia National LabsFAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] Livermore, CA 94550 http://www.jessrules.com
Re: JESS: How can I write this rule?
As compared to Bob's solution, there is no clause that restricts the 2nd not to those facts where the priority is equal to the established maximum. This is now required because the earliest time has to be found among those with the highest priority only. (Cf. the warning I added to the original solution where there was no requirement restricting the minimum to those facts matching the maximum!) (defrule MAIN::Station-3-Rule (MAIN::Station (id 3) (OBJECT ?station)) (MAIN::EntitiesQueue (downStreamRessourceId 3) (enqueuePriority ?priority1) (enqueueTimeStamp ?timeStamp1) (OBJECT ?upstreamQueue)) (not (MAIN::EntitiesQueue (downStreamRessourceId 3) (enqueuePriority ?priority2:( ?priority1 ?priority2 (not (MAIN::EntitiesQueue (downStreamRessourceId 3) (enqueuePriority ?priority1) ; (enqueueTimeStamp ?timeStamp2:( ?timeStamp1 ?timeStamp2 = (printout t Station-3-Rule has been activated ! crlf) ) Fires for: EntitiesQueue id=37, enqueuePriority=1, enqueueTimeStamp=30 kr Wolfgang Nicolas Fortin wrote: Hello group, Thank you very much Robert and Wolfgang for helping me even if it is the week end. I really appreciate this. After some tries in a test program with the rule that you suggested, I modified my real program to integrate the new rule. As you can see this rule is similar to Wolfgang's last: (defrule MAIN::Station-3-Rule (MAIN::Station (id 3) (OBJECT ?station)) (MAIN::EntitiesQueue (downStreamRessourceId 3) (enqueuePriority ?priority1) (enqueueTimeStamp ?timeStamp1) (OBJECT ?upstreamQueue)) (not (MAIN::EntitiesQueue (downStreamRessourceId 3) (enqueuePriority ?priority2:( ?priority1 ?priority2 (not (MAIN::EntitiesQueue (downStreamRessourceId 3) (enqueueTimeStamp ?timeStamp2:( ?timeStamp1 ?timeStamp2 = (printout t Station-3-Rule has been activated ! crlf) ) Unfortunately it is never activated and I can't figure out why. If I look the working memory it should. Attached to this post is the facts list (Facts.txt). Note that I inserted before the relevant facts, i.e. Station (id 3) (a single relevant fact) and EntitiesQueue (downStreamStationId 3) (3 relevant facts). I also attached the result of (matches MAIN::Station-3-Rule) function call (Matches.txt). Sorry for giving a lot of details. I rather like to give smallest example but I am not able to reproduce the problem. Any help or advice that could help me to debug this rule would be appreciate. Regards, Nicolas. Wolfgang Laun-2 wrote: On 10/21/07, Robert Kirby [EMAIL PROTECTED] wrote: If you want to consider only enabled instances, (defrule CP::enabled-example-rule Enabled My-Template with the greatest index1 and among those enabled with the smallest index2. (My-Template (id ?id) (enabled TRUE) (index1 ?index1) (index2 ?index2)) (not (My-Template (enabled TRUE) (index1 ?another-index1:( ?index1 ?another-index1 (not (My-Template (enabled TRUE) (index1 ?index1) (index1 ?another-index2:( ?index2 ?another-index2 = (printout t Enabled My-Template id= ?id with greatest index1= ?index1 and smallest index2= ?index2 with greatest index. crlf)) The rule isn't quite correct. In the second not term, you must bind slot index2 to ?another-index2, and the condition must be ( ?index2 ?another-index2). (Also, note the missing ''.) Thus: (defrule enabled-example-rule (My-Template (id ?id) (enabled TRUE) (index1 ?index1) (index2 ?index2)) (not (My-Template (enabled TRUE) (index1 ?another-index1 :( ?index1 ?another-index1 (not (My-Template (enabled TRUE) (index1 ?index1) (index2 ?another-index2 :( ?index2 ?another-index2 = (printout t id= ?id , index1= ?index1 , index2= ?index2 crlf) ) Cheers, Wolfgang If you want to only fire the maximal instance when it is enabled, (defrule CP::example-rule-when-enabled Enabled My-Template with the greatest index1 and among those enabled with the smallest index2. (My-Template (id ?id) (enabled TRUE) (index1 ?index1) (index2 ?index2)) (not (My-Template (index1 ?another-index1:( ?index1 ?another-index1 (not (My-Template (index1 ?index1) (index1 ?another-index2:( ?index2 ?another-index2 = (printout t My-Template id= ?id with greatest index1= ?index1 and smallest index2= ?index2 with greatest index is enabled. crlf)) Bob Kirby At 08:57 AM 10/20/2007, Nicolas Fortin wrote*: * Hello everybody, I have just added a bit more complexity to the previous rule and now I have the following template: (deftemplate MAIN::My-Template (slot id (type INTEGER)) (slot enabled (default FALSE
Re: JESS: How can I write this rule?
On 10/21/07, Robert Kirby [EMAIL PROTECTED] wrote: If you want to consider only enabled instances, (defrule CP::enabled-example-rule Enabled My-Template with the greatest index1 and among those enabled with the smallest index2. (My-Template (id ?id) (enabled TRUE) (index1 ?index1) (index2 ?index2)) (not (My-Template (enabled TRUE) (index1 ?another-index1:( ?index1 ?another-index1 (not (My-Template (enabled TRUE) (index1 ?index1) (index1 ?another-index2:( ?index2 ?another-index2 = (printout t Enabled My-Template id= ?id with greatest index1= ?index1 and smallest index2= ?index2 with greatest index. crlf)) The rule isn't quite correct. In the second not term, you must bind slot index2 to ?another-index2, and the condition must be ( ?index2 ?another-index2). (Also, note the missing ''.) Thus: (defrule enabled-example-rule (My-Template (id ?id) (enabled TRUE) (index1 ?index1) (index2 ?index2)) (not (My-Template (enabled TRUE) (index1 ?another-index1 :( ?index1 ?another-index1 (not (My-Template (enabled TRUE) (index1 ?index1) (index2 ?another-index2 :( ?index2 ?another-index2 = (printout t id= ?id , index1= ?index1 , index2= ?index2 crlf) ) Cheers, Wolfgang If you want to only fire the maximal instance when it is enabled, (defrule CP::example-rule-when-enabled Enabled My-Template with the greatest index1 and among those enabled with the smallest index2. (My-Template (id ?id) (enabled TRUE) (index1 ?index1) (index2 ?index2)) (not (My-Template (index1 ?another-index1:( ?index1 ?another-index1 (not (My-Template (index1 ?index1) (index1 ?another-index2:( ?index2 ?another-index2 = (printout t My-Template id= ?id with greatest index1= ?index1 and smallest index2= ?index2 with greatest index is enabled. crlf)) Bob Kirby At 08:57 AM 10/20/2007, Nicolas Fortin wrote*: * Hello everybody, I have just added a bit more complexity to the previous rule and now I have the following template: (deftemplate MAIN::My-Template (slot id (type INTEGER)) (slot enabled (default FALSE)) (slot index1 (type INTEGER)) (slot index2 (type INTEGER))) What I want to known is among the enabled My-Template with the greatest index1, what are those with the smallest index2. For example, with the following facts: (assert (MAIN::My-Template (id 1) (enabled TRUE) (index1 1) (index2 2))) (assert (MAIN::My-Template (id 2) (enabled TRUE) (index1 1) (index2 1))) (assert (MAIN::My-Template (id 3) (enabled TRUE) (index1 0) (index2 0))) Facts id 1, 2 and 3 are enabled. Only facts id 1 and 2 have the greatest index1. But among these facts, it is id 2 that has the smallest index2. So id 2 is the fact that I want. Another example, with the following facts: (assert (MAIN::My-Template (id 1) (enabled FALSE) (index1 1) (index2 2))) (assert (MAIN::My-Template (id 2) (enabled FALSE) (index1 1) (index2 1))) (assert (MAIN::My-Template (id 3) (enabled TRUE) (index1 0) (index2 0))) Facts id 3 is the only fact that is enabled, and there is no other enabled fact with greatest index1 and smallest index2. So id 3 is the fact that I want. Is it possible to do that with only one rule? Thank you. Nicolas From: [EMAIL PROTECTED] To: jess-users@sandia.gov Subject: RE: JESS: How can I write this rule? Date: Thu, 18 Oct 2007 16:59:19 -0400 Hello Ernest, There's a subtle difference between the solutions Jason and Wolfgang posted; you're basically using Jason's, but apparently you want Wolfgang's. Jason's and yours will fire for facts for which no single other fact has *both* a higher index1 and a lower index2. You're using a single not pattern, which restricts these two conditions to applying to a single other facts. Wolfgang's will for facts for which *no other fact* has a higher index1, and *no other fact* has a higher index2. He uses two separate not patterns to describe these two conditions, so each is considered separately. Make sense? It makes a lot of sense. Thank you for your explanation. In fact, I did not read Wolfgang's solution enough carefully. Sorry Wolfgang. Best regards, Nicolas. On Oct 18, 2007, at 8:30 AM, Nicolas Fortin wrote: Hello everybody and specially to Jason and Wolfgang. Thank you for your help guys. First, concerning what you said Jason, I don't want to hunt fact with the highest index1 and lowest index2 among all instances of an arbitrary number of fact template (e.g. My-Template, Queue, etc.). I did a typo (damn copy and paste), you should have seen only My- Template. So forget the Queue template. Second, I have already done an
Re: JESS: Java and Jess: Hashtable etc.
Hello Waschtl, Neither the code snippets nor the explanations you provided indicate what sort of facts you want to process with your rules, so I'm using classes of my own, which describe the facts I'm going to use: public class Song { private String myTitle; private String myAuthor; public Song( String title, String author ){ myTitle = title; myAuthor = author; } public String getTitle(){ return myTitle; } public void setTitle( String title ){ myTitle = title; } public String getAuthor(){ return myAuthor; } public void Author( String author ){ myTitle = author; } } import java.util.List; public class Album { String myArtist; private String myTitle; ListSong mySongs; public Album( String artist, String title, ListSong songs ){ myArtist = artist; myTitle = title; mySongs = songs; } public String getArtist(){ return myArtist; } public void setArtist( String artist ){ myArtist = artist; } public String getTitle(){ return myTitle; } public void setTitle( String title ){ myTitle = title; } public ListSong getSongs(){ return mySongs; } public void setSongs( ListSong songs ){ mySongs = songs; } } My main does a few simple things along the lines of your main. Notice the Rete add calls, where a Java object of one of my fact classes is added, one at a time. import java.util.ArrayList; import java.util.List; import jess.JessException; import jess.Rete; public class Project { private static String DIR = .../...; public static void main( String[] args ) throws JessException { System.out.println( Start... ); Rete engine = new Rete(); ListSong aftermath = new ArrayListSong(); aftermath.add( new Song( Mother's Little Helper, Jagger/Richards ) ); aftermath.add( new Song( Out Of Time, Jagger/Richards ) ); aftermath.add( new Song( Lady Jane, Jagger/Richards ) ); engine.add( new Album( The Rolling Stones, Aftermath, aftermath ) ); engine.add( new Song( A Hard Day's Night, Lennon/McCartney ) ); for( Song s: aftermath ){ engine.add( s ); } engine.batch( DIR + shTemp.clp ); engine.run(); System.out.println( Stop! ); } } If you want to add Java objects as facts, make sure that the classes they stem from have getters and setters according to JavaBeans. (The notion of adding a Hashtable isn't quite conformant with this.) See the Jess manual's section 5.3, Shadow facts: reasoning about Java objects. Now here are some simple rules: (defrule SongByLennonMcCarney ?song - (Song (author Lennon/McCartney)( title ?title)) = (printout t ?title crlf) ) (defrule AlbumWithSongByJaggerRichards ?jrsong - (Song (author Jagger/Richards) (OBJECT ?jrsongObj)) ?album - (Album (title ?title) (songs ?songs : (?songs contains ?jrsongObj))) = (printout t album with a song by Jagger/Richards: ?title crlf) ) Notice the binding of OBJECT so that we can use the List method contains. HTH Wolfgang
Re: JESS: How can I write this rule?
Nicolas Fortin wrote: Hello everybody, Suppose that I have the following template: (deftemplate MAIN::My-Template (slot id (type INTEGER)) (slot index1 (type INTEGER)) (slot index2 (type INTEGER))) I want a rule that would be activated by the fact with the greatest index1 *and* the smallest index2. Note that index1 and index2 *are not* unique. Assuming that you mean ...activated by *any* fact with..., (which, of course, need not exist as the maximum index1 could be in one fact and the minimum index2 in another),... So let's say that these facts are in the working memory: (assert (MAIN::My-Template (id 1) (index1 1) (index2 0)) (assert (MAIN::Queue (id 2) (index1 1) (index2 0)) (assert (MAIN::Queue (id 3) (index1 0) (index2 0)) ...and assuming that Queue is supposed to be the same as My-Template,... The rule would fire either with the first (id 1) or second (id 2) fact. ...and assuming that you mean ...would fire with the first (id 1) as well as with the second (id 2) fact And now let's say that these facts are in the working memory: (assert (MAIN::My-Template (id 1) (index1 1) (index2 -1)) (assert (MAIN::Queue (id 2) (index1 1) (index2 0)) (assert (MAIN::Queue (id 3) (index1 0) (index2 0)) The rule would fire only with the first fact (id 1). How can I write this kind of rule? ...you could write: (defrule minmax ?mt - (My-Template (id ?id) (index1 ?ind1) (index2 ?ind2)) (not (My-Template (index1 ?othind1 :( ?othind1 ?ind1 (not (My-Template (index2 ?othind2 :( ?othind2 ?ind2 = (printout t found ?id crlf) ) See the Jess manual's section 6.10., The 'not' conditional element. Thanks in advance. Nicolas http://www.emoticonesgratuites.ca/?icid=EMFRCA120 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: Jess JessTab protege
velven wrote: Is this due to the way i have written my rule such that for each agent, atleast (:X-coordinate ?x2:(= 1 (abs (- ?x2 ?x1 had to be checked by jess with another 199 agents? or something else? welcome any suggestions to optimise, Thank you for your time Forget my doubts regarding your formulas. For an agent at 'A', you match any other at any of the nine 'X' and at 'A'. As you have written, it's the many pairs that can be combined from 200 facts that cause the slow down. -Wolfgang 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: Jess JessTab protege
velven wrote: Hi everyone, I'm new to Jess and I have some questions 1) I'm using (mapclass) to map my protege classes into jess, but I found What is (mapclass), please? that the function maps all userdefined slots to be multislots although i have set them to be required single cardinality and integer type in protege. ie. the generated is (multislot :X-coordinate) when what i need is (slot :X-coordinate (type INTEGER)) The trouble occurs when i need to get the value to Java and it is identified as a list and I cannot use (slot-get) as only the facts were being modified during runtime (...slot-set is too costly) What is (slot-get) or (slot-set)? Though conversion is possible, I'm just wondering if theres a better way to do it as the conversion seems abit wasteful and costly to my simulation's execution. 2)I have this rule (defrule moving_aside ?node1-(object (is-a Agent)(:NAME ?n1)(:X-coordinate ?x1)(:Y-coordinate ?y1)(:Behaviour ?b1~move_aside~look_for_leader)) ?node2- (object (is-a Agent)(:NAME ?n2~?n1)(:X-coordinate ?x2:(= 1 (abs (- ?x2 ?x1(:Y-coordinate ?y2:(= 1 (abs (- ?y2 ?y1) = (modify ?node1 (:Behaviour move_aside)) ) Basically this rule checks for another agent beside it and set its behaviour to another state if present. According to my test case, though this rule is never fired, its presence alone slowed down the simulation with 200 agents. The checks resulting from the LHS are exercised each time object facts are asserted or modified. The *firing* of this rule with its simple RHS isn't the expensive part. Since you write that X-coordinates are INTEGER, a comparison using (:X-coordinate ?x2~?x1) might be a little faster. (But isn't either x-coordinate differs *or* y-coordinate differs sufficient to warrant the change of :Behaviour? As it stands now, *both* must differ.) -Wolfgang Is this due to the way i have written my rule such that for each agent, atleast (:X-coordinate ?x2:(= 1 (abs (- ?x2 ?x1 had to be checked by jess with another 199 agents? or something else? welcome any suggestions to optimise, Thank you for your time 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: Rules firing only once
Another solution to your problem could be based on a deftemplate Category which is used for finding a group of experts. Experts' facts are kept in a linked list used for assigning another expert for every new problem. (The code assumes that one expert is servicing only one Category, but this can be extended easily.) (deftemplate Category (slot catId) (slot currExpert (default nil))) (deftemplate Expert (slot name) (slot catId) (slot prevExpert (default nil)) (slot nextExpert (default nil))) (deftemplate Problem (slot proId) (slot user) (slot catId) (slot asgnExpert (default nil)) (slot status (default NEW))) (defrule assignProblem ?p - (Problem (catId ?cat)(status NEW)) ?c - (Category (catId ?cat)(currExpert ?e)) = (modify ?p (status ASSIGNED)(asgnExpert ?e)) (modify ?c (currExpert (fact-slot-value ?e nextExpert))) ) (defrule addExpert ?e - (Expert (prevExpert nil)(catId ?cat)) ?c - (Category (catId ?cat)(currExpert ?exp)) = (bind ?prev (fact-slot-value ?exp prevExpert)) (bind ?next (fact-slot-value ?exp nextExpert)) (modify ?e (prevExpert ?prev)(nextExpert ?next)) (modify ?prev (nextExpert ?e)) (modify ?next (prevExpert ?e)) ) (defrule addCategoryAndExpert ?e - (Expert (prevExpert nil)(catId ?cat)) (not (Category (catId ?cat))) = (assert (Category (catId ?cat)(currExpert ?e))) (modify ?e (prevExpert ?e)(nextExpert ?e)) ) (deffunction addExpert (?name ?cat) (assert (Expert (name ?name)(catId ?cat (deffunction addProblem (?pro ?user ?cat) (assert (Problem (proId ?pro)(user ?user)(catId ?cat))) (run)) (reset) (addExpert Jon cats) (addExpert Jerry cats) (addExpert Popeye spinach) (run) (addProblem 1 Ann cats) (addProblem 2 Bea spinach) (addProblem 3 Ann cats) (addProblem 4 Chi cats) (run) (facts) Noël Huebers wrote: Dear Jessers, I am developing a kind of an expert system. If a user has a problem, a problem fact is asserted. Now I'm looking at a rule to find an expert for my problem. In my implementation it is possible that several experts (facts) can match for the asserted problem. Right now, the user with the problem receives multiple expert proposal. But I want the user to get only one by time. Therefore, the rule should only fire once. I tried to modify the rule with 'exists'-test. Unfortunatly, I use some slots of the expert fact (e.g. name) on the RHS of the rule. Jess throws an exception that the bound variable of the expert fact is unknown. I read something according to this on the Jess book. Is there another way of achieving this? Another solution would be to retract the problem fact after the rule found the first expert. But later on, I want to implement a confirmation that the contact was established. If the expert is not available the problem fact should remain in the working memory. Another question is, after this problem is solved: Is it possible to randomize the matching expert fact? I don't want the first expert in the memory to get all of the help calls. Thanks for your suggestions! Best regards, Noel Huebers 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: Java objects
Noel Huebers wrote (defquery searchcontext (declare (variables ?name ?task ?val)) (context (username ?name) (action Bewertet) (task ?task) (value ?val))) Now I want to delete the some facts. How do I get a fact from the queryresult '?result' ? ;(deffunction delformerattempts(?n ?t ?v) ;(bind ?results (run-query* searchcontext ?n ?t ?v)) ;(while (?results next)) ;(retract ?results get)) All you have to do is extend the pattern in the query with a binding for the entire fact: (defquery searchcontext (declare (variables ?name ?task ?val)) ?context - (context (username ?name) (action Bewertet) (task ?task) (value ?val))) And then you access it with the get method: (deffunction delformerattempts (?n ?t ?v) (bind ?results (run-query* searchcontext ?n ?t ?v)) (while (?results next) (retract (?results get context But wouldn't it be more convenient to rearrange things so that the context fact maintains a counter, with new Bewertet events being counted right there. Here's how: (clear) (deftemplate Base (slot username)(slot action)(slot value)(slot task)) (deftemplate Context extends Base (slot count (default 1))) (deftemplate Event extends Base (slot stamp )) (defrule IncrementCount ?event - (Event (username ?s)(action Bewertet)(value ?v)(task ?t)) ?context - (Context (username ?s)(action Bewertet)(value ?v)(task ?t)(count ?c)) = (modify ?context (count (++ ?c))) (retract ?event) ) (defrule FirstTime ?event - (Event (username ?s)(action Bewertet)(value ?v)(task ?t)) (not (Context (username ?s)(action Bewertet)(value ?v)(task ?t))) = (assert (Context (username ?s)(action Bewertet)(value ?v)(task ?t))) (retract ?event) ) (deffacts ecs (Event (username Max)(action Bewertet)(value 3)(task Thesis)(stamp 1)) (Event (username Max)(action Bewertet)(value 3)(task Thesis)(stamp 2)) (Event (username Max)(action Bewertet)(value 3)(task Thesis)(stamp 3)) ) (reset) (run) kr Wolfgang 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: Java objects
Noël Huebers wrote: Hi, I'm new to the Jess language and have some questions. 1. I work with Java object. I stored them in Jess with store and assert/fetch commands. But I could not call there member in the lhs of my rule. No function calls allowed, right? So, for every object I made a rule to insert a Jess template. This works fine, but is this way of mapping Java objects to Jess facts and then discarding the object the best way to work with java objects? store and fetch are just a way of storing and retrieving arbitrary data. If you want to use Java objects in rules, look into the topic of shadow facts, see section 5.3. Shadow facts: reasoning about Java objects. 2. I am trying to implement a counter-logic for specific slot combinations. First, everytime a fact is inserted I check if there is already a procounter fact. If not I create one. This works fine. The next rule should recognize when a fact (EContext) is inserted and the counter (procounter) already exists. In this case, the count slot should only be modified. I try to compare bounded vars ?s ?v ?t from EContext to procounter slots, but I think Jess simply overwrites the binding. Can you help me with the correct syntax? Is there a better logic to implement a counter? If you have one fact (EContext (studentname Max) (action bewertet)(value 3)(task Thesis)) it won't be possible to ever assert another fact just like this one. This might be the cause of modpro failing to fire. Consider adding another slot to EContext such as a date or time stamp, and then you might see an increase. Notice that the rule might benefit from adding the option (declare (no-loop TRUE)). Best regards, Noel Huebers ***CODE*** (defrule modpro ; counter erhöhen (and (EContext (studentname ?s) (action bewertet) (value ?v) (task ?t)) ?pro - (procounter (name ?s) (task ?t) (val ?v) (count ?x)) ) = (modify ?pro (count (+ ?x 1))) ;increase counter (printout t Counter für ?s ?t ?v erhöhen!!! crlf)) 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: multislot matching and binding
Is it correct that it isn't possible to bind the entire value of a multislot to a variable *and* use some list pattern to restrict the facts at the same time? Consider: (deftemplate AE (multislot ae)) (deffacts facts (AE (ae a b c d e)) (AE (ae b c d e a)) (AE (ae e d c b a)) ) (defrule Rule ?fae - (AE (ae $?msae $? b c $? )) = (printout t match: ?msae crlf) ) (reset) Jess (run) match: () match: (a) 2 All the '' achieves is that both $?msae and the anonymous $? are bound to the sublist preceding b-c. It's possible to work around this restriction: A predicate can be written to test for the pattern, such as, e.g. (ae $?msae :(test-bc ?msae)). Wolfgang 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: Constraining values of a slot
To at least *detect* bad slot values consider setting up suitable rules that throw an exception, or whatever. The task of generating these straightforward rules can be automated with a userfunction. You might then, for instance, write (deftemplate SrcTemp (slot destFact)) (deftemplate DstTemp (slot id)) ;; set up the check for SrcTemp/destFact (fact-in-slot SrcTemp destFact DstTemp) An implementation of fact-in-slot can be found on this Jess Wiki pagehttp://herzberg.ca.sandia.gov/jesswiki/view?FactInSlotUserFunction
Re: JESS: query distinct values of a slot
Two solutions. (A) You define a query: (defquery personQuery (person (firstName ?fn)(lastName ?ln)(age ?age))) The Jess function values-of runs the query and processes the result, collecting the values of the result component with the name given as the function argument name into the list that's stored in ?values: (deffunction values-of (?comp) (bind ?result (run-query* personQuery)) (bind ?values (list)) (while (?result next) (bind ?values (union$ ?values (list (?result getString ?comp) (return ?values) ) You may call it like this: Jess (printout t (values-of fn) crlf) (Fred Bob Pete George) Or like this: Jess (printout t (values-of ln) crlf) (Smith Jones Thomas Best Smithson) (B) Another approach would be to keep a running union of the slot values in a single fact of another template called, say, firstNames. Its multislot values is initially empty: (deftemplate firstNames (multislot values)) (deffacts data (firstNames (values (list))) (person (firstName Fred) (lastName Smith)(age 12)) ... ) You need a rule to update your firstNames facts whenever there is a new person: (defrule first (person (firstName ?fn)) ?fns - (firstNames (values $?vlist)) = (modify ?fns (values (union$ $?vlist (list ?fn) With your set of facts and after a (run), you'll have another fact: (MAIN::firstNames (values George Pete Bob Fred)) and this will always be up-to-date after any person additions or firstName updates of person facts. In case of a retract, modify the values slot to the empty list, and it will re-collect the first names from the reduced set of person facts. kr Wolfgang Joaquín Cañadas wrote: Hello, I need some help with queries. How can I query the distinct values of a slot? The manual explains how to select facts with a concrete value in an slot. But my problem is different, for example, with these facts: *Jess *(deffacts data (person (firstName Fred) (lastName Smith)(age 12)) (person (firstName Fred) (lastName Jones)(age 9)) (person (firstName Bob)(lastName Thomas) (age 32)) (person (firstName Bob)(lastName Smith)(age 22)) (person (firstName Pete) (lastName Best) (age 21)) (person (firstName Pete) (lastName Smith)(age 44)) (person (firstName George) (lastName Smithson) (age 1)) ) I would like to obtain the distinct values of firstname slot: *Fred Bob Pete George* Is that possible? Thank you in advance Joaquín 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: No rules firing
One might very well argue that the automatic definition of a template for ordered facts, as in (defrule r (t 1 ?two) = ... ) or any fact definition is somewhat dangerous since it might cover up anything from a simple typos to a major syntax error. Adding the option of suppressing the auto-definition of ordered templates would be one way. Another way is the study of cross-references for templates by rules and queries, and vice versa. For obtaining the latter, see http://herzberg.ca.sandia.gov/jesswiki/view?TempsByRulesUserFunction and http://herzberg.ca.sandia.gov/jesswiki/view?RulesByTempsUserFunction Cheers Wolfgang Robert Kirby wrote: I would help to pretty-print your rules. If you had, you could see that you have (eq ?ov ?locality) (eq ?wv ?street) as patterns within an and to be matched rather than (test (and (eq ?ov ?locality) (eq ?wv ?street))). By the way, the outer and on the LHS of locality-stree is unnecessary. Bob Kirby At 11:48 AM 7/30/2007, Matthew J Hutchinson wrote: Hi, I have tried loading the following code with the batch command, then (run)ing the whole lot, unfortunately my rule is not firing. I was expecting the rule to fire, and as a result there should be several new locality-street-match facts. The code includes: --- (reset) (watch activations) (deftemplate potential-element (slot type)(slot value) ) (deftemplate agreement (slot of-type)(slot of-value)(slot with-type)(slot with-value) ) (deftemplate locality-street-match (slot locality-value)(slot street-value) ) (defrule locality-street (and (agreement (of-type locality)(of-value ?ov)(with-type street)(with-value ?wv)) (potential-element (type locality)(value ?locality)) (potential-element (type street)(value ?street)) (eq ?ov ?locality) (eq ?wv ?street) ) = (assert (locality-street-match (locality-value ?locality)(street-value ?street) ) ) ) (assert (potential-element (type locality)(value south perth) ) ) (assert (potential-element (type locality)(value wembley) ) ) (assert (potential-element (type locality)(value bentley) ) ) (assert (potential-element (type locality)(value floreat) ) ) (assert (potential-element (type locality)(value osborne park) ) ) (assert (potential-element (type street)(value marlow) ) ) (assert (potential-element (type street)(value coode) ) ) (assert (potential-element (type street)(value jutland) ) ) (assert (potential-element (type street)(value grantham) ) ) (assert (potential-element (type street)(value giles) ) ) (assert (agreement (of-type locality)(of-value south perth)(with-type street)(with-value coode) ) ) (assert (agreement (of-type locality)(of-value wembley)(with-type street)(with-value marlow) ) ) (assert (agreement (of-type locality)(of-value dalkeith)(with-type street)(with-value jutland) ) ) (assert (agreement (of-type locality)(of-value wembley)(with-type street)(with-value grantham) ) ) (assert (agreement (of-type locality)(of-value floreat)(with-type street)(with-value marlow) ) ) --- then I (run) it. Any ideas? - thank you so much. Cheers, Matt -- Matthew Hutchinson Ph.D. Candidate Department of Spatial Sciences Curtin University of Technology GPO Box U1987 Perth, Western Australia 6845 Visiting Scholar Department of Geography and Planning University of Akron Akron, Ohio USA 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: Java 1.5 enums
To match a slot with the result or a method call, prefix the call with an equal sign: (MyShadowFact (OBJECT ?o) (property1 =(MyEnum.xyz))) krW On 7/27/07, Krasnigor, Scott L (N-AST) [EMAIL PROTECTED] wrote: I believe you need to surround the enum with ( ), e.g. (property1 (MyEnum.xyz)). Enums are treated like method calls. The ( ) causes a call to your enum class to get the associated value for the enum. Hope this works for you. From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Skeptic 2000 Sent: Thursday, July 26, 2007 11:18 PM To: jess-users@sandia.gov Subject: JESS: Java 1.5 enums Hi, As shown on JessWiki, I use the import functions to get my enum class in Jess : (import xx.yy.zz.MyEnum) then I try to match a slot of a shadow fact to one of the enum field : (defrule rule1 (MyShadowFact (OBJECT ?o) (property1 MyEnum.xyz)) = ... ) What I'm doing wrong ? Thanks. JFL Soyez parmi les premiers à essayer Windows Live Mail. 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: Who needs class as a slot in a shadow fact?
Ernest Friedman-Hill wrote: On Jul 24, 2007, at 12:17 PM, Wolfgang Laun wrote: we see that the fact includes a slot class, inherited from Object . Why is this not suppressed? It never has been. Although I don't think the class property is *extremely* useful, I could certainly come up with ways to use it. It spares you the hazzle of writing ((fact-slot-value ?f OBJECT) getClass): you can do (fact-slot-value ?f class). OTOH, you can subclass jess.ReflectionClassResearcher, override getBeanProperties to filter out the class bean and set this as the Rete's class researcher. kr Wolfgang 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: Who needs class as a slot in a shadow fact?
After Jess (deftemplate Signal (declare (from-class at.laune.jess.Signal))) TRUE Jess (ppdeftemplate Signal) (deftemplate MAIN::Signal \$JAVA-OBJECT$ at.laune.jess.Signal\ (declare (from-class at.laune.jess.Signal))) Jess (bind ?f1 (assert (Signal))) Fact-1 Jess (facts) f-0 (MAIN::initial-fact) f-1 (MAIN::Signal (aspect Java-Object:jess.aj) (class Java-Object:jess.aj) (ident Java-Object:jess.aj) (OBJECT nil)) For a total of 2 facts in module MAIN. Jess we see that the fact includes a slot class, inherited from Object . Why is this not suppressed? kr Wolfgang 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: Defmodule vs. defrule
Isn't a (defmodule X) just a way of setting the default namespace for templates, facts, queries and rules? This, then, means that the execution of a (defmodule X) doesn't really imply that a module has come into existence. (Or does it create an empty module X and does (focus X) achieve anything useful?) Anyway, the point I'm trying to make is that only the arrival of some template/fact/query/rule of some module M really establishes that module M as a useful object. And since it is possible to override the default module name only a look at the full name of some new template/fact/query/rule will tell which module this item belongs to. Deleting a module is extremely tricky and has - in the general case - many hidden snags: - If (delete-module M) is executed on the RHS of a rule M::r, what does this mean? - What if the deleted module is on the focus stack? Remove it silently, throw an exception,...? - Any fact or template or query from some module M1 can be referenced from a rule or query of some other module M2. Apart from some complex checking, what should happen if this is detected? - What if you have a (deftemplate M2::T2 extends M1::T1)? - ... kr Wolfgang Henrique Lopes Cardoso wrote: I believe this was the second time you give me this kind of answer :). But I don't see any improvements in Jess71a2... Can I expect undefmodule and module-related events to be added in the next alpha version? Thanks. Henrique 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: Problem with bload and System functions
I can reproduce that error with Foo and Bar, running Jess7.1a1, due to some null pointer exception in the eval. But the documentation for the Jess function call says: The functor call may be omitted if the method being called is non-static. I guess that means that the call, as tried by Henrique, is in error. Using the correct form: System.out.println( jess.eval( (call System currentTimeMillis) ) ); works fine. But now the question is, why does jess.eval( (System.currentTimeMillis) ); work in the first place - it does, on the same system, omitting the bload calls. kr Wolfgang On 7/6/07, Ernest Friedman-Hill [EMAIL PROTECTED] wrote: Running Bar followed by Foo works for me (Jess 7.1a1). Does is not work for you? public class Bar { public static void main(String[] foo) throws Exception { Rete jess = new Rete(); FileInputStream fis = new FileInputStream (the_file.bsave); jess.bload(fis); fis.close(); System.out.println(jess.eval ((System.currentTimeMillis))); } } public class Foo { public static void main(String[] foo) throws Exception { Rete jess = new Rete(); FileOutputStream fos = new FileOutputStream (the_file.bsave); jess.bsave(fos); fos.close(); } } On Jul 6, 2007, at 8:36 AM, Henrique Lopes Cardoso wrote: Hi, If I bload a file (even an empty one), I get an Error during execution when executing (System.currentTimeMillis). Here's my code: Rete jess = new Rete(); FileInputStream fis = new FileInputStream (the_file.bsave); jess.bload(fis); fis.close(); jess.eval((System.currentTimeMillis)); It works fine if I read a .clp jess file using Jesp. Henrique -- - - - - - - - - - - - - - Henrique Lopes Cardoso DEEC/FEUP Rua Dr. Roberto Frias | 4200-465 Porto PORTUGAL (+351)225081400 ext.1315 [EMAIL PROTECTED] | www.fe.up.pt/~hlc - - - - - - - - - - - - - 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 owner-jess- [EMAIL PROTECTED] - 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] 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: Problem with bload and System functions
Here is another check on the effect of bsave/bload. I define this function: (deffunction ppallfunctions () (bind ?sb (new StringBuffer)) (bind ?it ((engine) listFunctions)) (while (?it hasNext) (bind ?f (?it next)) (bind ?class (call ?f getClass)) (?sb append ?class) (?sb append ) (?sb append ?f) (?sb append : ) (bind ?iflist (call java.util.Arrays asList (call ?class getInterfaces))) (for (bind ?i 0) ( ?i (?iflist size)) (++ ?i) ((?sb append ) append (?iflist get ?i )) ) (?sb append ) ) (?sb toString) ) Running (ppallfunctions) and writing this to before.txt, then doing a bsave/bload and another (ppallfunctions), this time to after.txt: $ wc before.txt after.txt 772before.txt 381after.txt So, I guess, the imported statics are still known (otherwise there would be a proper error message), but they aren't fully defined, sort of. 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: An inconsistency between listFunctions() and PrettyPrinter()
This is surprising: (deffunction ppallfunctions () (bind ?sb (new StringBuffer)) (bind ?it ((engine) listFunctions)) (while (?it hasNext) (bind ?f (?it next)) ;; The following call isn't possible because the intrinsic functions ;; don't implement jess.Visitable, and the only constructor for ;; jess.PrettyPrinter has an argument of this type. ;;(?sb append (new jess.PrettyPrinter (?f))) (?sb append ) ) (?sb toString) ) OK, one can filter the unhospitable functions, but what's the point in returning objects that cannot be processed in the usual way? 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: Problem with bload and System functions
The same problem occurs when running bin/jess, and (most likely) with any other of the import-ed things. Statics of some classes are automatically (imports are in jess/scriptlib.clp) defined as functions, and that's why there are some exceptions to the rule stated in the documentation on (call...), and that's why (call class method) works. Notice that after re-running an import after a bload, all is well again. ~~/Jess$ /extra/Jess71a1/bin/jess Jess, the Rule Engine for the Java Platform Copyright (C) 2006 Sandia Corporation Jess Version 7.1a1 5/14/2007 This copy of Jess will expire in 27 day(s). Jess (bsave) Jess reported an error in routine Funcall.get while executing (bsave). Message: Missing argument(s) in function call (bsave). Program text: ( bsave ) at line 2. Jess (bsave a_file.bsave) TRUE Jess (bload a_file.bsave) TRUE Jess (System.currentTimeMillis) Jess reported an error in routine System.currentTimeMillis while executing (System.currentTimeMillis). Message: Error during execution. Program text: ( System.currentTimeMillis ) at line 5. Nested exception is: null Jess (exit) ~~/Jess$ /extra/Jess71a1/bin/jess Jess, the Rule Engine for the Java Platform Copyright (C) 2006 Sandia Corporation Jess Version 7.1a1 5/14/2007 This copy of Jess will expire in 27 day(s). Jess (System.currentTimeMillis) 1183840185529 Jess (bload a_file.bsave) TRUE Jess (System.currentTimeMillis) Jess reported an error in routine System.currentTimeMillis while executing (System.currentTimeMillis). Message: Error during execution. Program text: ( System.currentTimeMillis ) at line 3. Nested exception is: null Jess (call System currentTimeMillis) 1183840265505 Jess (System.getenv HOME) Jess reported an error in routine System.getenv while executing (System.getenv HOME). Message: Error during execution. Program text: ( System.getenv HOME ) at line 5. Nested exception is: null Jess (call System getenv HOME) /home/laune Jess (Integer.highestOneBit 17) Jess reported an error in routine Integer.highestOneBit while executing (Integer.highestOneBit 17). Message: Error during execution. Program text: ( Integer.highestOneBit 17 ) at line 4. Nested exception is: null Jess (import java.lang.Integer) TRUE Jess (Integer.highestOneBit 17) 16 Jess 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: Announcing wiki contributions
On 7/3/07, Wolfgang Laun [EMAIL PROTECTED] wrote: There are some recent contributions to the topic Design Patterns on the Jess Wiki (http://www.jessrules.com/jesswiki/view). And here's FactsAsSlotValues, another design pattern. Given the right data, it may be used to answer questions such as: Who are the parents of George II? Jess (getParents George II) George II is the child of George I and Sophia Dorothea of Brunswick-Lüneberg. Who succeeds James II? Jess (getSuccessor James II) King William III is the successor of King James II. Queen Mary II is the successor of King James II. Almost in time for Independence Day... ;-) Kind regards Wolfgang 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: Announcing wiki contributions
There are some recent contributions to the topic Design Patterns and to the User Function Examples section of the topic Jess Snippets on the Jess Wiki (http://www.jessrules.com/jesswiki/view). The design patterns (if that's what they are) demonstrate * the association of actions with facts (ActingFacts), * the processing of facts arranged as a tree (IvyOnTrees) and * an algorithm operating on a network of nodes (FanOutZoomIn). The Userfunction examples deal with * string processing (JoinStrings, Interpolate), * list processing (SpliceList), * calling lambda functions (LambdaCall), * accessing facts (AsBean, GetTemplate), * timer functions (AfterEvery) and * miscellaneous (WhatIs). Any comments (critique, suggestions for improvement,...) more than welcome. Kind regards Wolfgang Laun 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: Re: Real deftemplate of extended fact - Solved it!
This Userfunction is another way of getting the deftemplate name of some fact: http://herzberg.ca.sandia.gov/jesswiki/view?GetTemplateUserFunction HTH Wolfgang Henrique Lopes Cardoso wrote: Hi, Just to let you know that I solved my own problem. I had not realized that with a query like (defquery q (declare (variables ?foo)) ?x - (t (foo ?foo)) ) I can access variable ?x and turn it into a fact object (although I have done it before). I then did something like: QueryResult qr = jess.runQueryStar(q, new ValueVector().add(1)); qr.next(); qr.get(x).factValue(engine.getGlobalContext()).getDeftemplate().getBaseName() Is there an easier way to do it? Henrique Henrique Lopes Cardoso wrote: Hi, I am trying to get the real deftemplate of a fact belonging to a sub-deftemplate. Something like this: (deftemplate t (slot foo) ) (deftemplate t1 extends t (slot bar)) (deftemplate t2 extends t (slot qwe)) ; The facts (t1 (foo 1) (bar 2)) (t2 (foo 2) (qwe 1)) Now, I am trying to get the real deftemplate name for a fact: (defrule r (t (foo 1)) = (printout t The real deftemplate name for this fact is ???t1_or_t2??? crlf)) I want to get this from Java, so I thought of defining a defquery and access its results (is there an easier way, e.g. through the Rete class API?). (defquery get-real-deftemplate-name (declare (variables ?foo)) ?context - (t (foo ?foo)) ; NOW WHAT? ) There is probably an easy way to do this, right? Thanks, Henrique 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: Help: OutOfMemory problem
Not knowing the details, I can only quote divide and conquer. If the sets of facts (F) and rules (R) can be divided so that F = union(F1, F2,... Fn) and R = union(R1, R2,...Rn) and these may be paired to run as F1/R1,...Fn/Rn then you might be able to process even bigger Java programs. Perhaps some of the investigative rules need only facts local to some .java file or, perhaps, some package. I guess that only public/import related issues would require a global view of things. WL Ernest Friedman-Hill wrote: On Jun 27, 2007, at 3:22 PM, fan yang wrote: I didn't take consideration of Q12 yet. I will look at it. But for my case, I just tried to load facts and didn't try to fire the rules. Do you have other advices for me? Thank you. Pattern matching happens when working memory is changed -- i.e., all the partial matches are formed when you assert the facts. When you call run, Jess already knows what rules to fire -- it's a fast and efficient operation. So in fact this is precisely the solution to your problem -- you just have to figure out how to properly implement it. On 6/27/07, Ernest Friedman-Hill [EMAIL PROTECTED] wrote: On Jun 27, 2007, at 1:47 PM, fan yang wrote: I have tried Jess Version 7.1a1 to load the same aforementioned facts file, I still got the following error without any luck. Ernest, you said that 7.1 parser would detect duplicate symbols and share them, how can I know this new function work? Need I give some commands to Jess and ask Jess parser detect duplicate and share them? If 7.1 parser will not be a solution for my problem, is there another way to fix or alleviate my problem? thank you. Well, since there was a relevant new feature, that's the first thing I mentioned; but there is a lot of old-school advice I can give, too. The most important one is understanding and minimizing partial-match count. For example, in the FAQ there is a question dedicated to this: http://herzberg.ca.sandia.gov/jess/FAQ.shtml#Q12 . Have you taken this into consideration yet? If not, that's where you go next. Fan Jess Exception in thread main java.lang.OutOfMemoryError : Java heap space at jess.factory.FactoryImpl.newToken(FactoryImpl.java:27) at jess.Node2.tokenMatchesLeft(Node2.java:328) at jess.Node2.tokenMatchesRight(Node2.java :344) at jess.Node2.doRunTestsVaryLeft (Node2.java:381) at jess.Node2.runTestsVaryLeft(Node2.java:354) at jess.Node2.callNodeRight(Node2.java:234) at jess.Node1.passAlong (Node1.java:49) at jess.Node1TECT.callNodeRight (Node1TECT.java:40) at jess.NodeRoot.passAlong(NodeRoot.java:34) at jess.NodeRoot.callNodeRight(NodeRoot.java:14) at jess.FactList.processToken(FactList.java:31) at jess.FactList._assert (FactList.java:204) at jess.FactList.assertFact(FactList.java:178) at jess.Rete.assertFact(Rete.java:495) at jess.Jesp.loadFacts(Jesp.java:351) at jess.LoadFacts.call(IOFunctions.java :314) at jess.FunctionHolder.call(FunctionHolder.java:35) at jess.Funcall.execute (Funcall.java:325) at jess.Jesp.parseAndExecuteFuncall(Jesp.java:2190) at jess.Jesp.parseExpression (Jesp.java:453) at jess.Jesp.promptAndParseOneExpression(Jesp.java:303) at jess.Main.execute(Main.java:177) at jess.Main.main(Main.java:35) On 6/27/07, Ernest Friedman-Hill [EMAIL PROTECTED] wrote: It looks like your facts include a mostly symbols, with a lot of duplication. This is good news, because the parser in Jess 7.1 (there's an alpha version available on the web site) will detect duplicate symbols and share them, which in your case could save a *lot* of memory. Try it out and see what happens! On Jun 27, 2007, at 9:34 AM, fan yang wrote: Hi, I'm trying to use Jess to detect source code defects. The tool first parse source code and generate facts which represent design information such as classes, functions, attributes, inheritances and invocations etc., then apply Jess rule to detect flaws. The tools works on small size of source code. but It got OutOfMemory error when it dealt with bigger projects such as JHotDraw (SourceForge project). I have read Jess manual, mailing list and Jess in Action book, I didn't get solution. Would you please tell me how to apply Jess on large facts set. What is the best practice or procedure to make Jess application use less memory. Or Is there a way to know how many memory the different facts occupy? Here shows a little bit more details of my test case, can you point me right way to avoid out of memory problem? JHotDraw project's facts file is about 4M bytes. My computer has 2G RAM. I set maximum java heap size to 1G through JVM's -Xmx1024M, I got OutOfMemory exception when I just tried to load facts using the following code: (clear) (batch
Re: JESS: Another rule that doesn't fire
Robert Kirby wrote: Since the accumulate-NextTo pattern (accumulate (bind ?xcount 0) (++ ?xcount) ?xcount (NextTo (room1 ?rid))) doesn't include a room2 match, shouldn't the pattern be matched just once for any one ?rid instantiation? The documentation is not clear about what a token means: a match to a fact or a node in the Rete network. Moving the (reset) down, just before (run), produces the expected result; so I guess my (naive?) expectations with respect to accumulate aren't entirely wrong: --- 103 has 1 connections. --- 102 has 2 connections. --- 101 has 2 connections. === Suite 100 has 1 neighbours. --- 100 has 1 connections. 5 Notice that NextTo is not meant to be symmetric, although common sense would indicate that forall x, y | x y : NextTo(x,y) = NextTo(y,x). (This is a *very* mathematical hotel; you might say a mathel ;-) Incidentally, deftemplate Room includes a default of false for a boolean slot. Due to case sensitivity, the default should probably be FALSE. OK, but not relevant for the problem. (I've changed things as compared to the original source.) -W Bob Kirby At 08:39 AM 6/27/2007, Wolfgang Laun wrote: Perhaps this is of interest: The original code had two rules - the only ones with accumulate - as the fifth and sixth rule between (reset) and (run), and the problem didn't surface until I added number 6. -W Ernest Friedman-Hill wrote: This appears to be an incremental reset bug. The term incremental reset refers to the special processing that has to be done to bring a rule up to date if it's added to an already-populated working memory. Jess expects you to do things the other way around: compile the Rete network by defining all the rules, and then push the data through it; and indeed, if you move your reset to after the rules are defined, they both fire correctly. Thanks for the report; we'll look into this further and get it fixed. On Jun 27, 2007, at 10:34 AM, Wolfgang Laun wrote: In the program below, Jess will only fire the second rule if both are uncommented, but each of them fires if the other one isn't there. If the order of rule definitions is reversed, the second one wins again. Jess Version 7.0p1 Kind regards Wolfgang (clear) (deftemplate Obj (slot id (type STRING)) ) (deftemplate Room extends Obj (slot occupied (type SYMBOL)(default false)) ; Boolean ) (deftemplate Suite extends Room (slot rooms (type INTEGER))) (deftemplate Single extends Room) (deftemplate Double extends Room) (deftemplate NextTo (slot room1 (type STRING)) (slot room2 (type STRING)) ) (deffacts fact-23 (Suite (id 100) (rooms 3)) (Single (id 101)) (Double (id 102)) (Double (id 103)) (NextTo (room1 100)(room2 101)) (NextTo (room1 101)(room2 100)) (NextTo (room1 101)(room2 102)) (NextTo (room1 102)(room2 101)) (NextTo (room1 102)(room2 103)) (NextTo (room1 103)(room2 102)) ) (reset) ;;/*** (defrule oneNext Check that a suite has exactly one neighbour. (Suite (id ?rid)) ?sn - (accumulate (bind ?xcount 0) (++ ?xcount) ?xcount (NextTo (room1 ?rid))) (test (= ?sn 1)) = (printout t === Suite ?rid has ?sn neighbours. crlf) ) ;;***/ ;;/*** (defrule maxNext Check that no room is next to three or more. (Room (id ?rid)) ?nc - (accumulate (bind ?count 0) (++ ?count) ?count (NextTo (room1 ?rid))) (test (= ?nc 2)) = (printout t --- ?rid has ?nc neighbours. crlf) ) ;;***/ (run) 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 owner-jess- [EMAIL PROTECTED] - 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] 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
JESS: Another rule that doesn't fire
In the program below, Jess will only fire the second rule if both are uncommented, but each of them fires if the other one isn't there. If the order of rule definitions is reversed, the second one wins again. Jess Version 7.0p1 Kind regards Wolfgang (clear) (deftemplate Obj (slot id (type STRING)) ) (deftemplate Room extends Obj (slot occupied (type SYMBOL)(default false)) ; Boolean ) (deftemplate Suite extends Room (slot rooms (type INTEGER))) (deftemplate Single extends Room) (deftemplate Double extends Room) (deftemplate NextTo (slot room1 (type STRING)) (slot room2 (type STRING)) ) (deffacts fact-23 (Suite (id 100) (rooms 3)) (Single (id 101)) (Double (id 102)) (Double (id 103)) (NextTo (room1 100)(room2 101)) (NextTo (room1 101)(room2 100)) (NextTo (room1 101)(room2 102)) (NextTo (room1 102)(room2 101)) (NextTo (room1 102)(room2 103)) (NextTo (room1 103)(room2 102)) ) (reset) ;;/*** (defrule oneNext Check that a suite has exactly one neighbour. (Suite (id ?rid)) ?sn - (accumulate (bind ?xcount 0) (++ ?xcount) ?xcount (NextTo (room1 ?rid))) (test (= ?sn 1)) = (printout t === Suite ?rid has ?sn neighbours. crlf) ) ;;***/ ;;/*** (defrule maxNext Check that no room is next to three or more. (Room (id ?rid)) ?nc - (accumulate (bind ?count 0) (++ ?count) ?count (NextTo (room1 ?rid))) (test (= ?nc 2)) = (printout t --- ?rid has ?nc neighbours. crlf) ) ;;***/ (run) 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: Another rule that doesn't fire
Perhaps this is of interest: The original code had two rules - the only ones with accumulate - as the fifth and sixth rule between (reset) and (run), and the problem didn't surface until I added number 6. -W Ernest Friedman-Hill wrote: This appears to be an incremental reset bug. The term incremental reset refers to the special processing that has to be done to bring a rule up to date if it's added to an already-populated working memory. Jess expects you to do things the other way around: compile the Rete network by defining all the rules, and then push the data through it; and indeed, if you move your reset to after the rules are defined, they both fire correctly. Thanks for the report; we'll look into this further and get it fixed. On Jun 27, 2007, at 10:34 AM, Wolfgang Laun wrote: In the program below, Jess will only fire the second rule if both are uncommented, but each of them fires if the other one isn't there. If the order of rule definitions is reversed, the second one wins again. Jess Version 7.0p1 Kind regards Wolfgang (clear) (deftemplate Obj (slot id (type STRING)) ) (deftemplate Room extends Obj (slot occupied (type SYMBOL)(default false)) ; Boolean ) (deftemplate Suite extends Room (slot rooms (type INTEGER))) (deftemplate Single extends Room) (deftemplate Double extends Room) (deftemplate NextTo (slot room1 (type STRING)) (slot room2 (type STRING)) ) (deffacts fact-23 (Suite (id 100) (rooms 3)) (Single (id 101)) (Double (id 102)) (Double (id 103)) (NextTo (room1 100)(room2 101)) (NextTo (room1 101)(room2 100)) (NextTo (room1 101)(room2 102)) (NextTo (room1 102)(room2 101)) (NextTo (room1 102)(room2 103)) (NextTo (room1 103)(room2 102)) ) (reset) ;;/*** (defrule oneNext Check that a suite has exactly one neighbour. (Suite (id ?rid)) ?sn - (accumulate (bind ?xcount 0) (++ ?xcount) ?xcount (NextTo (room1 ?rid))) (test (= ?sn 1)) = (printout t === Suite ?rid has ?sn neighbours. crlf) ) ;;***/ ;;/*** (defrule maxNext Check that no room is next to three or more. (Room (id ?rid)) ?nc - (accumulate (bind ?count 0) (++ ?count) ?count (NextTo (room1 ?rid))) (test (= ?nc 2)) = (printout t --- ?rid has ?nc neighbours. crlf) ) ;;***/ (run) 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 owner-jess- [EMAIL PROTECTED] - 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] 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: Weighted facts
Andrei Boutyline wrote: A third approach is to allow multiple instances of the same feature, but have a high-salience rule that sits around and waits for the existence of two instances of the same feature, and then retracts them and restates one feature with a combined weight; my gut feeling is that this is the preferable approach, but necessitates a bit more retraction than the first solution and allows repeat facts which are against the rules of Jess. I'd prefer the third approach, because it neatly separates the tasks of asserting another weight for some feature and the one of accumulating the numbers. Repeat facts can be avoided by adding a slot with a unique value: (assert (weightedfeature (feature ?f) (weight ?w) (mark (gensym* Wolfgang 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: WMEs as slot values
Greetings to everybody on this list. The general idea of this approach is to use WME references as slot values. Retrieval of one fact will then permit efficient access to one or more related facts, via some (constant) slots. I haven't found any hint that this isn't permitted, but in the Jess distribution there wasn't an example demonstrating this either. Anyway, there are situations when doing this appears to fail during pattern matching, but I've also found a working example. - I'm using Jess Version 7.0p1 12/21/2006. The following Jess program uses working memory elements as slot values, and this one doesn't fire the rule crossover, although I think it should. (reset) (deftemplate bridge (slot name (type STRING)) (slot occup (type SYMBOL)) (slot east (type OBJECT)) (slot west (type OBJECT))) (deftemplate side (slot name (type STRING)) (slot bridge (type OBJECT)) (slot occup (type SYMBOL))) (defrule crossover ?e - (side (name ?ename) {occup == FALSE}) ?w - (side (name ?wname) {occup == TRUE}) ?br - (bridge (name ?bname){occup == FALSE} (east $east){east == ?e} (west $west){west == ?w}) = (printout t ?bname ?ename ?wname crlf) ) (bind ?east (assert (side (name East) (occup FALSE (bind ?west (assert (side (name West) (occup TRUE (bind ?gate (assert (bridge (name GoldGate) (occup FALSE) (east ?east) (west ?west (modify ?east (bridge ?gate)) (modify ?west (bridge ?gate)) (facts) (run) Jess (batch aba.clp) f-0 (MAIN::initial-fact) f-1 (MAIN::side (name East) (bridge Fact-3) (occup FALSE)) f-2 (MAIN::side (name West) (bridge Fact-3) (occup TRUE)) f-3 (MAIN::bridge (name GoldGate) (occup FALSE) (east Fact-1) (west Fact-2)) For a total of 4 facts in module MAIN. 0 Not trying to match two side facts in the same rule appears to work, e.g., (defrule x ?e - (side (name ?ename) {occup == FALSE}) ?br - (bridge (name ?bname){occup == FALSE}) = (printout t x: ?bname ?ename crlf) ) fires, but this one (with or without the third LHS term) doesn't: (defrule y ?e - (side (name ?ename) {occup == FALSE}) ?w - (side (name ?wname) {occup == TRUE}) ?br - (bridge (name ?bname){occup == FALSE}) = (printout t y: ?bname ?ename ?wname crlf) ) -- But a similar example works: (reset) (deftemplate person (slot name (type STRING)) (slot father (type OBJECT)) (slot mother (type OBJECT))) (bind ?adam (assert (person (name Adam (bind ?eve(assert (person (name Eve (bind ?cain (assert (person (name Cain) (father ?adam) (mother ?eve (bind ?abel (assert (person (name Abel) (father ?adam) (mother ?eve (bind ?lilith (assert (person (name Lilith) (father ?adam) (mother ?eve (defrule siblings ?p1 - (person (name ?name1) (father ?f1:(neq ?f1 nil)) (mother ?m1:(neq ?m1 nil))) ?p2 - (person (name ?name2:( ?name1 ?name2)) {father == ?f1) {mother == ?m1)) = (printout t ?name1 and ?name2 are siblings. crlf) ) (run) Abel and Lilith are siblings. Cain and Lilith are siblings. Abel and Cain are siblings. 3 TIA for any comments, kind regards Wolfgang 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: breaking loops broken
Jess Version 7.0p1 12/21/2006 Using return to break a (for) or (foreach) is documented behaviour. (It isn't for (while), but perhaps this is just an omission in the documentation.) However: ;; Using return to exit from a loop confuses Jess. ;; Loops won't work any more. A (clear) appears to remove the fault. ;; for + return (for (bind ?i 0) ( ?i 5) (++ ?i) (if (= ?i 3) then (return huhu)) (printout t i= ?i crlf ) ) ;; foreach + return (foreach ?el (create$ 1 5 10 50 100) (if (= ?el 10) then (return huhu)) (printout t el= ?el crlf )) ;; while + return (bind ?i 0) (while (= ?i 3) do (if (= ?i 2) then (return huhu)) (printout t i= ?i crlf ) (++ ?i) ) ;; for instance: Jess (for (bind ?i 0) ( ?i 5) (++ ?i) (if (= ?i 3) then (return huhu)) (printout t i= ?i crlf ) ) i=0 i=1 i=2 huhu Jess (for (bind ?i 0) ( ?i 5) (++ ?i) (if (= ?i 3) then (return huhu)) (printout t i= ?i crlf ) ) huhu Jess (clear) Jess (foreach ?el (create$ 1 5 10 100) (if (= ?el 10) then (return huhu)) (printout t el= ?el crlf ) ) el=1 el=5 huhu Jess (foreach ?el (create$ 1 5 10 100) (if (= ?el 10) then (return huhu)) (printout t el= ?el crlf ) ) huhu Jess (clear) Jess (bind ?i 0) 0 Jess (while (= ?i 3) do (if (= ?i 2) then (return huhu)) (printout t i= ?i crlf ) (++ ?i) ) i=0 i=1 huhu Jess (bind ?i 0) 0 Jess (while (= ?i 3) do (if (= ?i 2) then (return huhu)) (printout t i= ?i crlf ) (++ ?i) ) huhu Jess Kind regards Wolfgang 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: breaking loops broken
16.70 and 16.71 probably shouldn't mention return at all; this was indeed leading me up the garden path. (I was thinking of (for) and (foreach) as some inline function definition plus call, and that's why you can use return to break from them.) Ernest Friedman-Hill wrote: I think you'll find that any of the loops below will work fine in a context where return has a defined meaning: in particular, in a deffunction or the RHS of a defrule. I could weasel out of this by calling this undefined behavior, as returning from a loop at the prompt has no useful meaning -- there's no higher level to return to. But thanks for the report -- return should just be equivalent to break when called in a context like this, so this should be fixed. On Jun 11, 2007, at 3:42 AM, Wolfgang Laun wrote: Jess Version 7.0p1 12/21/2006 Using return to break a (for) or (foreach) is documented behaviour. (It isn't for (while), but perhaps this is just an omission in the documentation.) However: ;; Using return to exit from a loop confuses Jess. ;; Loops won't work any more. A (clear) appears to remove the fault. ;; for + return (for (bind ?i 0) ( ?i 5) (++ ?i) (if (= ?i 3) then (return huhu)) (printout t i= ?i crlf ) ) ;; foreach + return (foreach ?el (create$ 1 5 10 50 100) (if (= ?el 10) then (return huhu)) (printout t el= ?el crlf )) ;; while + return (bind ?i 0) (while (= ?i 3) do (if (= ?i 2) then (return huhu)) (printout t i= ?i crlf ) (++ ?i) ) ;; for instance: Jess (for (bind ?i 0) ( ?i 5) (++ ?i) (if (= ?i 3) then (return huhu)) (printout t i= ?i crlf ) ) i=0 i=1 i=2 huhu Jess (for (bind ?i 0) ( ?i 5) (++ ?i) (if (= ?i 3) then (return huhu)) (printout t i= ?i crlf ) ) huhu Jess (clear) Jess (foreach ?el (create$ 1 5 10 100) (if (= ?el 10) then (return huhu)) (printout t el= ?el crlf ) ) el=1 el=5 huhu Jess (foreach ?el (create$ 1 5 10 100) (if (= ?el 10) then (return huhu)) (printout t el= ?el crlf ) ) huhu Jess (clear) Jess (bind ?i 0) 0 Jess (while (= ?i 3) do (if (= ?i 2) then (return huhu)) (printout t i= ?i crlf ) (++ ?i) ) i=0 i=1 huhu Jess (bind ?i 0) 0 Jess (while (= ?i 3) do (if (= ?i 2) then (return huhu)) (printout t i= ?i crlf ) (++ ?i) ) huhu Jess Kind regards Wolfgang 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 owner-jess- [EMAIL PROTECTED] - 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] 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]