如何推断Clips中的其他关系?

时间:2014-11-08 08:28:36

标签: clips expert-system

我想为家庭创建一个知识库系统,以匹配家庭成员之间的不同关系。 我们假设我们有以下deftemplate

(deftemplate fmember 
    (slot name)
    (slot gender (type STRING) (allowed-values "female" "male") )
    (slot bd)
    (slot birthplace)
    (slot height)
    (multislot parents)
    (multislot siblings)
    (slot spouse) 
)

假设我们断言了不同的家庭成员。

现在,对于以下规则,家庭成员和他/她的叔叔之间应该匹配

(defrule uncle 
   (fmember (name ?n)(parents ?p$?) )
   (fmember (name ?na)(siblings ?sp$?) )
   (eq ?p ?sp)
=>
   (printout t  ?na " is uncle for " ?n)
)

我想遵循的逻辑: 查找姓名为n的家庭成员,其父亲p是父亲和母亲的多时间段,找到另一位姓名为na的家庭成员及其兄弟姐妹sp然后检查pna

的兄弟姐妹之一

我不确定我在多时隙中采用价值观的方式,但这是我所理解的。

1 个答案:

答案 0 :(得分:0)

要匹配多字段插槽中的单个值,请在与该值匹配的变量的两侧放置多字段通配符:

(parents $? ?p $?)
(siblings $? ?p $?) 

例如:

CLIPS> (clear)
CLIPS> 
(deftemplate fmember 
   (slot name)
   (slot gender (type SYMBOL) (allowed-values female male))
   (slot bd)
   (slot birthplace)
   (slot height)
   (multislot parents)
   (multislot siblings)
   (slot spouse))
CLIPS> 
(deffacts data 
   (fmember (name "Jack Smith")
            (gender male) 
            (parents "John Smith" "Jane Smith")
            (siblings "Janet Jones" "Jill Parker"))
   (fmember (name "Janet Jones")
            (gender female) 
            (parents "John Smith" "Jane Smith")
            (siblings "Jack Smith" "Jill Parker")
            (spouse "Bill Jones"))
   (fmember (name "Jill Parker")
            (gender female) 
            (parents "John Smith" "Jane Smith")
            (siblings "Jack Smith" "Janet Jones"))
   (fmember (name "Bill Jones")
            (gender male) 
            (parents "Bob Jones" "Sue Jones")
            (spouse "Janet Jones"))
   (fmember (name "Fred Jones")
            (gender male) 
            (parents "Bill Jones" "Janet Jones")))
CLIPS>    
(defrule uncle 
   (fmember (name ?n) 
            (parents $? ?p $?))
   (fmember (name ?na) 
            (gender male)
            (siblings $? ?p $?))
   =>
   (printout t  ?na " is the uncle of " ?n crlf))
CLIPS> (reset)
CLIPS> (run)
Jack Smith is the uncle of Fred Jones
CLIPS>