Reputation: 31
I'm trying to create a family tree program using CLIPS.
I'm very new to CLIPS and am facing difficulty with some operations in one of the defrule I have created.
The operation I'm trying to perform is to create facts for children who are siblings of each other. So for each pair of children, I expect the program to generate 2 new siblings facts. But the program seems to generate 4 - it's also listing each child as its own sibling...
I tried googling for a solution, but I couldn't figure out how to ask the computer to not fire if(?cn == ?sn).
Can someone please help?
(deftemplate siblings
(slot subject-name)
(slot sibling-name)
)
(defrule set-siblings
(child
(child-name ?cn)
(parent-name ?p))
(child
(child-name ?sn)
(parent-name ?p))
=>
(assert (siblings
(subject-name ?cn)
(sibling-name ?sn))
)
Upvotes: 0
Views: 113
Reputation: 10757
Modify your second pattern so that the child name matched must be different than the name bound in the first pattern:
(defrule set-siblings
(child
(child-name ?cn)
(parent-name ?p))
(child
(child-name ?sn&~?cn)
(parent-name ?p))
=>
(assert (siblings
(subject-name ?cn)
(sibling-name ?sn))
)
Upvotes: 1