我是 CLIPS 的新手,所以我确信有更好的方法,但以下规则可以满足您的需求:
(defrule inc-wines-with-color
(increase-all-with color ?color ?amount)
(wine (name ?name) (color ?color))
=>
(assert (increase-certainty ?name ?amount)))
(defrule retract-inc-all-with
?f <- (increase-all-with $?)
=>
(retract ?f))
(defrule increase-wine-certainty
(not (increase-all-with $?))
?ic <-(increase-certainty ?name ?amount)
?wine <- (wine (name ?name) (certainty ?c))
=>
(printout t "Incrementing " ?name " from " ?c " to " (+ ?amount ?c) crlf)
(modify ?wine (certainty (+ ?amount ?c)))
(retract ?ic))
以下是运行它的结果:
CLIPS> (reset)
CLIPS> (assert (increase-all-with color red 0.2))
<Fact-4>
CLIPS> (run)
Incrementing Merlot from 0 to 0.2
Incrementing Cabernet sauvignon from 0 to 0.2
CLIPS> (facts)
f-0 (initial-fact)
f-1 (wine (name "Chardonnay") (color white) (certainty 0))
f-7 (wine (name "Merlot") (color red) (certainty 0.2))
f-8 (wine (name "Cabernet sauvignon") (color red) (certainty 0.2))
For a total of 4 facts.
注意:您可能需要将冲突解决策略设置为 LEX 或 MEA,以保证规则的正确排序。