CLIPS(templates) - 家庭关系:在编写规则时处理模板和初始事实的麻烦
CLIPS(templates) - family relations: trouble with handling templates and initial facts while writing rules
我正在努力解决以下 CLIPS 编程问题:
问题:编写一组规则来定义家庭关系,例如:
(兄弟 ?x ?y) (即 "x is a brother of y")
(姐姐 ?x ?y)(即 "x is a sister of y")
(son ?x ?y)(即 "x is a son of y")
(女儿 ?x ?y)(即 "x is a daughter of y")
此任务的限制是只能根据以下前提构建规则:
(父亲 ?x ?y)(即 "x is a father of y")
(母亲 ?x ?y)(即 "x is a mother of y")
(男?x)(即"x is a male")
(女?y)(即"y is a female")
该任务还假设必须提供一些初始事实,并且要检查正确性,应该有一个显示关于导出结论的信息的实现。
我的尝试
我创建的模板和初始事实如下:
(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 文件后,我始终收到以下这种形式的错误消息:
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 指南,用谷歌搜索了错误消息,但我没有取得任何进展。
帮助将不胜感激!!!对我来说,在使用上面提供的所有模板和事实编写规则(sister ?x ?y)的情况下,看看这些东西是如何工作的就足够了。
如果为事实定义 deftemplate,则必须在指定槽值时包含槽名称。
(deffacts family
(mother-of(mother Anna) (child Tracy))
(mother-of(mother Anna) (child Cindy))
(female (person Anna))
(female (person Tracy))
(female (person Cindy))
)
我正在努力解决以下 CLIPS 编程问题:
问题:编写一组规则来定义家庭关系,例如:
(兄弟 ?x ?y) (即 "x is a brother of y")
(姐姐 ?x ?y)(即 "x is a sister of y")
(son ?x ?y)(即 "x is a son of y")
(女儿 ?x ?y)(即 "x is a daughter of y")
此任务的限制是只能根据以下前提构建规则:
(父亲 ?x ?y)(即 "x is a father of y")
(母亲 ?x ?y)(即 "x is a mother of y")
(男?x)(即"x is a male")
(女?y)(即"y is a female")
该任务还假设必须提供一些初始事实,并且要检查正确性,应该有一个显示关于导出结论的信息的实现。
我的尝试
我创建的模板和初始事实如下:
(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 文件后,我始终收到以下这种形式的错误消息:
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 指南,用谷歌搜索了错误消息,但我没有取得任何进展。
帮助将不胜感激!!!对我来说,在使用上面提供的所有模板和事实编写规则(sister ?x ?y)的情况下,看看这些东西是如何工作的就足够了。
如果为事实定义 deftemplate,则必须在指定槽值时包含槽名称。
(deffacts family
(mother-of(mother Anna) (child Tracy))
(mother-of(mother Anna) (child Cindy))
(female (person Anna))
(female (person Tracy))
(female (person Cindy))
)