【发布时间】:2020-01-17 11:41:35
【问题描述】:
我正在使用deftemplates 构建家谱。我使用deffacts family 通过断言人们的母亲和父亲来声明初始事实基础。然后我设置了一堆规则来断言兄弟姐妹,祖父母,堂兄弟等。我想从用户那里得到两个名字,然后根据事实,它会告诉我他们之间的关系是什么。我被这个问题难住了,请帮忙。
我一直在尝试使用find-all-facts、find-fact,但我不知道如何正确使用查询语法。我需要一个循环来遍历每个事实吗?
我正在使用的定义模板:
(deftemplate father-of (slot father) (slot child))
(deftemplate mother-of (slot mother) (slot child))
(deftemplate parent-of (slot parent) (slot child))
(deftemplate sister-of (slot sister) (slot sibling))
(deftemplate brother-of (slot brother) (slot sibling))
(deftemplate aunt-of (slot aunt) (slot nephew-or-niece))
(deftemplate uncle-of (slot uncle) (slot nephew-or-niece))
(deftemplate cousin-of (slot cousin-1) (slot cousin-2))
...
最初的事实基础被剪断:
(deffacts family
;GreatGrandParents
(father-of (father "Henry") (child "Bob"))
(father-of (father "Henry") (child "Susie"))
(father-of (father "Henry") (child "Anton"))
(mother-of (mother "Georgette") (child "Bob"))
...)
我一直在尝试的:
(defrule get-relationship ""
=>
(printout t crlf "Enter a person in the family: ")
(bind ?p1 (read))
(printout t crlf "Enter another person in the family: ")
(bind ?p2 (read))
(find-all-facts
($a?-of ($a? ?p1) ($b? ?p2)) ;any fact that contains both names entered
((!= 0 (str-compare ?p1 ?p2)) ;given ?p1 and ?p2 are dissimilar
(printout t ?p1 "is a" $a? "of" $b? crlf)) ;display the relationship found
)
【问题讨论】:
标签: clips expert-system