Create rules in CLIPS to move from unknown to known person facts -


assume given set of 'person' facts defined according following construct:

(deftemplate person (slot name) (slot sex) (allowed-values male female) (multislot children)) 

write rules following:

  • create fact of form (unknown-person ) each name appears in children multislot of person fact not in name slot of person fact (it assumed no 2 people have same name)
  • for each fact of form (unknown-person ) ask user sex of person, retract fact , assert new fact of form (unknown-person ).
  • for each fact of form (unknown-person ), retract fact , create new person fact person (it assumed person has no children).

your rules should data validation ensure allowed value supplied user

define template in clips:

(deftemplate person      (slot name)      (slot sex)      (slot gender (allowed-values male female))      (multislot children)) 

start unknown-person creation (caveat: may not correct still creates person without checking see if exist).

(defrule childrencataloguer "first layer of unknown person resolution"     (person (children $?ch))     =>     (progn$ (?term ?ch)         (assert (unknown-person ?term))     )) 

deal caveat above

(defrule removeunknownswithpersonsalready     (person (name ?n))     ?up <-(unknown-person ?n)     =>     (retract ?up)) 

now, gender:

(defrule getgender      ?up-nogen <-(unknown-person ?n)     =>     (retract ?up-nogen)     (printout t crlf "please enter male or female indicate " ?n "'s gender" crlf )     (assert (unknown-person ?n (read))) ) 

there other ways can gender confirmation, have liked use deftemplate itself, allowed-values have fed validation. don't know how yet.

(assert (gender male)) (assert (gender female)) 

now, validation:

(defrule checkgender     ?p <- (unknown-person ?n ?s)     (not (gender ?s))     =>     (retract ?p)     (assert (unknown-person ?n)) ) 

finally, graduate unknown

(defrule graduatefromunknown     (declare (salience -10))     ?up <- (unknown-person ?n ?s)     =>     (retract ?up)     (assert (person (name ?n) (sex ?s))) ) 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -