2016-11-22 6 views
0

は、どのように私はどのように我々はクリップ条件付きルール

if hotel = poor then stay 
if hotel = poor and weather = raining then stay 
if (hotel = poor and weather = sunny) or (hotel = good and weather = raining) then plan 

おかげのようなルールを作成しない、例えばこの本Whith

(deftemplate holiday 
(slot hotel (allowed-symbols nice good poor)) 
(slot weather (allowed-symbols sunny raining)) 
) 
(deftemplate output 
(slot option (allowed-symbols go plan stay)) 
) 

を出力

を見つけるために、クリップに条件付きルールを作ることができます

答えて

1
(defrule hotel-rule1 
     (holiday (hotel ?hotel&:(eq ?hotel poor))) 
     => 
     (assert (output (option stay))) 
    ) 

(defrule hotel-rule2 
     (holiday (hotel ?hotel&:(eq ?hotel poor)) (weather ?weather&:(eq ?weather raining))) 
     => 
     (assert (output (option stay))) 
    ) 

私が書いた例のように、最後のルールの "or"条件を2つの異なるルールで分割します。

bye ニック

+0

ありがとうございます。エラーが表示されます:[EXPRNPSR3]オプションの関数宣言がありません。私は何か間違っているのですか? – Selrac

+0

申し訳ありませんが、動作しています。あなたのコードを正しくコピーしませんでした。ありがとう – Selrac

+0

変数をバインドしてeq関数を呼び出すのではなく、定数を直接照合することができます。たとえば、(休日(ホテルのホテル&:(悪い))(天気?天気&:(eq?天気予報)))、 –