RE: JESS: query in jess

2004-06-27 Thread Jason Morris



Hi 
Alvin,
Leave it to Dr. Friedman-Hill 
to quickly point out the simplest solution! :-D  I was going to 
suggest that a defquery might also be a solution since it 
can easily handle more general filtering.  For 
example:
 
(defquery 
find-substring-in-mail  (declare (variables ?substring))  
(mail (content ?c))  (test (not (eq (str-index ?substring ?c) 
FALSE
 
Now, a 
simple test program (I called it a.clp) could then look 
like:
 
(clear)(deftemplate mail  (slot 
content))
 
(deffacts 
mail(mail (content "AAAxxx"))(mail (content "BBByyy"))(mail (content 
"CCCxxx"))(mail (content "AAAyyy")))
 
(defquery 
find-substring-in-mail  (declare (variables ?substring))  
(mail (content ?c))
  ;; Here you use a test fact to filter 
the mail facts
  ;; by 
seeing if the substring is present in the content.  (test (not (eq 
(str-index ?substring ?c) FALSE
 
(defrule 
print-all-AAAs=>
;; Rather 
than hard-coding the AAA, you could have
;; some 
interactive input from the user.(bind ?itt (run-query find-substring-in-mail 
"AAA"))(printout t "The mail facts with " crlf)(printout t "content 
substring = AAA" crlf)
(printout t 
"id    content" crlf)(printout t "---   " 
crlf)(while (?itt hasNext)  (bind ?token (call ?itt 
next))  (bind ?fact (call ?token fact 1))
  ;; 
This is just here to remind you that you can call
  ;; 
any public methods of Java objects from Jess script.  (bind ?id 
(call ?fact getFactId))  (printout t ?id " " 
(fact-slot-value ?fact content) crlf)))  
(reset)(run)
 
The output 
is:
 
Jess> 
(batch a.clp)The mail facts withcontent substring = 
AAAid    content---   
1 AAAxxx4 
AAAyyy1Jess>
 
Hope this 
helps!
Cheers,
 
Jason

Jason 
MorrisMorris Technical 
Solutions[EMAIL PROTECTED]www.morristechnicalsolutions.comfax/phone: 
503.692.1088 
 

  -Original Message-From: [EMAIL PROTECTED] 
  [mailto:[EMAIL PROTECTED]On Behalf Of sun xiSent: 
  Saturday, June 26, 2004 7:36 PMTo: [EMAIL PROTECTED]; 
  [EMAIL PROTECTED]Subject: JESS: query in 
  jess
  
  Hi, everybody
   
  Given a set of facts:
  (mail (content "AAAxxx"))
  (mail (content "BBByyy"))
  (mail (content "CCCxxx"))
  (mail (content "AAAyyy"))
   
  Can somebody guide me how to find the mails whose 
  content begin with "AAA" ?
   
  Appreciate all your replies :)Thanks,Alvin 
  Swen
  
  [EMAIL PROTECTED]<~O5M3!* MSN Hotmail 
   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 in jess

2004-06-27 Thread ejfried
I think sun xi wrote:
> Hi, everybody
> Given a set of facts:
> (mail (content "AAAxxx"))
> (mail (content "BBByyy"))
> (mail (content "CCCxxx"))
> (mail (content "AAAyyy"))
> 
> Can somebody guide me how to find the mails whose content begin with "AAA" ?

A pattern to do this could just look like

  (mail (content ?c&:(?c startsWith AAA)))

Here I'm calling the java.lang.String function "startsWith" to do the
work. You could use this pattern either in a rule or in a query.



-
Ernest Friedman-Hill  
Science and Engineering PSEsPhone: (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]