Declarative 误解剪辑功能。Can';我找不到正确的答案
我很难理解剪辑是如何工作的。我需要一个像“mooo->cow”这样的回答。这是我的密码Declarative 误解剪辑功能。Can';我找不到正确的答案,declarative,clips,Declarative,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 m
(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)
)
.
然后我把这个放在控制台上:
(值班规则)
(关注事实)
(监视调用)
(重置)
(运行)
(声音动物(声音动物))
我得到的答案是:
[EXPRNPSR3]声音的Miising函数声明
嗯。。。我在看“动物->牛”之类的东西
有人能帮我解决这个问题吗?我知道这应该很简单,但我被卡住了。。。谢谢 您尚未定义名为sound\u 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命令创建声音事实以触发声音动物规则:(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>
CLIPS>
(老虎机(老虎机名称)(老虎机声音))
剪辑>
(d)动物
(动物(名牛)(鸣叫声))
(动物(名犬)(声带)
(动物(名猫)(声音)
(动物(名羊)(声音me-e-e))
(动物(名鸭)(鸣叫))
)
剪辑>
(动物的声音)
(声音?x)
(动物(名称?动物)(声音?x))
=>
(打印输出t?动物crlf))
剪辑>
(无声音动物定义)
(声音?x)
(非(动物(名称?动物)(声音?x)))
=>
(打印输出t?x=>“动物不存在”crlf)
剪辑>(观看规则)
剪辑>(观看事实)
剪辑>(重置)
f-0(初始事实)
==>f-1(动物(牛名)(鸣叫声))
==>f-2(动物(名犬)(发声棒))
==>f-3(动物(名猫)(声音meuw))
==>f-4(动物(名羊)(声音me-e-e))
==>f-5(动物(名鸭)(鸣叫))
剪辑>(断言(声音mooo))
==>f-6(声音鸣叫)
剪辑>(运行)
火1声音动物:f-6,f-1
奶牛
剪辑>
非常感谢!!这对我帮助很大!!:P