Title: Re: JESS: Default conversion of boolean values

       
I see said the blind man. With your note, and a bit more experimentation, I see that the Iterator returned by defquery returns a list of jess.Fact, not fact-ids.

So here's the lastest (and successful attempt) in getting values from a multislot


(clear)
(deftemplate illness "Name of illness and symptoms for it"
  (slot name)
  (multislot symptoms))

; collect all symptoms in a list
(defquery get-all-symptoms
  (illness (symptoms $?)) )

(deffacts list-of-illnesses
(illness (name Flu) (symptoms "Runny Nose"  "Sore Throat")) )

(reset)

(facts)

(defrule test
  ?fact-id <- (illness (name Flu) )   ; this gives you a fact-id
  => (bind ?symptom-list (fact-slot-value ?fact-id symptoms) ) ; get multilist via fact-id
     (printout t "Fact-id = " ?fact-id crlf)
     (printout t "From defrule test - 1st element of list " (nth$ 1 ?symptom-list) crlf crlf)  )
   

(deffunction get-symptom-list ()
 "Run query to get all symptoms concatenated to one list"
  (printout t "start of get-symptom-list" crlf)
  (bind ?it (run-query get-all-symptoms)) ; ?it contains java.util.Iterator
  (while (?it hasNext)     ; use Iterator.hasNext() method to see if more results
    (bind ?token (call ?it next))  ; call Iterator.next() to get jess.Token (which
                                   ; contains a jess.Fact
    (bind ?jess-fact (?token fact 1))  ; so get the jess.Fact, NOT the fact-id
    (bind ?fact-id (fact-id (?jess-fact getFactId))) ; now get the fact-id
    (bind ?symptom-list (fact-slot-value ?fact-id symptoms)) ; and now get the multilist
    (printout t "From defquery/deffunction - 1st element of list " (nth$ 1 ?symptom-list) crlf)
  )
 )

(run)

(get-symptom-list)


Gives the following results:

f-0   (MAIN::initial-fact) f-1   (MAIN::illness (name Flu) (symptoms "Runny Nose" "Sore Throat")) For a total of 2 facts. Fact-id = <Fact-1>

From defrule test - 1st element of list Runny Nose

start of get-symptom-list
From defquery/deffunction - 1st element of list Runny Nose




This e-mail and any files transmitted with it, are confidential to National Grid and are intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error, please contact the National Grid USA Enterprise Support Center on 508-389-3375 or 315-428-6360.

Reply via email to