Expert system 我们能用Jess中相同的值计算事实吗?

Expert system 我们能用Jess中相同的值计算事实吗?,expert-system,jess,Expert System,Jess,使用Jess作为规则引擎,我们可以断言一个事实,即某个证人在某个地方见过一个人,并且与时间相关: (deffacts witnesses (witness Batman Gotham 18) (witness Hulk NYC 19) (witness Batman Gotham 2) (witness Superman Chicago 22) (witness Batman Gotham 10) ) 根据规定,我想知道几个证人是否在同一地点见过同一个人

使用Jess作为规则引擎,我们可以断言一个事实,即某个证人在某个地方见过一个人,并且与时间相关:

(deffacts witnesses
    (witness Batman Gotham 18)
    (witness Hulk NYC 19)
    (witness Batman Gotham 2)
    (witness Superman Chicago 22)
    (witness Batman Gotham 10)
)
根据规定,我想知道几个证人是否在同一地点见过同一个人,而不考虑时间

在Jess文档中,我们得到了一个计算10万及以上销售额的员工的示例:

(defrule count-highly-paid-employees
    ?c <- (accumulate (bind ?count 0)                        ;; initializer
    (bind ?count (+ ?count 1))                    ;; action
    ?count                                        ;; result
    (employee (salary ?s&:(> ?s 100000)))) ;; CE
    =>
    (printout t ?c " employees make more than $100000/year." crlf))
因为我们在高谭看过三次蝙蝠侠

我不知道如何使用“累计”的条件元素(CE)部分。我可以使用“测试”来保留同一个人和同一地点的事实吗

你知道如何做到这一点吗

谢谢大家!


注:“累积”的Syntax为

(accumulate <initializer> <action> <result> <conditional element>)
(累积)

我将省略关于
?plost
的内容,因为您没有确切解释这是什么;如果需要,您可以将其添加回您自己

(几乎)做你想做的事的基本规则如下。你没有得到的CE部分只是一个我们想要积累的模式;在这里,它与在同一地点见证的同一人的事实相匹配,与第一人匹配的事实相匹配:

(defrule count-witnesses
  ;; Given that some person ?person was seen in place ?place
  (witness ?person ?place ?)  
  ;; Count all the sightings of that person in that place  
  ?c <- (accumulate (bind ?count 0)
                    (bind ?count (+ ?count 1))
                    ?count
                    (witness ?person ?place ?))
  ;; Don't fire unless the count is at least 3
  (test (>= ?c 3))
  =>
  (assert (place-seen ?person ?place))
)
(accumulate <initializer> <action> <result> <conditional element>)
(defrule count-witnesses
  ;; Given that some person ?person was seen in place ?place
  (witness ?person ?place ?)  
  ;; Count all the sightings of that person in that place  
  ?c <- (accumulate (bind ?count 0)
                    (bind ?count (+ ?count 1))
                    ?count
                    (witness ?person ?place ?))
  ;; Don't fire unless the count is at least 3
  (test (>= ?c 3))
  =>
  (assert (place-seen ?person ?place))
)
(defrule count-witnesses
  ;; Given that some person ?person was seen in place ?place, and there is no other 
  ;; sighting of the same person at the same place at an earlier time
  (witness ?person ?place ?t1)    
  (not (witness ?person ?place ?t2&:(< ?t2 ?t1)))
  ;; Count all the sightings of that person in that place  
  ?c <- (accumulate (bind ?count 0)
                    (bind ?count (+ ?count 1))
                    ?count
                    (witness ?person ?place ?))
  ;; Don't fire unless the count is at least 3
  (test (>= ?c 3))
  =>
  (assert (place-seen ?person ?place))
)