【问题标题】:Misunderstanding CLIPS functions. Can't find the right answer对 CLIPS 功能的误解。找不到正确答案
【发布时间】:2015-09-27 04:08:39
【问题描述】:

我无法理解 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 (sound mooo))

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

嗯...我在看像“动物->牛”之类的东西 有人能帮我解决这个问题吗?我知道这应该很简单,但我卡住了...谢谢!!

【问题讨论】:

    标签: declarative clips


    【解决方案1】:

    您尚未定义名为 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> 
    

    【讨论】:

    • 非常感谢!!对我帮助很大!! :P
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-12
    • 2020-12-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多