Jess规则中累积的复杂条件元素

Jess规则中累积的复杂条件元素

本文介绍了Jess规则中累积的复杂条件元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在JessTab中找到温度观测值的平均值,这需要结合多个类别的事实.以下规则:

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)))

WM中的

具有以下格式:

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:

推荐答案

似乎(并且您的最新观察证实了这一点),累加无法应用于带连词的CE.最好的方法是创建包含需要计算平均值的值的临时事实,但必须注意创建独特的临时事实.

It seems (and your latest observation confirms it) that accumulate cannot be applied to a CE with a conjunction. The best way is to create temporary facts containing the values over which the average needs to be computed, but care must be taken to create distinct temporary fact.

(deftemplate Value (slot v)(slot s)

(defrule createValueFacts
    (declare (salience 100))
    (object (is-a http..#ObservationValue)
            (OBJECT ?ov)
            (http..#hasDataValue ?v)
    )
?s<-(object (is-a http..#SensorOutput)
            (OBJECT ?so)
            (http..#hasValue ?ov)
    )
    (object (is-a http..#Observation)
            (OBJECT ?o)
            (http..#observationResult ?so)
            (http..#qualityOfObservation ?qo)
    )
=>
    (assert (Value (v ?v)(s ?s))   ; using slot s to make fact unique
)

这些Value事实很容易累积:

(defrule averageOfObsValue
?res <- (accumulate
    (progn (bind ?s 0)(bind ?n 0))
    (progn (bind ?s (+ ?s ?v)) (++ ?n))
    (create$ ?n ?s)
    (Value (v ?v)))
=>
(bind ?s (nth$ 2 ?res))
(bind ?n (nth$ 1 ?res))
(printout t "Average value is " (/ ?s ?n) " of " ?n " temperature observations." crlf))

这篇关于Jess规则中累积的复杂条件元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 18:32