0

例如,我有:

(deftemplate Animal
(slot has-feathers (default FALSE))
(slot name (default "George"))
)

在一项规则中,我有:

(defrule bird-test
?a <-(Animal (has-feathers ?))
=>
(printout t ?a.name " is a bird" crlf)
"Add slot 'bird' to ?a or Animal"
)

我该怎么做?并提前谢谢你

编辑:谢谢各位!我想我明白我需要做什么。

4

2 回答 2

0

定义后,您不能将插槽添加到模板中;这类似于在程序运行时向 Java 类添加成员变量。

但是您可以设置现有插槽的值;如果您的模板有一个kind插槽,您可以说

(modify ?a (kind bird))
于 2015-04-23T04:02:40.803 回答
0

除了 Ernest 提出的预先提供插槽的建议之外,您还可以考虑一个多插槽,它可以充当您的规则可能为 Animal 检测到的各种属性的容器。

(deftemplate Animal
    (slot name)
    (slot has-feathers)
    (multislot props)...)

你可以写

(defrule bird-test
  (declare (no-loop TRUE))
  ?a <-(Animal (has-feathers TRUE)(props $?ex ))
=>
  (modify ?a (props $?ex isBird))
  (printout t ?a.name "'s props: " ?a.props crlf)
)

或者,可以使用一种非常通用的 deftemplate 来动态表达所有种类或属性:

(deftemplate is-a
    (slot thing)
    (slot property))

但这不仅仅是一个答案。

于 2015-04-23T05:24:08.837 回答