我试图在 JessTab 中找到温度观测的平均值,这需要加入来自多个类的事实。以下规则:
(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)))
在 WM 中具有以下形式:
(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)))
并在运行时出现以下错误:
Jess 在执行 (nth$ 3 ?res) 时在例程 Context.getVariable 中报告错误,而在执行 (run) 时执行 defrule MAIN::averageOfObsValue655 时执行 (bind ?q (nth$ 3 ?res))。消息:没有这样的变量 res。程序文本:(运行)在第 137 行。