私は 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 に設定する必要がある場合があります。