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
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 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: 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]
Re: JESS: String to Symbol
I think Roger Studner wrote: (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) Move the reset *after* you define the rule (the normal pattern is to define rules, then add data) and it works fine. This shouldn't matter, but it apparently does. Congratulations, you've found a bug! Thanks for the report. - 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]
JESS: String to Symbol
This might be a simple question but I have not been able to find the solution by myself. I need to assert some ordered facts dynamically and I have to assess the head of the list by concatenating two strings. The Java concat function returns a string value, but the Jess assert function needs its first parameter to be a symbol, so I need to transform the calculated value. How can I convert a string into a symbol? The constructor of the Value class can be used to get a new Value from a String, but I do not know how to transform a Value into a symbol either. Thanks for your help. Regards, Fernando. 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: String to Symbol
I think [EMAIL PROTECTED] wrote: How can I convert a string into a symbol? In Java, String string = whatever; Value symbol = new Value(string, RU.SYMBOL); In Jess, (bind ?string whatever) (bind ?symbol (sym-cat ?string)) - 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: String to Symbol
I am sorry, I should have been more detailed. What I want to do is somethink like this: (bind ?string (call string1 concat string2)) (bind ?symbol (sym-cat ?string)) (assert ?symbol 10) This code does not work because the first argument of the assert function is expected to be a symbol, and not a variable containing a symbol. Is there any way to do that, or the first parameter can not be built dynamically? Thanks a lot. Fernando I think [EMAIL PROTECTED] wrote: How can I convert a string into a symbol? In Java, String string = whatever; Value symbol = new Value(string, RU.SYMBOL); In Jess, (bind ?string whatever) (bind ?symbol (sym-cat ?string)) 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: String to Symbol
How about: (bind ?string (call string1 concat string2)) (bind ?symbol (sym-cat ?string)) (build (str-cat (assert ( ?symbol 10 Henrique --- [EMAIL PROTECTED] wrote: I am sorry, I should have been more detailed. What I want to do is somethink like this: (bind ?string (call string1 concat string2)) (bind ?symbol (sym-cat ?string)) (assert ?symbol 10) This code does not work because the first argument of the assert function is expected to be a symbol, and not a variable containing a symbol. Is there any way to do that, or the first parameter can not be built dynamically? Thanks a lot. Fernando I think [EMAIL PROTECTED] wrote: How can I convert a string into a symbol? In Java, String string = whatever; Value symbol = new Value(string, RU.SYMBOL); In Jess, (bind ?string whatever) (bind ?symbol (sym-cat ?string)) 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]