Re: JESS: Finding fact the max/min slot value
(defrule biggest-number (number ?number) (not (number ?num2 ?num)) = (printout t biggest number: ) (printout t ?number crlf) ) I think? On 2/1/06, erich.oliphant [EMAIL PROTECTED] wrote: Hi, I am trying to figure out the best way to have a rule fire only for a fact whose slot value is the min or max of a group of facts. For example: (deftemplate number (slot value)) (assert number (value 1)) (assert number (value 2)) (assert number (value 3)) (assert number (value 4)) (defrule biggest-number (number (value ?val)) = ) I only want biggest-number to fire for (number (value 4)). Is a defquery better here? 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: Goal in each action
To jump in.. I suggest that everyone buys that book if they are going to use Jess. It *does* repeat some material available in the online docs and other places, but also includes quite a good bit more code and examples than I found anywhere else. Roger Studner On 1/26/06, Daniela CLARO [EMAIL PROTECTED] wrote: Hi James, Thank you very much for your deeply answer. I have some comments to add..
JESS: Accumulate Function - LHS
Are there situations or usages of (accumulate) that would actually prevent a rule from firing? ?c - (accumulate (bind ?count 0) ;; initializer (bind ?count (+ ?count 1)) ;; action ?count (pattern to look for.. single fact, not even complex) ) If there are *no matches* to this pattern, should it always fire and have ?c bound to zero? Thanks, Roger
Re: JESS: creating an audit trail
Both suggestions are equally useful.. thanks.. I'll check in the API for registering a listener with the jess engine (is it for the whole engine, or by rule?) As well, i'm already using log4j in my java wrapper classes I make use of Engine's in.. so I will just STORE a logger and use it to track various 'inferred' pieces of information. Thanks both of you for your help Roger S On 12/1/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I think Roger Studner wrote: Has anyone has success in industry with a pattern or methodology for tracking which rules fires and for what facts through a set of rules? Not sure what you mean by a pattern or methodology, but... I have thought of listeners on firings That's all you have to do; DEFRULE_FIRED events contain the actual Activation object, which gives you the Defrule and all the Fact objects that matched. You'll get the events in the order the rules fire. You can then log all the info you want. Is there something more that you need beyond that? - 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://herzberg.ca.sandia.gov To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED]
Re: JESS: Size of an activation record
And even an addendum to this question: Is there (I read something 'akin' to this in the mailing archive) a big performance hit as well? I like to use beans/shadow facts for a variety of reasons, but have always been under the impression that when i'm going to assert a 'huge' number of a particular fact type, that I should be using a deftemplate/fact API versus just using defclass/definstance of a bean representing the exact same information. Thanks, Roger On 11/22/05, Scott Moss [EMAIL PROTECTED] wrote: It would be useful to me to extend this discussion a little-- specifically to the memory requirements of facts and shadow facts. Is there any way of know whether a shadow fact relating to a Java object with (say) all fields having getter and setter methods (the latter having property change support) uses more or less memory than a Fact with the same number and types of slots? The question is about relative rather than absolute memory usage. thanks. [EMAIL PROTECTED] wrote: I think Kristina Marasovic wrote: [Charset iso-8859-1 unsupported, filtering to ASCII...] Hi, can someone tell me if it is possible (and how) to get or to measure the size of an activation record. You don't really know the size of *any* Java object, as the details of object representation are implementation-dependent. Furthermore, it's rather tricky to determine the size of an object when that object is part of a dense interconnected web of objects like Jess's Rete network. That said, in the current implementation, an Activation object has 4 members, which at 4 bytes each is 16 bytes. Along with the generally-assumed Java memory overhead per object of 16 bytes, that means each Activation is 32 bytes. If you have 756,000 of them, that's 24 MB. If you include the 4 byte array element that holds each Activation, then that adds another 3 MB. Now, each Activation record has a reference to a Defrule (which would exist anyway) and a Token in the Rete network. If you want to start including those Tokens in the memory count, then it becomes very complicated very quickly, as many, many Tokens are shared, and also Token is a recursive data structure -- a Token usually contains a reference to another parent token. The depth of the recursion and the amount of sharing is entirely dependent on the nature of your rules. - 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://herzberg.ca.sandia.gov To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED] . -- Professor Scott Moss Director Centre for Policy Modelling Manchester Metropolitan University Aytoun Building Manchester M1 3GH http://cfpm.org/~scott (t) +44 (0)161 247 3886 (f) +44 (0)161 247 6802 (m) +44 (0)7740 942564 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: Object to built-in type
You can use instance of, do a cast, and then contruct the right Value (or LongValue in the case of a Long/long) and then set a slot with that value. Source code examples help, so here ya go: public static void insertFactFromTemplateNameAndSlotValueMap(Rete engine, Deftemplate t, String slot, Object value, boolean asSymbol) throws Exception { Value v = null; if (value instanceof Long) { long l = ((Long) value).longValue(); if (asSymbol) { v = new Value(l, RU.SYMBOL); } else { v = new LongValue(l); } } else if (value instanceof Integer) { int i = ((Integer) value).intValue(); if (asSymbol) { v = new Value(i, RU.SYMBOL); } else { v = new Value(((Integer) value).intValue(), RU.LONG); } } else if (value instanceof String) { String s = ((String) value).toString(); if (asSymbol) { v = new Value(s, RU.SYMBOL); } else { v = new Value(s, RU.STRING); } } Fact factToInsert = new Fact(t); factToInsert.setSlotValue(slot, v); engine.assertFact(factToInsert); } On 11/18/05, Yura [EMAIL PROTECTED] wrote: Hi jess-users Is there any way to convert Java object to one of the predefined Jess types (e.g. I need to convert Object which is actually Integer to RU.INTEGER). Yuri
Re: JESS: Accessing the Java object behind a shadow fact in a userfunction
Get from the slot OBJECT. something like (bind ?obj (fact-slot-value ?fact OBJECT)) I could be wrong :) On 11/14/05, erich.oliphant [EMAIL PROTECTED] wrote: Hi, I am implementing a convienenice userfunction that takes a bound shadow fact as an argument and returns some of it's deeply nested data. The argument to the userfunction is of course a jess.Fact. I can't quite figure out how to get a reference to the underlying Java object from the docs. I see the methods that flag shadow facts but nothing to get at the actual object. Any help would get greatly appreciated. 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]
JESS: defquery
I am trying to do some 'counting'. I make a defquery to return a fact. I get back the Iterator.. i retreive the token.. I get the fact. When I try to modify the fact.. I get an error that 'the fact is not in working memory'. I mean, I even asserted the fact before using it. I just don't want to match on it on the LHS for obvious reasons (circular firing). Thanks, Roger S
Re: JESS: String to Symbol
Fun one with Accumulate: (deftemplate encounter (slot date) (slot code)) (reset) (assert (encounter (date 2005-10-31) (code 440))) (assert (encounter (date 2005-10-31) (code 440))) (assert (encounter (date 2005-10-31) (code 777.1))) (assert (encounter (date 2005-10-31) (code 468.1))) (assert (encounter (date 2005-10-31) (code 440))) (assert (encounter (date 2005-10-31) (code 777.1))) (assert (encounter (date 2005-10-31) (code 777.1))) (assert (encounter (date 2005-10-31) (code 468.1))) (assert (encounter (date 2005-10-31) (code 440))) (assert (encounter (date 2005-10-31) (code 440))) (defrule count-icd9-codes ?c - (accumulate (bind ?count 0) ;; initializer (bind ?count (+ ?count 1)) ;; action ?count ;; result (encounter (code ?c : (eq ?c 440))) ) = (printout t There are ) (printout t ?c) (printout t encounter. for ICD9 code: ) ) (facts) (run) This (and anything in the accumlates match area) *always* returns 0 as the count variable. I took the example (modified) from the 7.0 'new features' area of the docs. I tried just (encounter) to match on *any* encounter, and I always get 0. Any hints? Roger
Re: JESS: String to Symbol
Thanks so much! I wanted to say.. that what made me think something was 'amiss'.. is that the accumulate example from the web page: (deftemplate employee (slot salary)) (deffacts employee-facts (employee (salary 1007700)) (employee (salary 1002347700)) (employee (salary 107712000)) ) (watch all) (reset) (defrule count-highly-paid-employees ?c - (accumulate (bind ?count 0) ;; initializer (bind ?count (+ ?count 1)) ;; action ?count ;; result (employee (salary ?s:( ?s 10 ;; CE = (printout t ?c employees make more than $10/year. crlf)) (run) This (that uses ?c and ?s) also prints 0 every time. Thanks again and again, Roger S. On 11/8/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I think Roger Studner wrote: (defrule count-icd9-codes ?c - (accumulate (bind ?count 0) ;; initializer (bind ?count (+ ?count 1)) ;; action ?count ;; result (encounter (code ?c : (eq ?c 440))) ) ... This (and anything in the accumlates match area) *always* returns 0 as the count variable. I took the example (modified) from the 7.0 'new features' area of the docs. You've used the same variable ?c to mean two totally different things in the same pattern: you're binding the result of the accumulate to it, but you're also binding the contents of the code slot to it. This is tricky enough that even I would have to trace through with a debugger to see what will happen -- but I can guarantee you that it won't be the answer you're expecting! Finally, note that there's no reason to write patterns like this (encounter (code ?c : (eq ?c 440))) when the following is equivalent but simpler, clearer, *and* more efficient: (encounter (code 440)) Conveniently, making this change will also fix the problem outlined above! - 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://herzberg.ca.sandia.gov To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED]