ルールエンジンとしてジェスを使用して、我々はいくつかの証人は、いくつかの場所で、人を見て、そして時間に関連付けられた事実を主張することができます:ルールでJessで同じ値のファクトを数えることはできますか?
(deffacts witnesses
(witness Batman Gotham 18)
(witness Hulk NYC 19)
(witness Batman Gotham 2)
(witness Superman Chicago 22)
(witness Batman Gotham 10)
)
を、私はいくつかの目撃者が持っているかどうかを知りたいです同じ場所で同じ人を見て、時間を考慮しなかった。
ジェスのドキュメントでは、我々は100Kとよりのsalrariesを行う従業員をカウントするため、この例を得た:
(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))
だから私は、前の例で私のコードをベース:「(deffacts)で
(defrule count-witnesses
(is-lost ?plost)
(witness ?pseen ?place ?time)
?c <- (accumulate (bind ?count 0)
(bind ?count (+ ?count 1))
?count
(test()) ; conditional element of accumulate
(test (= ?plost ?pseen))
(test (>= ?count 3))
=>
(assert (place-seen ?place))
)
を上記のルールとルールに従って、エンジンはその事実を主張しなければならない。
(place-seen Gotham)
バットマンはゴッサムで3回見たので。
'accumulate'の条件付き要素(CE)部分の使い方はわかりません。同じ人と場所で事実を保持するために「テスト」を使うことはできますか?
どのようにこれを達成するためのアイデアですか?
ありがとうございました!
注:「蓄積」のsynthaxは、私はあなたがまさに、それが何であるかを説明していないとして、?plost
についてのものを除外するつもりです
(accumulate <initializer> <action> <result> <conditional element>)