Re: JESS: Comparing string

2005-09-09 Thread ejfried
Jess doesn't have an explicit else-if feature; if you put an if into
the else of another if, then that second if is a separate
function call, so it needs its own parentheses. 

If I may, I will point out a few other things here: You don't need to
spell out the names of any classes in java.lang, as it's implicitly
imported, just as in Java. Second, you don't actually need to
construct Strings at all; you can call Java String methods on Jess
strings. Third, you can (and should) always omit call when calling a
Java instance method; it's really only needed when you're invoking a
static method. So you could clean your function up like this:

(deffunction compare-comptment-function(?s1 ?s2)
  (if (eq ?s1 ?s2) then
(return FFF)
else (if (?s1 contains ?s2) then
  (printout t COMES 1 crlf)
  (return ?s1)
  else (if (?s2 contains ?s1) then
(printout t COMES 2 crlf)
(return ?s2)
else
  (printout t COMES 3 crlf)
  (return (str-cat ?s1 , ?s2))  

I think Amit Jain wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
 Hi all 
 I'm trying to compare two strings
 
 (deffunction compare-comptment-function(?s1 ?s2)
 (bind ?str-buff1 (new java.lang.String ?s1))
 (bind ?str-buff2 (new java.lang.String ?s2))
 (if (eq ?s1 ?s2) then
 (return FFF)
 else if (call ?str-buff1 contains ?str-buff2) then
 (printout t COMES 1 crlf)
 (return ?s1)
 else if (call ?str-buff2 contains ?str-buff1) then
 (printout t COMES 2 crlf)
 (return ?s2)
 else
 (printout t COMES 3 crlf)
 (return (str-cat ?s1 , ?s2
 
 SO when i call (compare-comptment-function CSEE CS) it should return 
 COMES 1 CSEE
 
 (compare-comptment-function CSE CSEEE) it should return COMES 2 
 CSEEE
 and (compare-comptment-function AE CSE) it should return COMES 3 
 AE,CSE 
 
 but it keeps going into first elseif loop in all the cases. please tell me 
 what i'm doing wrong. thanks for the help.
 -amit



-
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: Comparing string

2005-09-09 Thread Amit Jain
worked like charm. thanks
-amit

On 9/9/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 
 Jess doesn't have an explicit else-if feature; if you put an if into
 the else of another if, then that second if is a separate
 function call, so it needs its own parentheses.
 
 If I may, I will point out a few other things here: You don't need to
 spell out the names of any classes in java.lang, as it's implicitly
 imported, just as in Java. Second, you don't actually need to
 construct Strings at all; you can call Java String methods on Jess
 strings. Third, you can (and should) always omit call when calling a
 Java instance method; it's really only needed when you're invoking a
 static method. So you could clean your function up like this:
 
 (deffunction compare-comptment-function(?s1 ?s2)
 (if (eq ?s1 ?s2) then
 (return FFF)
 else (if (?s1 contains ?s2) then
 (printout t COMES 1 crlf)
 (return ?s1)
 else (if (?s2 contains ?s1) then
 (printout t COMES 2 crlf)
 (return ?s2)
 else
 (printout t COMES 3 crlf)
 (return (str-cat ?s1 , ?s2))
 
 I think Amit Jain wrote:
 [Charset iso-8859-1 unsupported, filtering to ASCII...]
  Hi all
  I'm trying to compare two strings
 
  (deffunction compare-comptment-function(?s1 ?s2)
  (bind ?str-buff1 (new java.lang.String ?s1))
  (bind ?str-buff2 (new java.lang.String ?s2))
  (if (eq ?s1 ?s2) then
  (return FFF)
  else if (call ?str-buff1 contains ?str-buff2) then
  (printout t COMES 1 crlf)
  (return ?s1)
  else if (call ?str-buff2 contains ?str-buff1) then
  (printout t COMES 2 crlf)
  (return ?s2)
  else
  (printout t COMES 3 crlf)
  (return (str-cat ?s1 , ?s2
 
  SO when i call (compare-comptment-function CSEE CS) it should return
  COMES 1 CSEE
 
  (compare-comptment-function CSE CSEEE) it should return COMES 2
  CSEEE
  and (compare-comptment-function AE CSE) it should return COMES 3
  AE,CSE
 
  but it keeps going into first elseif loop in all the cases. please tell 
 me
  what i'm doing wrong. thanks for the help.
  -amit
 
 
 
 -
 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: Pattern Binding for CE

2005-09-09 Thread ejfried
I think Krasnigor, Scott L (N-AST) wrote:

 I have an ID slot defined for the Bean object used to define the facts
 but can't seem to figure out how to get the fact that triggered the rule
 so I can modify it for this particular case (all my other rules allow
 pattern binding). 

I formatted your rule to make it easier to understand.

(defrule doctrine-untripped
;; sets qualDoctrine to FALSE if any check flags are FALSE
?docFact - (or
(and (testTrkClass (qualRng FALSE))
 (testTrkClass (qualDoctrine ~FALSE)))

(and (testTrkClass (qualBrg FALSE))
 (testTrkClass (qualDoctrine ~FALSE
=
(modify  ?docFact (qualDoctrine FALSE)))

So the or has two branches, each of which is an and. Those ands,
in turn, each match two facts (the two could, in fact, be the same
one, or they could be different.)

Based on your comment, and on your problem description, my guess is
that you didn't realize that, and you intend the and to simply group
together multiple tests on the same fact. It doesn't work that way:
you should write all the tests for a single fact in a single pattern,
or else the rule can match bits and pieces from multiple facts. So
really I think you mean

(defrule doctrine-untripped
;; sets qualDoctrine to FALSE if any check flags are FALSE
?docFact - (or
(testTrkClass (qualRng FALSE) (qualDoctrine ~FALSE))
(testTrkClass (qualBrg FALSE) (qualDoctrine ~FALSE))
=
(modify  ?docFact (qualDoctrine FALSE)))

Because each branch of the or matches a single branch, the pattern
binding is OK.



-
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]