home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ckscripts / cheetah < prev    next >
Text File  |  2020-01-01  |  6KB  |  257 lines

  1. # From: "Dat Nguyen" <thucdat@hotmail.com>
  2. # Subject: Module cheetah
  3. # Date: Wed, 19 May 2004 01:16:37 -0400
  4. #
  5. # Animal Taxonomy is a favorite subject of specialized rule-based programming 
  6. # languages. With some creative construction, C-Kermit can solve that problem 
  7. # in the same manner. The cheetah.kr script exposes the same look and feel of 
  8. # many rule-based programs. Many configuration problems in computer 
  9. # administration and network should be solvable similarly, provided the rule 
  10. # set can be identified.
  11. #
  12. # This demonstration comes in two modules: rule-engine and cheetah.
  13. # To run the demonstration, tell Kermit to TAKE the cheetah module.
  14. #
  15. # Here is cheetah:
  16.  
  17. take rule-engine
  18.  
  19. define rule_1 {
  20.     (if (AND
  21.          (isThisFactTrue '(the animal has hair))
  22.          (availableRule '\v(macro))
  23.          )
  24.       (.
  25.        (addThisFact '(the animal is a mammal))
  26.        (1)
  27.        )
  28.      (0)
  29.      )
  30. }
  31.  
  32. define rule_2 {
  33.     (if (AND
  34.          (isThisFactTrue '(the animal gives milk))
  35.          (availableRule '\v(macro))
  36.          )
  37.       (.
  38.        (addThisFact '(the animal is a mammal))
  39.        (1)
  40.        )
  41.      (0)
  42.      )
  43. }
  44.  
  45. define rule_3 {
  46.     (if (AND
  47.          (isThisFactTrue '(the animal has feathers))
  48.          (availableRule '\v(macro))
  49.          )
  50.       (.
  51.        (addThisFact '(the animal is a bird))
  52.        (1)
  53.        )
  54.      (0)
  55.      )
  56. }
  57.  
  58. define rule_4 {
  59.     (if (AND
  60.          (isThisFactTrue '(the animal flies))
  61.          (isThisFactTrue '(the animal lays eggs))
  62.          (availableRule '\v(macro))
  63.          )
  64.       (.
  65.        (addThisFact '(the animal is a bird))
  66.        (1)
  67.        )
  68.      (0)
  69.      )
  70. }
  71.  
  72. define rule_5 {
  73.     (if (AND
  74.          (isThisFactTrue '(the animal is a mammal))
  75.          (isThisFactTrue '(the animal eats meat))
  76.          (availableRule '\v(macro))
  77.          )
  78.       (.
  79.        (addThisFact '(the animal is a carnivore))
  80.        (1)
  81.        )
  82.      (0)
  83.      )
  84. }
  85.  
  86. define rule_6 {
  87.     (if (AND
  88.          (isThisFactTrue '(the animal is a mammal))
  89.          (isThisFactTrue '(the animal has pointed teeth))
  90.          (isThisFactTrue '(the animal has claws))
  91.          (isThisFactTrue '(the animal's eyes point forward))
  92.          (availableRule '\v(macro))
  93.          )
  94.       (.
  95.        (addThisFact '(the animal is a carnivore))
  96.        (1)
  97.        )
  98.      (0)
  99.      )
  100. }
  101.  
  102. define rule_7 {
  103.     (if (AND
  104.          (isThisFactTrue '(the animal is a mammal))
  105.          (isThisFactTrue '(the animal has hooves))
  106.          (availableRule '\v(macro))
  107.          )
  108.       (.
  109.        (addThisFact '(the animal is an ungulate))
  110.        (1)
  111.        )
  112.      (0)
  113.      )
  114. }
  115.  
  116. define rule_8 {
  117.     (if (AND
  118.          (isThisFactTrue '(the animal is a mammal))
  119.          (isThisFactTrue '(the animal chews its cud))
  120.          (availableRule '\v(macro))
  121.          )
  122.       (.
  123.        (addThisFact '(the animal is an ungulate))
  124.        (addThisFact '(the animal is even-toed))
  125.        (1)
  126.        )
  127.      (0)
  128.      )
  129. }
  130.  
  131. define rule_9 {
  132.     (if (AND
  133.          (isThisFactTrue '(the animal is a carnivore))
  134.          (isThisFactTrue '(the animal has a tawny colour))
  135.          (isThisFactTrue '(the animal has dark spots))
  136.          (availableRule '\v(macro))
  137.          )
  138.       (.
  139.        (say '(the animal is a cheetah))
  140.        (addThisFact '(the animal is a cheetah))
  141.        (1)
  142.        )
  143.      (0)
  144.      )
  145. }
  146.  
  147. define rule_10 {
  148.     (if (AND
  149.          (isThisFactTrue '(the animal is a carnivore))
  150.          (isThisFactTrue '(the animal has a tawny colour))
  151.          (isThisFactTrue '(the animal has black stripes))
  152.          (availableRule '\v(macro))
  153.          )
  154.       (.
  155.        (say '(the animal is a tiger))
  156.        (addThisFact '(the animal is a tiger))
  157.        (1)
  158.        )
  159.      (0)
  160.      )
  161. }
  162.  
  163. define rule_11 {
  164.     (if (AND
  165.          (isThisFactTrue '(the animal is an ungulate))
  166.          (isThisFactTrue '(the animal has long legs))
  167.          (isThisFactTrue '(the animal has a long neck))
  168.          (availableRule '\v(macro))
  169.          )
  170.       (.
  171.        (say '(the animal is a giraffe))
  172.        (addThisFact '(the animal is a giraffe))
  173.        (1)
  174.        )
  175.      (0)
  176.      )
  177. }
  178.  
  179. define rule_12 {
  180.     (if (AND
  181.          (isThisFactTrue '(the animal is an ungulate))
  182.          (isThisFactTrue '(the animal has a white colour))
  183.          (isThisFactTrue '(the animal has black stripes))
  184.          (availableRule '\v(macro))
  185.          )
  186.       (.
  187.        (addThisFact '(the animal is a zebra))
  188.        (1)
  189.        )
  190.      (0)
  191.      )
  192. }
  193.  
  194. define rule_13 {
  195.     (if (AND
  196.          (isThisFactTrue '(the animal is a bird))
  197.          (isThisFactTrue '(the animal does not fly))
  198.          (isThisFactTrue '(the animal has long legs))
  199.          (isThisFactTrue '(the animal has a long neck))
  200.          (isThisFactTrue '(the animal is black and white))
  201.          (availableRule '\v(macro))
  202.          )
  203.       (.
  204.        (addThisFact '())
  205.        (1)
  206.        )
  207.      (0)
  208.      )
  209. }
  210.  
  211. define rule_14 {
  212.     (if (AND
  213.          (isThisFactTrue '(the animal is a bird))
  214.          (isThisFactTrue '(the animal does not fly))
  215.          (isThisFactTrue '(the animal swims))
  216.          (isThisFactTrue '(the animal is black and white))
  217.          (availableRule '\v(macro))
  218.          )
  219.       (.
  220.        (addThisFact '(the animal is a penguin))
  221.        (1)
  222.        )
  223.      (0)
  224.      )
  225. }
  226.  
  227. define rule_15 {
  228.     (if (AND
  229.          (isThisFactTrue '(the animal is a bird))
  230.          (isThisFactTrue '(the animal is a good flier))
  231.          (availableRule '\v(macro))
  232.          )
  233.       (.
  234.        (addThisFact '(the animal is an albatross))
  235.        (1)
  236.        )
  237.      (0)
  238.      )
  239. }
  240.  
  241. echo
  242. clearAllFacts
  243. addGoal never
  244. echo
  245.  
  246. # The following assumption reveals a giraffe
  247. addThisFact {the animal has hair}
  248. addThisFact {the animal has claws}
  249. addThisFact {the animal has pointed teeth}
  250. addThisFact {the animal's eyes point forward}
  251. addThisFact {the animal has a tawny colour}
  252. addThisFact {the animal has dark spots}
  253. echo
  254.  
  255. firerule {rule_1 rule_2 rule_3 rule_4 rule_5 rule_6 rule_7 rule_8 -
  256. rule_9 rule_10 rule_11 rule_12 rule_13 rule_14 rule_15}
  257.