0

クラス B には 3 つのインスタンスがあり、C には 2 つのインスタンスがあります。A のすべての暗黙的なインスタンスをカウントする JessTab ルールを記述できますか? つまり、5 を返しますか?

Jess でのクラス A のマッピング:

(mapclass http...#A)

A の直接のインスタンスがないため、0 になるインスタンスをカウントするルール:

元は:

(defrule countAinstances 
?c <- (accumulate (bind ?count 0) 
(bind ?count (+ ?count 1)) 
?count 
(object (ís-a http...#A))
) 
=> 
(printout t ?c " number of class A instances." crlf))

これは、A のサブクラスのインスタンスをカウントしません。

修正版:

(defrule countAinstances 
?c <- (accumulate (bind ?count 0) 
(bind ?count (+ ?count 1)) 
?count 
(object (OBJECT ?x&:(instanceof ?x http...#A)))
) 
=> 
(printout t ?c " number of class A instances." crlf))

次のエラーが表示されます。

Jess は、ルール LHS (TECT) の実行中にルール LHS (TEQ) の実行中に (instanceof ?_20_x(0,2,-1) http...#A) ルーチン instanceof でエラーを報告しました。メッセージ: クラスが見つかりません: http...#A. プログラムテキスト: ( defrule countAinstances ?c <- ( Accumulate ( bind ?count 0 ) ( bind ?count ( + ?count 1 ) ) ?count ( object ( OBJECT ?x & : ( instanceof ?x http...#A ) ) ) ) = > ( printout t ?c "number of class A instances." crlf ) ) at line 20.

ネストされた例外: http...#A

4

2 に答える 2

1

オブジェクトにアクセスし、プロテジ スロット is-a ではなく、Jess 自身の関数 instanceof に依存します。

(object (OBJECT ?x&:(instanceof ?x A))) 

A がインポートされていない場合は、完全なクラス名を使用します。

Java クラス名がない場合は、(or) 関数を使用して、そのパターンのすべてのクラスとサブクラスをテストする必要があります。かなり退屈です。

後で

is-a には、クラス名と比較できるクラス参照が含まれているため、これがルールを記述する最も簡単な方法です。

defrule countAinstances
?c <- (accumulate (bind ?count 0) 
(bind ?count (+ ?count 1)) 
?count 
(object (is-a ?x&B|C))
      )
=> 
(printout t ?c " number of subclass instances." crlf))
于 2015-01-03T10:15:47.853 に答える
0

完全なソリューション ルールは次のとおりです。

(defrule countAinstances
?c <- (accumulate (bind ?count 0) 
(bind ?count (+ ?count 1)) 
?count 
(object (is-a ?x&:(or (= ?x B)(= ?x C))))
)
=> 
(printout t ?c " number of subclass instances." crlf))
于 2015-01-03T14:21:55.963 に答える