我用下面的CLIPS编程问题所困扰:
问题:编写一套规则来定义像家庭关系:
(兄弟?X?y)的(即, “x为Y A兄弟”)
(妹妹?X?y)的(即, “x为Y A姐姐”)
(儿子?X?y)的(即, “x为Y A儿子”)
(女儿?X?y)的(即, “x为Y A女儿”)
此任务中的约束是规则只能从以下前提来构建:
(爸?X?y)的(即, “x为Y A父”)
(母?X?y)的(即, “x为Y A母”)
(雄性?X)(即, “x是一个男性”)
(女性?Y)(即, “y是女性”)
该任务还假定必须有提供一些初步事实和检查的正确性应该有显示有关最后得出结论信息的实现。
我尝试
我创建的模板和初始事实如下:
(deftemplate father-of
(slot father)
(slot child)
)
(deftemplate mother-of
(slot mother)
(slot child)
)
(deftemplate male
(slot person)
)
(deftemplate female
(slot person)
)
(deffacts family
(mother-of(mother Anna) (child Tracy)
(mother-of(mother Anna) (child Cindy)
(female Anna)
(female Tracy)
(female Cindy)
)
我写的,如果某些人检查规则的尝试是其他人的妹妹如下:
(defrule sister-of
(and
(female (person ?x))
(female (person ?y))
(female (person ?z))
(mother-of (mother ?x) (child ?y))
(mother-of (mother ?x) (child ?z))
)
=>
(assert (sister ?y ?z))
(printout t ?y " is a sister of " ?z crlf)
)
输出误差
一旦予加载.clp文件I consistenly获得这种形式的以下错误消息:
CLIPS (6.30 3/17/15)
CLIPS> (reset)
CLIPS> (clear)
CLIPS> (load family.clp)
Defining deftemplate: father-of
Defining deftemplate: mother-of
Defining deftemplate: male
Defining deftemplate: female
Defining deffacts: family
[PRNTUTIL2] Syntax Error: Check appropriate syntax for deftemplate pattern.
ERROR:
(deffacts MAIN::family
(mother-of (mother Anna) (child Markus))
(female Anna
FALSE
CLIPS>
我尝试
我查了一下关于基本的编程,一派错误信息CLIPS导游,但我并没有取得任何进展。
帮助将不胜感激!对我来说就足够了看到这个东西在写作上面提供的所有模板和事实的规则(妹妹?X?Y)的情况下的情况下是如何工作的。
如果定义了一个自定义模板的一个事实,你必须指定槽值时,包括插槽名称。
(deffacts family
(mother-of(mother Anna) (child Tracy))
(mother-of(mother Anna) (child Cindy))
(female (person Anna))
(female (person Tracy))
(female (person Cindy))
)