bastado78
bastado78

Reputation: 21

CLIPS family tree expert system

I am trying to create a CLIPS program that describes family relations. I am completely lost, I don't even know where to start. Given the following deftemplates for facts describing a family tree.

    (deftemplate father‐of (slot father) (slot child))
    (deftemplate mother‐of (slot mother) (slot child))
    (deftemplate male (slot person))
    (deftemplate female (slot person))
    (deftemplate wife‐of (slot wife) (slot husband))
    (deftemplate husband‐of (slot husband) (slot wife))

Write rules that infer the following relations. Describe the deftemplates you use to solve the problem. a) Uncle, aunt b) Cousin c) Grandparent d) Grandfather, grandmother e) Sister, bother Run the expert system for your own family tree.

I have looked up similar examples and tried doing something similar but I am still struggling to understand what I need to do

Upvotes: 2

Views: 1275

Answers (1)

Gary Riley
Gary Riley

Reputation: 10757

Here's how you could do it for determining the sister:

         CLIPS (6.31 6/12/19)
CLIPS> (deftemplate father-of (slot father) (slot child))
CLIPS> (deftemplate mother-of (slot mother) (slot child))
CLIPS> (deftemplate male (slot person))
CLIPS> (deftemplate female (slot person))
CLIPS> 
(deffacts info
   (father-of (father Bill) (child Mary))
   (mother-of (mother Jane) (child Mary))
   (father-of (father Bill) (child John))
   (mother-of (mother Jane) (child John))
   (male (person Bill))
   (male (person John))
   (female (person Jane))
   (female (person Mary)))
CLIPS>    
(defrule sister-of
   (or (male (person ?person))
       (female (person ?person)))
   (female (person ?sister&~?person))
   (father-of (father ?father) (child ?person))
   (father-of (father ?father) (child ?sister))
   (mother-of (mother ?mother) (child ?person))
   (mother-of (mother ?mother) (child ?sister))
   =>
   (printout t ?sister " is the sister of " ?person crlf))
CLIPS> (reset)
CLIPS> (run)
Mary is the sister of John
CLIPS> 

Upvotes: 0

Related Questions