I am trying to find average value of temperature observations in JessTab which requires joining facts from multiple classes. The following rule:
(defrule averageOfObsValue
?res <-
(accumulate
(progn (bind ?s 0)(bind ?n 0))
(progn (bind ?s (+ ?s ?v)) (++ ?n))
(create$ ?n ?s ?qo)
(and
(object (is-a http..#ObservationValue)
(OBJECT ?ov)
(http..#hasDataValue ?v)
)
(object (is-a http..#SensorOutput)
(OBJECT ?so)
(http..#hasValue ?ov)
)
(object (is-a http..#Observation)
(OBJECT ?o)
(http..#observationResult ?so)
(http..#qualityOfObservation ?qo)
)
)
)
=>
(bind ?q (nth$ 3 ?res))
(bind ?s (nth$ 2 ?res))
(bind ?n (nth$ 1 ?res))
(if (= (?q getURI) "http..#Temperature") then
(printout t "Average value is " (/ ?s ?n) " of " ?n " temperature observations." crlf)))
in the WM has the following form:
(defrule MAIN::averageOfObsValue
(or
(and
(object (is-a http..#ObservationValue)
(OBJECT ?ov)
(http..#isValueOf ?so)
(http..#hasDataValue ?v)))
(and
(object (is-a http..#SensorOutput)
(OBJECT ?so) (http..#isObservationResultOf ?o)))
(and
(object (is-a http..#Observation)
(OBJECT ?o) (http..#qualityOfObservation ?qo))))
=>
(bind ?q (nth$ 3 ?res))
(bind ?s (nth$ 2 ?res))
(bind ?n (nth$ 1 ?res))
(if (= (?q getURI) "http..#Temperature") then
(printout t "Average value is " (/ ?s ?n) " of " ?n " temperature observations." crlf)))
and while running it the following error appears:
Jess reported an error in routine Context.getVariable while executing (nth$ 3 ?res) while executing (bind ?q (nth$ 3 ?res)) while executing defrule MAIN::averageOfObsValue655 while executing (run). Message: No such variable res. Program text: ( run ) at line 137.