我刚刚开始在CLIPS工作。我试图做这个简单的规则,但我不知道如何在这里使用逻辑OR。我知道我可以定义两个规则(一个用于亲戚,另一个用于亲戚),但我认为这不是重点。 规则是:如果你是他的兄弟或姐妹,你是某人的亲戚。
(defrule MAIN::siblings-relatives
(is-brother ?x ?y)
(test (or (is-sister ?x ?y))
=>
(assert (is-relative ?x ?y))
(printout t ?x " is relative of " ?y crlf))
答案 0 :(得分:2)
CLIPS> (clear)
CLIPS>
(defrule siblings-relatives
(or (is-brother ?x ?y)
(is-sister ?x ?y))
=>
(assert (is-relative ?x ?y))
(printout t ?x " is relative of " ?y crlf))
CLIPS> (assert (is-brother Dave Jim))
<Fact-1>
CLIPS> (assert (is-sister Jane Frank))
<Fact-2>
CLIPS> (run)
Jane is relative of Frank
Dave is relative of Jim
CLIPS> (facts)
f-0 (initial-fact)
f-1 (is-brother Dave Jim)
f-2 (is-sister Jane Frank)
f-3 (is-relative Jane Frank)
f-4 (is-relative Dave Jim)
For a total of 5 facts.
CLIPS>