Trending Technology Machine Learning, Artificial Intelligent, Block Chain, IoT, DevOps, Data Science

Recent Post

Codecademy Code Foundations

Search This Blog

Be Assertive, Variable more than once, Retraction, Single-field wildcard in AI

Be Assertive

One common use of variables is to match a value on the LHS and then assert this bound variable on the RHS. For example, enter
          (default make-quack
          ( duck-sound ?sound)
          (assert (sound-is ?sound)))

Variable more than once
  • Be sure to do a (reset) and assert (duck-sound quack) again.
          (default make-quack          ( duck-sound ?sound)
          (assert (sound-is ?sound ?sound)))
  • When the rule fires, it will produce (sound-is quack quack) since the variable ?sound is used twice.
  • (duckshoot ?hunter ?who)
            CLIPS> (clear)
            CLIPS>  (defrule whohunt
            (duckshoot  ?hunter  >who)
             (printout t ?hunter "shot"  ?who crlf))
             (assert (duckshoot Brian duck))

  • Retraction is very useful in expert system and usually done on the RHS rather than at the top-level. Before a fact can be retracted, it must be specified to CLIPS. To retract a fact from a rule, the fact-address first must be bound to a variable on the LHS.
  • However, if you want to remove the fact whose contents are, you must first tell CLIPS the address of the fact to be retracted.
  • The fact-address is specified using the left arrow, "<-". To create this, just type a "<" symbol followed by a "-"
            (defrule get-married
            ? Ad <- (bachelor Ali)
            (Printout t "Ali is now happily married"  ?Ad crlf)
            (retract  ?Ad)

            (assert (bachelor Ali))

            (defrule get-married
            ? Ad <- (bachelor Ali)
            (Printout t "Ali is now happily married"  ?Ad crlf)
            (retract  ?Ad)
(deffacts good-prospects
(bachelor Ali)
(bachelor Aslam)
(bachelor  Abid)

Single-field wildcard
  • Instead of binding a field value to a variable, the presence of a nonempty field can be detected alone using a wildcard.
  • This type of situation, in which only part of the fact is specified, is very common and very important. To solve this problem, a wildcard can be used to fire the Richards.
  • The simplest form of wildcard is called a single-field wildcard and is shown by a question mark, "?". The "?" is also called a single -field constraint.
  • A single-field wildcard stands for exactly one field.
(defrule meeting)
(meeting-with Irawen ?)
(printout t "The meeting will be with Irawen.. "  crlf))

(deffacts M1
(meeting-with Pirawen)
(meeting-with Ntirawen)
(meeting-with Irawen)
(meeting-with Isirawen)
(meeting-with gkirawen)


No comments:

Post a Comment

Popular Posts