2016-05-21 3 views
0

私はCLIPSとクラスで大きな問題を抱えています。 私はCLIPSで小規模のセキュリティ評価を開発しましたが、ユーザーがより良い説明を望む場合は、ボタンをクリックして説明を受け取ります。CLIPSと主なdefmessage-handlers

(defclass QUESTION (is-a USER) 
(role concrete) 
(pattern-match reactive) 
(slot id (type STRING)) 
(slot description (type STRING) (create-accessor read))) 

と、このようなインスタンスのセット::

(definstances EXPLANATION 
(E1 of QUESTION (id "GQ01")(description "Choose YES if you don't know ... "))) 

は、システムは、この操作::

(send (find-instance ((?f QUESTION)) (str-compare ?f:id ?id-question)) get-description) 
を使用する記述を取得するための そうするためには、私のシステムは、このようなクラスを持っています

問題を実行すると、このメッセージが表示されます。

[MSGFUN1] No applicable primary message-handlers found for get-description. 
[PRCCODE4] Execution halted during the actions of deffunction explain-question. 
[PRCCODE4] Execution halted during the actions of deffunction yes-or-no-p. 
[PRCCODE4] Execution halted during the actions of defrule ask-for-component-needed. 

どうすれば解決できますか?私は、?idの質問と等しい場合、インスタンスセットのインスタンスのIDは、インスタンスに関連付けられた説明を印刷します。

答えて

0

関数find-instanceとfind-all-instancesは、インスタンスが見つかった場合はmultifield値を返し、そうでない場合はFALSEを返します。したがって、multifield(nth $を使用)からインスタンス値を抽出し、マルチファイアではなく送信すること。また、CLIPSでは、ブール値falseはシンボルFALSEであり、ブール演算は偽以外の値を真として扱います。 str-compareの戻り値は整数なので、find-instance呼び出しでクエリに使用する場合は、=または!=を使用して明示的に値を0と比較する必要があります。文字列を字句順に並べ替えるのでなければ、str-compareの使用にはあまり意味がありません。この場合、単にeqを使用してください。

また、find-instanceではなくdo-for-instanceを使用することをお勧めします。一致するQUESTIONインスタンスが見つからない場合は、n番目の$/find-instanceが有効な値を返したかどうかを明示的にテストする必要があります。そうでない場合、sendを呼び出すとエラーが発生します。

CLIPS> (clear) 
CLIPS> 
(defclass QUESTION (is-a USER) 
    (role concrete) 
    (slot id (type STRING)) 
    (slot description (type STRING))) 
CLIPS>  
(definstances EXPLANATION 
    (E1 of QUESTION (id "GQ01") 
        (description "Choose YES if you don't know ... "))) 
CLIPS> (reset) 
CLIPS> (bind ?id-question "GQ01") 
"GQ01" 
CLIPS> (send (find-instance ((?f QUESTION)) (str-compare ?f:id ?id-question)) get-description) 
[MSGFUN1] No applicable primary message-handlers found for get-description. 
FALSE 
CLIPS> (find-instance ((?f QUESTION)) (eq ?f:id ?id-question)) 
([E1]) 
CLIPS> (send (nth$ 1 (find-instance ((?f QUESTION)) (eq ?f:id ?id-question))) get-description) 
"Choose YES if you don't know ... " 
CLIPS> (do-for-instance ((?f QUESTION)) (eq ?f:id ?id-question) ?f:description) 
"Choose YES if you don't know ... " 
CLIPS> (bind ?id-question "GQ03") 
"GQ03" 
CLIPS> (send (nth$ 1 (find-instance ((?f QUESTION)) (eq ?f:id ?id-question))) get-description) 
[MSGFUN1] No applicable primary message-handlers found for get-description. 
FALSE 
CLIPS> (do-for-instance ((?f QUESTION)) (eq ?f:id ?id-question) ?f:description) 
FALSE 
CLIPS> 
+0

今すぐご利用いただきありがとうございます。 –