Hello,
I am trying to use defquery with 2 parameters as mentioned in the Page 129: Jess in Action. I suppose we can any amount of input parameters. The code has been tweaked as is required from Page 129 for my purpose.
;;Template for the problem type.
;;slot problemtype-category can refer to configuration or information or troubleshooting.
(deftemplate problemtype
(slot problemtype-ident)
(slot problemtype-category)
(slot problemtype-desc)
(slot problemtype-techident)
(slot problemtype-prodident))
;;Insert Records for Problem Types.
(deffacts problemtype
(problemtype (problemtype-ident test1) (problemtype-category configuration)
(problemtype-desc testing1) (problemtype-techident 1) (problemtype-prodident 1)))
(deffacts problemtype
(problemtype (problemtype-ident test2) (problemtype-category troubleshooting)
(problemtype-desc testing2) (problemtype-techident 2) (problemtype-prodident 2)))
;;slot problemtype-category can refer to configuration or information or troubleshooting.
(deftemplate problemtype
(slot problemtype-ident)
(slot problemtype-category)
(slot problemtype-desc)
(slot problemtype-techident)
(slot problemtype-prodident))
;;Insert Records for Problem Types.
(deffacts problemtype
(problemtype (problemtype-ident test1) (problemtype-category configuration)
(problemtype-desc testing1) (problemtype-techident 1) (problemtype-prodident 1)))
(deffacts problemtype
(problemtype (problemtype-ident test2) (problemtype-category troubleshooting)
(problemtype-desc testing2) (problemtype-techident 2) (problemtype-prodident 2)))
;Write the defQuery.
(defquery q_problemtype
(declare (variables ?word ?param))
(problemtype (problemtype-ident ?test) (problemtype-desc ?o&: (= (str-compare ?o ?word) 0)) (problemtype-techident ?o&: (= (str-compare ?o ?param) 0)))
)
;;bind the problem type.
(bind ?w testing2)
(bind ?y 2)
(bind ?w testing2)
(bind ?y 2)
(printout t crlf "Querying for word: " ?w crlf)
(printout t crlf "Querying for word: " ?y crlf)
(printout t "Running query..." crlf)
(bind ?it (run-query q_problemtype ?w ?y))
(printout t "Iterating results..." crlf)
(while (?it hasNext)
(printout t crlf "Matched a fact group:" crlf)
(bind ?token (call ?it next))
(bind ?fact (call ?token fact 1)) ;; get the problemtype-ident fact of the match
(printout t "prod: ")
(printout t "problemtype-ident: " (fact-slot-value ?fact "problemtype-ident")))
(printout t crlf "Done" crlf)
(printout t crlf "Querying for word: " ?y crlf)
(printout t "Running query..." crlf)
(bind ?it (run-query q_problemtype ?w ?y))
(printout t "Iterating results..." crlf)
(while (?it hasNext)
(printout t crlf "Matched a fact group:" crlf)
(bind ?token (call ?it next))
(bind ?fact (call ?token fact 1)) ;; get the problemtype-ident fact of the match
(printout t "prod: ")
(printout t "problemtype-ident: " (fact-slot-value ?fact "problemtype-ident")))
(printout t crlf "Done" crlf)
I don't what is the mistake in the syntax.
Appreciate all your help.
Prasath
Do you Yahoo!?
Yahoo! Photos: High-quality 4x6 digital prints for 25"