【发布时间】:2019-03-31 04:51:15
【问题描述】:
简介
我正在尝试用 CLIPS 语言实现一个规则——一个人是另一个人的兄弟的关系。 约束是这样的规则只能从以下前提推导出来:
(male ?x) ("x 是女性")
(female ?y) ("y 是女性")
(mother-of ?x ?y) ("x is a mother of y")
(father-of ?x ?y) ("x is a Father of 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
(father-of (father John) (child Mark))
(father-of (father John) (child Mary))
(mother-of (mother Alice) (child Mark))
(mother-of (mother Alice) (child Mary))
(male (person John))
(male (person Mark))
(female (person Alice))
(female (person Mary))
)
(defrule brother
(and
(male (person ?alpha))
(mother-of (mother ?x) (child ?alpha))
(father-of (father ?y) (child ?alpha))
(mother-of (mother ?x) (child ?beta))
(father-of (father ?y) (child ?beta))
)
=>
(printout t ?alpha " is a brother of " ?beta crlf)
(assert (brother ?alpha ?beta))
)
问题的要点
上面的代码编译并返回“true”(换句话说,构造的规则在逻辑上是正确的)。
然而,有一个微妙的问题:
如何避免添加事实的问题,例如“马克是马克的兄弟”(我们假设每个名字都是唯一的,所以同名对应同一个人)?显然,这样的事实是错误的,但我的规则却输出了这样的愚蠢。
上面的代码没有处理这个问题。
如何解决这个问题?
致谢
感谢您在这个问题上的帮助!!!
【问题讨论】:
标签: logic relationship clips expert-system