对 CLIPS 功能的误解。找不到正确答案

Misunderstanding CLIPS functions. Can't find the right answer

我无法理解 CLIPS 的工作原理。我需要得到一个像 "mooo -> cow" 这样的答案。这是我的代码。

(deftemplate animal (slot name)(slot sound))

(deffacts Input_animal 
    (animal(name cow)(sound mooo))
    (animal(name dog)(sound barf))
    (animal(name cat)(sound meuw))
    (animal(name sheep)(sound me-e-e))
    (animal(name duck)(sound cuack))
    )

(defrule sound_animal 
    (sound ?x)
    (animal(name ?animal)(sound ?x))
    =>
    (printout t ?animal crlf)
)

(defrule no_sound_animal 
    (sound ?x)
    (not(animal(name ?animal)(sound ?x)))
    =>
    (printout t ?x => "the animal doesn't exist" crlf)
)
.

然后我把这个放在控制台上: (观看规则) (观察事实) (观看调用) (重启) (运行) (sound_animal (声音 mooo))

我得到了这个答案: [EXPRNPSR3] 声音的 Miising 函数声明

好吧...我正在观察 "animal -> cow" 有人可以帮我解决这个问题吗?我知道这应该很简单,但我卡住了...谢谢!!

您尚未定义名为 sound_animal 或 sound 的函数,因此尝试调用这些函数将产生错误。

CLIPS> (sound_animal (sound mooo))

[EXPRNPSR3] Missing function declaration for sound_animal.
CLIPS> (deffunction sound_animal ())
CLIPS> (sound_animal (sound mooo))

[EXPRNPSR3] Missing function declaration for sound.
CLIPS>

使用 assert 命令创建一个声音事实来触发 sound_animal 规则:(assert (sound moo))。 assert 命令是一种特殊形式,因为 assert 函数名称后面的括号用于分隔事实关系及其槽,而不是表示对带有 moo 参数的声音函数的函数调用。

CLIPS> 
(deftemplate animal (slot name)(slot sound))
CLIPS> 
(deffacts Input_animal 
    (animal(name cow)(sound mooo))
    (animal(name dog)(sound barf))
    (animal(name cat)(sound meuw))
    (animal(name sheep)(sound me-e-e))
    (animal(name duck)(sound cuack))
    )
CLIPS> 
(defrule sound_animal 
    (sound ?x)
    (animal(name ?animal)(sound ?x))
    =>
    (printout t ?animal crlf))
CLIPS> 
(defrule no_sound_animal 
    (sound ?x)
    (not(animal(name ?animal)(sound ?x)))
    =>
    (printout t ?x => "the animal doesn't exist" crlf))
CLIPS> (watch rules)
CLIPS> (watch facts)
CLIPS> (reset)
<== f-0     (initial-fact)
==> f-0     (initial-fact)
==> f-1     (animal (name cow) (sound mooo))
==> f-2     (animal (name dog) (sound barf))
==> f-3     (animal (name cat) (sound meuw))
==> f-4     (animal (name sheep) (sound me-e-e))
==> f-5     (animal (name duck) (sound cuack))
CLIPS> (assert (sound mooo))
==> f-6     (sound mooo)
<Fact-6>
CLIPS> (run)
FIRE    1 sound_animal: f-6,f-1
cow
CLIPS>