【发布时间】:2014-12-27 08:26:32
【问题描述】:
我试图在 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 在例程 Context.getVariable 中报告错误 执行时 (nth$ 3 ?res) 执行时 (bind ?q (nth$ 3 ?res)) 在执行 defrule MAIN::averageOfObsValue655 在执行(运行)时。 消息:没有这样的变量 res。 程序文本:(运行)在第 137 行。
【问题讨论】:
-
(progn (bind ?s 0)(bind ?n 0)行中有一个相当明显的语法错误 - 没有右括号。 -
@laune 我解决了这个问题并修改了问题