1
votes

I am struggling with the following CLIPS programming problem:

Problem: write a set of rules to define family relations like:

(brother ?x ?y) (i.e. "x is a brother of y")

(sister ?x ?y) (i.e. "x is a sister of y")

(son ?x ?y) (i.e. "x is a son of y")

(daughter ?x ?y) (i.e. "x is a daughter of y")

The constraint in this task is that the rules can be constructed only from the following premises:

(father ?x ?y) (i.e. "x is a father of y")

(mother ?x ?y) (i.e. "x is a mother of y")

(male ?x) (i.e. "x is a male")

(female ?y) (i.e. "y is a female")

The task also assumes that there must be some initial facts provided and that to check the correctness there should be an implementation of displaying information about derived conclusions.

My attempt

I created templates and initial facts as follows:

(deftemplate father-of 
    (slot father)
    (slot child)
)

(deftemplate mother-of 
    (slot mother)
    (slot child)
)

(deftemplate male
    (slot person)
)

(deftemplate female
    (slot person)
 )

(deffacts family
      (mother-of(mother Anna) (child Tracy)
      (mother-of(mother Anna) (child Cindy)
      (female Anna)
      (female Tracy)
      (female Cindy)
 )

My attempt in writing a rule for checking if certain person is a sister of other person was as follows:

(defrule sister-of
      (and
           (female (person ?x))
           (female (person ?y))
           (female (person ?z))
           (mother-of (mother ?x) (child ?y))
           (mother-of (mother ?x) (child ?z))
       )
=>
(assert (sister ?y  ?z))
(printout t ?y " is a sister of " ?z crlf)
)

Output error

Once I load .clp file I consistenly obtain the following error message of such form:

         CLIPS (6.30 3/17/15)
CLIPS> (reset)
CLIPS> (clear)
CLIPS> (load family.clp)
Defining deftemplate: father-of
Defining deftemplate: mother-of
Defining deftemplate: male
Defining deftemplate: female
Defining deffacts: family

[PRNTUTIL2] Syntax Error:  Check appropriate syntax for deftemplate pattern.

ERROR:
(deffacts MAIN::family
   (mother-of (mother Anna) (child Markus))
   (female Anna
FALSE
CLIPS>

My attempts

I checked CLIPS guides regarding basic programming, googled error message, but I did not make any progress.

Help will be greatly appreciated!!! For me it suffices to see how this stuff works in the case of the case of writing a rule (sister ?x ?y) with all the templates and facts provided above.

1

1 Answers

1
votes

If you define a deftemplate for a fact, you must include the slot names when specifying the slot values.

(deffacts family
      (mother-of(mother Anna) (child Tracy))
      (mother-of(mother Anna) (child Cindy))
      (female (person Anna))
      (female (person Tracy))
      (female (person Cindy))
 )