; Templates (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)) (deftemplate parent-of (slot parent) (slot child)) (deftemplate sibling-of (slot sibling1) (slot sibling2)) (deftemplate grandparent-of (slot grandparent) (slot child)) (deftemplate grandmother-of (slot grandmother) (slot child)) (deftemplate grandfather-of (slot grandfather) (slot child)) (deftemplate ancestor-of (slot older) (slot younger)) ; Rules (defrule sibling (mother-of (mother ?mother) (child ?sibling1)) (mother-of (mother ?mother) (child ?sibling2&~?sibling1)) (father-of (father ?father) (child ?sibling1)) (father-of (father ?father) (child ?sibling2)) => (assert (sibling-of (sibling1 ?sibling1) (sibling2 ?sibling2)))) (defrule male (father-of (father ?father)) => (assert (male (person ?father)))) (defrule sister (sibling-of (sibling1 ?sister) (sibling2 ?sibling)) (female (person ?sister)) => (printout t ?sister " is the sister of " ?sibling crlf)) (defrule brother (sibling-of (sibling1 ?brother) (sibling2 ?sibling)) (male (person ?brother)) => (printout t ?brother " is the brother of " ?sibling crlf)) (defrule female (mother-of (mother ?mother)) => (assert (female (person ?mother)))) (defrule uncle (male (person ?uncle)) (mother-of (mother ?mother) (child ?child)) (father-of (father ?father) (child ?child)) (sibling-of (sibling1 ?uncle) (sibling2 ?mother|?father)) => (printout t ?uncle " is the uncle of " ?child crlf) ) (defrule aunt (female (person ?aunt)) (mother-of (mother ?mother) (child ?child)) (father-of (father ?father) (child ?child)) (sibling-of (sibling1 ?aunt) (sibling2 ?mother|?father)) => (printout t ?aunt " is the aunt of " ?child crlf) ) (defrule mother (mother-of (mother ?mother) (child ?child)) => (assert (parent-of (parent ?mother) (child ?child)))) (defrule father (father-of (father ?father) (child ?child)) => (assert (parent-of (parent ?father) (child ?child)))) (defrule grandparent (parent-of (parent ?grandparent) (child ?parent)) (parent-of (parent ?parent) (child ?child)) => (assert (grandparent-of (grandparent ?grandparent) (child ?child)))) (defrule grandmother (grandparent-of (grandparent ?grandparent) (child ?child)) (female (person ?grandparent)) => (assert (grandmother-of (grandmother ?grandparent) (child ?child))) (printout t ?grandparent " is the grandmother of " ?child crlf) ) (defrule grandfather (grandparent-of (grandparent ?grandparent) (child ?child)) (male (person ?grandparent)) => (assert (grandfather-of (grandfather ?grandparent) (child ?child))) (printout t ?grandparent " is the grandfather of " ?child crlf) ) (defrule cousin (grandmother-of (grandmother ?grandmother) (child ?child1)) (grandfather-of (grandfather ?grandfather) (child ?child1)) (grandmother-of (grandmother ?grandmother) (child ?child2&~?child1)) (grandfather-of (grandfather ?grandfather) (child ?child2)) (not (sibling-of (sibling1 ?child1) (sibling2 ?child2))) => (printout t ?child1 " is the cousin of " ?child2 crlf) ) (defrule ancestor (parent-of (parent ?parent) (child ?child)) => (assert (ancestor-of (older ?parent) (younger ?child))) (printout t ?parent " is the ancestor of " ?child crlf)) (defrule ancestor2 (ancestor-of (older ?ancestor) (younger ?heir)) (parent-of (parent ?ancestor2) (child ?ancestor)) => (assert (ancestor-of (older ?ancestor2) (younger ?heir))) (printout t ?ancestor2 " is the ancestor of " ?heir crlf)) ; Initial Facts (you can change these to reflect your own family) (deffacts my-family (male (person Tommy)) (male (person Adam)) (female (person Aimee)) (female (person Wendy)) (father-of (father Tom) (child Tommy)) (father-of (father Tom) (child Adam)) (father-of (father Tom) (child Aimee)) (father-of (father Tom) (child Wendy)) (mother-of (mother Diana) (child Adam)) (mother-of (mother Diana) (child Tommy)) (mother-of (mother Diana) (child Aimee)) (mother-of (mother Diana) (child Wendy)) (mother-of (mother Jane) (child Diana)) (mother-of (mother Clara) (child Tom)) (father-of (father Paul) (child Diana)) (father-of (father Stanley) (child Tom)) (father-of (father Stanley) (child Brian)) (mother-of (mother Clara) (child Brian)) (father-of (father Brian) (child Jeff)) (father-of (father Paul) (child Lisa)) (mother-of (mother Jane) (child Lisa)) (mother-of (mother Lisa) (child Tiffany)) )