我有一个 A 类,它由两个子类 B 和 C 组成。B 类有三个实例,而 C 类有两个。我可以编写一个 JessTab 规则来计算 A 的所有隐式实例,即给我 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 (TEQ) 时执行 (instanceof ?_20_x(0,2,-1) http...#A) 时报告例程 instanceof 错误,同时执行规则 LHS (TECT)。消息:找不到类:http...#A。程序文本: ( defrule countAinstances ?c <- (accumulate ( bind ?count 0 ) ( bind ?count ( + ?count 1 ) ) ?count ( object ( OBJECT ?x & : ( instanceof ?x http...#A ) ) ) ) = > ( printout t ?c "A 类实例的数量。" crlf ) ) 在第 20 行。
嵌套异常是:http...#A