I want to create a knowledge base system for families to match different relations between family members.
Let's assume that we have the following 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)
)
Assuming that we asserted different family members.
Now for the follwing rule it should match between a family member and his/her uncle
(defrule uncle
(fmember (name ?n)(parents ?p$?) )
(fmember (name ?na)(siblings ?sp$?) )
(eq ?p ?sp)
=>
(printout t ?na " is uncle for " ?n)
)
The logic i want to follow :
Find a family member with the name n
who has a parent p
which is a multislotfor father and mother, find another family member whose name will be na
and his siblings sp
and then check if the p
is one of the siblings of na
I am not sure about the way i take values in multislot but that's what i understand.
To match a single value within a multifield slot, place multifield wildcards on both sides of the variable matching the value:
(parents $? ?p $?)
(siblings $? ?p $?)
For example:
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>