RE: JESS: dealing with shadow facts having null properties
Well, I'm really sorry...JFL > From: [EMAIL PROTECTED]> Subject: Re: JESS: dealing with shadow facts having > null properties> Date: Fri, 3 Aug 2007 15:23:03 -0400> To: > jess-users@sandia.gov> > Look closely at your stack trace: it says "Message: > Called method > threw an exception." If you called getCause() on the > JessException, > it would return a NullPointerException, and if you looked at > that > NPE's stack trace, you'd see it was thrown by the getA() method of > > your Test class. Here are the relevant lines from your code:> > private > Integer a = null;> ...> public int getA() {> return a;> }> > Note that the > type of variable "a" is Integer, but getA() is > returning an int. That means > that, due to auto-unboxing, the Java > compiler is going to emit code as if > you had written something like> > public int getA() {> return a.intValue();> > }> > > and since "a" is null, this line throws a NullPointerException. It's > > not Jess's fault if your getter methods throw NPEs when called!> > > > > > On > Aug 3, 2007, at 2:51 PM, Skeptic 2000 wrote:> > >> > Hi and thanks a lot for > helping, the details are here :> >> > That's the ShadowFact :> >> > public > class Test {> >> >> >> >> > private Integer a = null;> >> > private Integer b > = 4;> >> >> >> >> > public Test() {> >> >> >> > }> >> >> >> >> > public int > getA() {> >> > return a;> >> > }> >> >> >> >> > public int getB() {> >> > > return b;> >> > }> >> >> > }> >> > That's the .CLP file :> >> > (defclass > Test xxx.yyy.zzz.Test)> >> >> > (defrule testrule> >> > (Test (a ?a) (b ?b))> > >> > =>> >> > (printout t "testrule ok")> >> > )> >> > That's the java code > :> >> > void functionX() {> > ...> > jessEngine.add(new Test());> > ...> > }> > >> > That's the exception :> >> > Jess reported an error in routine > DefinstanceList.updateMultipleSlots.> >> > Message: Called method threw an > exception.> >> > at > jess.DefinstanceList.getSlotValueFromObject(DefinstanceList.java: > > 371)> > >> > at jess.DefinstanceList.setAllSlotValuesFromObject > > > (DefinstanceList.java:353)> >> > at > jess.DefinstanceList.createNewShadowFact(DefinstanceList.java:332)> >> > at > jess.DefinstanceList.definstance(DefinstanceList.java:111)> >> > at > jess.Rete.definstance(Rete.java:1903)> >> > at > jess.Rete.definstance(Rete.java:1883)> >> > at jess.Rete.add(Rete.java:2023)> > > ...> >> >> > JFL> >> >> >> >> >> > > From: [EMAIL PROTECTED]> > > Subject: > Re: JESS: dealing with shadow facts having null properties> > > Date: Fri, 3 > Aug 2007 10:48:15 -0400> > > To: jess-users@sandia.gov> > >> > > I can't > reproduce anything like this; can you show me a stack trace> > > (run > jess.Main with -stacktrace to see a full error trace).> > >> > > On Aug 2, > 2007, at 6:12 PM, Skeptic 2000 wrote:> > >> > > >> > > > When I add a shadow > fact with a property having a null value, I > > get> > > > an exception (in > updateMultiSlot IRRC).> > > >> > > > JFL> > > >> > > > > From: [EMAIL > PROTECTED]> > > > > Subject: Re: JESS: dealing with shadow facts having null > > > properties> > > > > Date: Thu, 2 Aug 2007 15:57:55 -0400> > > > > To: > jess-users@sandia.gov> > > > >> > > > > Jess has been able to handle null > properties for a long time; > > 6.1p8> > > > > can handle them, as can the > current versions. What problem > > are you> > > > > having, exactly?> > > > > >> > > > > On Aug 2, 2007, at 2:19 PM, Skeptic 2000 wrote:> > > > >> > > > > > >> > > > > > Hi,> > > > > >> > > > > > I need to add in the working memory > some shadow facts with> > > > > > properties whose values are null. > Currently, my workaround > > is to> > > > > > use a "NullObject" to prevent > Jess from crashing upon > > finding a> > > > > > null value.> > > > > >> > > > > > > Is it the recommended way to do it ?> > > > > >> > > > > > JFL> > > > > > >> > > > > > Soyez parmi les premiers à essayer Windows Live Mail.> > > > >> > > > > > -> > > > > > Ernest Friedman-Hill> > > > > Advanced Software Research Phone: (925) > 294-2154> > > > > Sandia National Labs FAX: (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 > owner-jess-> > > > [EMAIL PROTECTED]> > > > > > > > > > > > > >> > > >> > > >> > > > Soyez parmi les premiers à essayer Windows Live Mail.> > > >> > > -> > > > Ernest Friedman-Hill> > > Advanced Software Research Phone: (925) 294-2154> > > > Sandia National Labs FAX: (925) 2
Re: JESS: dealing with shadow facts having null properties
Look closely at your stack trace: it says "Message: Called method threw an exception." If you called getCause() on the JessException, it would return a NullPointerException, and if you looked at that NPE's stack trace, you'd see it was thrown by the getA() method of your Test class. Here are the relevant lines from your code: private Integer a = null; ... public int getA() { return a; } Note that the type of variable "a" is Integer, but getA() is returning an int. That means that, due to auto-unboxing, the Java compiler is going to emit code as if you had written something like public int getA() { return a.intValue(); } and since "a" is null, this line throws a NullPointerException. It's not Jess's fault if your getter methods throw NPEs when called! On Aug 3, 2007, at 2:51 PM, Skeptic 2000 wrote: Hi and thanks a lot for helping, the details are here : That's the ShadowFact : public class Test { private Integer a = null; private Integer b = 4; public Test() { } public int getA() { return a; } public int getB() { return b; } } That's the .CLP file : (defclass Test xxx.yyy.zzz.Test) (defrule testrule (Test (a ?a) (b ?b)) => (printout t "testrule ok") ) That's the java code : void functionX() { ... jessEngine.add(new Test()); ... } That's the exception : Jess reported an error in routine DefinstanceList.updateMultipleSlots. Message: Called method threw an exception. at jess.DefinstanceList.getSlotValueFromObject(DefinstanceList.java: 371) at jess.DefinstanceList.setAllSlotValuesFromObject (DefinstanceList.java:353) at jess.DefinstanceList.createNewShadowFact(DefinstanceList.java:332) at jess.DefinstanceList.definstance(DefinstanceList.java:111) at jess.Rete.definstance(Rete.java:1903) at jess.Rete.definstance(Rete.java:1883) at jess.Rete.add(Rete.java:2023) ... JFL > From: [EMAIL PROTECTED] > Subject: Re: JESS: dealing with shadow facts having null properties > Date: Fri, 3 Aug 2007 10:48:15 -0400 > To: jess-users@sandia.gov > > I can't reproduce anything like this; can you show me a stack trace > (run jess.Main with -stacktrace to see a full error trace). > > On Aug 2, 2007, at 6:12 PM, Skeptic 2000 wrote: > > > > > When I add a shadow fact with a property having a null value, I get > > an exception (in updateMultiSlot IRRC). > > > > JFL > > > > > From: [EMAIL PROTECTED] > > > Subject: Re: JESS: dealing with shadow facts having null properties > > > Date: Thu, 2 Aug 2007 15:57:55 -0400 > > > To: jess-users@sandia.gov > > > > > > Jess has been able to handle null properties for a long time; 6.1p8 > > > can handle them, as can the current versions. What problem are you > > > having, exactly? > > > > > > On Aug 2, 2007, at 2:19 PM, Skeptic 2000 wrote: > > > > > > > > > > > Hi, > > > > > > > > I need to add in the working memory some shadow facts with > > > > properties whose values are null. Currently, my workaround is to > > > > use a "NullObject" to prevent Jess from crashing upon finding a > > > > null value. > > > > > > > > Is it the recommended way to do it ? > > > > > > > > JFL > > > > > > > > Soyez parmi les premiers à essayer Windows Live Mail. > > > > > > - > > > Ernest Friedman-Hill > > > Advanced Software Research Phone: (925) 294-2154 > > > Sandia National Labs FAX: (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 owner-jess- > > [EMAIL PROTECTED] > > > > > > > > > > > > Soyez parmi les premiers à essayer Windows Live Mail. > > - > Ernest Friedman-Hill > Advanced Software Research Phone: (925) 294-2154 > Sandia National Labs FAX: (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 owner-jess- [EMAIL PROTECTED] > > Soyez parmi les premiers à essayer Windows Live Mail. - 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 -
RE: JESS: dealing with shadow facts having null properties
Hi and thanks a lot for helping, the details are here : That's the ShadowFact : public class Test { private Integer a = null; private Integer b = 4; public Test() { } public int getA() { return a; } public int getB() { return b; } } That's the .CLP file : (defclass Test xxx.yyy.zzz.Test) (defrule testrule (Test (a ?a) (b ?b)) => (printout t "testrule ok") ) That's the java code : void functionX() { ... jessEngine.add(new Test()); ... } That's the exception : Jess reported an error in routine DefinstanceList.updateMultipleSlots. Message: Called method threw an exception. at jess.DefinstanceList.getSlotValueFromObject(DefinstanceList.java:371) at jess.DefinstanceList.setAllSlotValuesFromObject(DefinstanceList.java:353) at jess.DefinstanceList.createNewShadowFact(DefinstanceList.java:332) at jess.DefinstanceList.definstance(DefinstanceList.java:111) at jess.Rete.definstance(Rete.java:1903) at jess.Rete.definstance(Rete.java:1883) at jess.Rete.add(Rete.java:2023) ... JFL > From: [EMAIL PROTECTED]> Subject: Re: JESS: dealing with shadow facts having > null properties> Date: Fri, 3 Aug 2007 10:48:15 -0400> To: > jess-users@sandia.gov> > I can't reproduce anything like this; can you show > me a stack trace > (run jess.Main with -stacktrace to see a full error > trace).> > On Aug 2, 2007, at 6:12 PM, Skeptic 2000 wrote:> > >> > When I add > a shadow fact with a property having a null value, I get > > an exception (in > updateMultiSlot IRRC).> >> > JFL> >> > > From: [EMAIL PROTECTED]> > > > Subject: Re: JESS: dealing with shadow facts having null properties> > > > Date: Thu, 2 Aug 2007 15:57:55 -0400> > > To: jess-users@sandia.gov> > >> > > > Jess has been able to handle null properties for a long time; 6.1p8> > > can > handle them, as can the current versions. What problem are you> > > having, > exactly?> > >> > > On Aug 2, 2007, at 2:19 PM, Skeptic 2000 wrote:> > >> > > > >> > > > Hi,> > > >> > > > I need to add in the working memory some shadow > facts with> > > > properties whose values are null. Currently, my workaround > is to> > > > use a "NullObject" to prevent Jess from crashing upon finding a> > > > > null value.> > > >> > > > Is it the recommended way to do it ?> > > >> > > > > JFL> > > >> > > > Soyez parmi les premiers à essayer Windows Live > Mail.> > >> > > -> > > > Ernest Friedman-Hill> > > Advanced Software Research Phone: (925) 294-2154> > > > Sandia National Labs FAX: (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 owner-jess- > > [EMAIL PROTECTED]> > > > > > >> > >> >> > Soyez parmi les premiers à essayer Windows Live Mail.> > > -> Ernest > Friedman-Hill> Advanced Software Research Phone: (925) 294-2154> Sandia > National Labs FAX: (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]> > > _ Soyez parmi les premiers à essayer Windows Live Mail. http://ideas.live.com/programpage.aspx?versionId=5d21c51a-b161-4314-9b0e-4911fb2b2e6d
Re: JESS: dealing with shadow facts having null properties
I can't reproduce anything like this; can you show me a stack trace (run jess.Main with -stacktrace to see a full error trace). On Aug 2, 2007, at 6:12 PM, Skeptic 2000 wrote: When I add a shadow fact with a property having a null value, I get an exception (in updateMultiSlot IRRC). JFL > From: [EMAIL PROTECTED] > Subject: Re: JESS: dealing with shadow facts having null properties > Date: Thu, 2 Aug 2007 15:57:55 -0400 > To: jess-users@sandia.gov > > Jess has been able to handle null properties for a long time; 6.1p8 > can handle them, as can the current versions. What problem are you > having, exactly? > > On Aug 2, 2007, at 2:19 PM, Skeptic 2000 wrote: > > > > > Hi, > > > > I need to add in the working memory some shadow facts with > > properties whose values are null. Currently, my workaround is to > > use a "NullObject" to prevent Jess from crashing upon finding a > > null value. > > > > Is it the recommended way to do it ? > > > > JFL > > > > Soyez parmi les premiers à essayer Windows Live Mail. > > - > Ernest Friedman-Hill > Advanced Software Research Phone: (925) 294-2154 > Sandia National Labs FAX: (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 owner-jess- [EMAIL PROTECTED] > > Soyez parmi les premiers à essayer Windows Live Mail. - 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]
Re: JESS: query distinct values of a slot
Instead of imnmediately printing the results below, add them to a java.util.List, and sort the list; then you can print them in order. So, for example (import java.util.*) (deffunction print-unique-first-names () "print unique first names from person facts" (bind ?results (run-query* unique-first-name)) (bind ?list (new ArrayList)) (while (?results next) (?list add (?results get firstName)) (?results close) (call Collections sort ?list) (printout t (?list toString) crlf)) Or you could loop over ?list and print each item however you want. On Aug 3, 2007, at 6:00 AM, Joaquín Cañadas wrote: Thank you Bob for your quick and useful answer! It was simpler than I was trying (without success). I have another related question, I hope not to abuse ;). How can we modify the print function for printing names sorted alphabetically? In the Jess in Action book an example rule called sort-and-print does something similar, but retracting printed facts. It would be possible to sort without retracting facts? Thank you ! Joaquín Robert Kirby escribió: As a Jess 7.0p1 query: (defquery unique-first-name "A query for unique first names among person facts" ?person <- (person (firstName ?firstName)) (not (and ?earlier-person <- (person (firstName ?firstName)) (test (< ?earlier-person ?person) (deffunction print-unique-first-names () "print unique first names from person facts" (bind ?results (run-query* unique-first-name)) (while (?results next) (printout t (?results get firstName) crlf)) (?results close)) where the query body could also be used in the LHS of a rule. The idiom is to use only the fact with the smallest ID for each match in Jess. Projections like this are how SQL queries are defined, without needing an exclusion. Bob Kirby At 04:47 PM 8/2/2007, 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 - 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]
Re: JESS: query distinct values of a slot
Thank you Bob for your quick and useful answer! It was simpler than I was trying (without success). I have another related question, I hope not to abuse ;). How can we modify the print function for printing names sorted alphabetically? In the Jess in Action book an example rule called sort-and-print does something similar, but retracting printed facts. It would be possible to sort without retracting facts? Thank you ! Joaquín Robert Kirby escribió: As a Jess 7.0p1 query: (defquery unique-first-name "A query for unique first names among person facts" ?person <- (person (firstName ?firstName)) (not (and ?earlier-person <- (person (firstName ?firstName)) (test (< ?earlier-person ?person) (deffunction print-unique-first-names () "print unique first names from person facts" (bind ?results (run-query* unique-first-name)) (while (?results next) (printout t (?results get firstName) crlf)) (?results close)) where the query body could also be used in the LHS of a rule. The idiom is to use only the fact with the smallest ID for each match in Jess. Projections like this are how SQL queries are defined, without needing an exclusion. Bob Kirby At 04:47 PM 8/2/2007, 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
Re: JESS: query distinct values of a slot
As a Jess 7.0p1 query: (defquery unique-first-name "A query for unique first names among person facts" ?person <- (person (firstName ?firstName)) (not (and ?earlier-person <- (person (firstName ?firstName)) (test (< ?earlier-person ?person) (deffunction print-unique-first-names () "print unique first names from person facts" (bind ?results (run-query* unique-first-name)) (while (?results next) (printout t (?results get firstName) crlf)) (?results close)) where the query body could also be used in the LHS of a rule. The idiom is to use only the fact with the smallest ID for each match in Jess. Projections like this are how SQL queries are defined, without needing an exclusion. Bob Kirby At 04:47 PM 8/2/2007, 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
RE: JESS: Redefining extended deftemplates
Thanks for that Wolfgang. Actually we do already have a workaround - somewhat similar to what you describe below. However I just wanted to point out what is happening in the jess code in the m_deftemplates TreeMap when you redefine an extended deftemplate. Regards, - Howard -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Wolfgang Laun Sent: Thursday, August 02, 2007 9:58 AM To: jess-users@sandia.gov Subject: Re: JESS: Redefining extended deftemplates Maybe this is a workaround: Assuming that the rules file you reload contains all deftemplates referenced by these rules (or, in other words, if this rules file can be batched into a virgin rete engine), then you could batch the file with the updated rules into an auxiliary Rete, iterate over all rules in the auxiliary and add them to the working Rete. Below is a Userfunction (load-rules ) doing just that. kr Wolfgang package at.laune.jess; import java.util.Iterator; import jess.Context; import jess.HasLHS; import jess.JessException; import jess.Rete; import jess.RU; import jess.Userfunction; import jess.Value; import jess.ValueVector; /** * A Jess Userfunction class (re-)loading rules from a Jess file. * * (load-rules ) * * @author Wolfgang Laun */ public class LoadRules implements Userfunction { private static final String NAME = "load-rules"; /** Get the name of the Jess function. * @see jess.Userfunction#getName() */ public String getName(){ return NAME; } /** Call the userfunction * @see jess.Userfunction#call(jess.ValueVector, jess.Context) */ public Value call( ValueVector vv, Context context ) throws JessException { int narg = vv.size() - 1; // Check that we have no element. if( narg != 1 ) throw new JessException( NAME, "missing argument:", "pathname"); Rete theRete = context.getEngine(); String path = vv.get( 1 ).stringValue( context ); Rete aux = new Rete(); aux.batch( path ); // Iterate over all rules and queries. int nRules = 0; Iterator ruleIt = aux.listDefrules(); while( ruleIt.hasNext() ){ HasLHS rq = (HasLHS)ruleIt.next(); theRete.addDefrule( rq ); nRules++; } return new Value( nRules , RU.INTEGER ); } } Greenblatt, Howard wrote: >Hi there, > > > >In our system we sometimes need to reload a rules file that may >contain deftemplates. This could happen for example if a rule changes >and needs to be redefined in the system. We reload the rules file with >the updated rule. Since deftemplates cannot be redefined (without >clearing out the rules engine first), we don't allow them to be >modified; however they still may be in the file. > > > >I have seen the jess src code (jess70p1 - Deftemplate.java - line 155 >"equals" method) where you check to see if a new deftemplate object >matches an existing one of the same name. If they are identical there >is no error. This works fine except where the deftemplate extends >another deftemplate. It appears that the parent id of the extended >deftemplate is different even though the parent template is identical. > > > > >This error can be duplicated in a single script. Consider the >following: > > > >(deftemplate t1 > > (slot s1)) > > > >(deftemplate t2 extends t1 > > (slot s2)) > > > >; > >; redefining t1 is no problem > >; > >(deftemplate t1 > > (slot s1)) > > > >; > >; redefining t2 causes an error where you cannot redefine > >; the template even though it is exactly the same. > >; > >(deftemplate t2 extends t1 > > (slot s2)) > > > > > >I believe what is happening is that when t1 is redefined and added to >the m_deftemplates TreeMap (Defmodule,java - line 125 "addDeftemplate" >method) it is assigned a new id which does not match the id of t1 (as >a parent) when template t2 is redefined. > > > >Thanks, > > > >- Howard > > > > 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: 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]