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))))
(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))
(deftemplate mail
(slot content))
(deffacts
mail
(mail (content "AAAxxx"))
(mail (content "BBByyy"))
(mail (content "CCCxxx"))
(mail (content "AAAyyy")))
(mail (content "AAAxxx"))
(mail (content "BBByyy"))
(mail (content "CCCxxx"))
(mail (content "AAAyyy")))
(defquery
find-substring-in-mail
(declare (variables ?substring))
(mail (content ?c))
(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))))
(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)
(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))
(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)
(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 with
content substring = AAA
id content
--- --------
1 AAAxxx
4 AAAyyy
1
Jess>
The mail facts with
content substring = AAA
id content
--- --------
1 AAAxxx
4 AAAyyy
1
Jess>
Hope this
helps!
Cheers,
Jason
------------------------
Jason
Morris
Morris Technical
Solutions
[EMAIL PROTECTED]
www.morristechnicalsolutions.com
fax/phone:
503.692.1088
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of sun xi
Sent: Saturday, June 26, 2004 7:36 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: JESS: query in jessHi, everybodyGiven 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] --------------------------------------------------------------------