home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 241_01 / expert.h < prev    next >
Encoding:
C/C++ Source or Header  |  1987-08-29  |  5.8 KB  |  179 lines

  1. /*
  2. HEADER:         CUG241;
  3. TITLE:          Rule-Based Compiler for Expert System;
  4. DATE:           12/30/85;
  5. VERSION:
  6. DESCRIPTION:   "Source code for rule-based compiler for an Expert System";
  7. KEYWORDS:       Artificial Intelligence, expert systems, rule-based compiler;
  8. SYSTEM:         MS-DOS or UNIX System V;
  9. FILENAME:       ;
  10. WARNINGS:      "User-supported, non-commercial"
  11. AUTHORS:        George Hageman; 
  12. COMPILERS:      Microsoft C V3.00 or UNIX System V Portable C Compiler;
  13. REFERENCES:     ;
  14. ENDREF
  15. */
  16.  
  17. /*************************************************************************
  18. **                                    **
  19. **    The software contained in this distribution is copyright (C)    **
  20. **    by George Hageman 1985 and is released into the public         **
  21. **    domain with the following restrictions:                 **
  22. **                                    **
  23. **        (1)  This software is intended for non-commertial    **
  24. **            usage.                        **
  25. **        (2)  I am held save from damages resulting from        **
  26. **            its use, and                    **
  27. **        (3)  The following concepts and legal jargon are    **
  28. **            agreed to by the user of this software.        **
  29. **                                    **
  30. **    User-supported software concept:                 **
  31. **                                    **    
  32. **    IF    you find use for this software                **
  33. **    ANDIF it saves you some development time            **
  34. **    THEN        send me $10.00                    **
  35. **    ANDTHENHYP  you will feel good!                    **
  36. **                                    **
  37. **                                    **
  38. **    This source code is provided on an "as is" basis without    **
  39. **    warranty of any kind, expressed or implied, including but    **
  40. **    not limited to the implied warranties of merchantability    **
  41. **    and fitness for a particular purpose.  The entire risk as    **
  42. **    to quality and performance of this software is with you.     **
  43. **    Should the software prove defective, you assume the entire    **
  44. **    cost of all necessary repair, servicing, or correction.  In    **
  45. **    no event will the author be liable to you for any damages,    **
  46. **    including any lost profits, lost savings, or other        **
  47. **    incidental or consequential damages arising out of the  use    **
  48. **    of inability to use this software.  In short my friends, I    **
  49. **    have done  a reasonable ammount of work in debugging this    **
  50. **    software and I think it is pretty good but, as you know,    **
  51. **    there is always some chance that a bug is still lurking     **
  52. **    around. If you should happen to be lucky enough to  find one,    **
  53. **    please let me know so I    can make an attempt to fix it.        **
  54. **                                    **
  55. **                Thanks,                    **
  56. **                                    **
  57. **                George Hageman                **
  58. **                P.O. Box 11234                **
  59. **                Boulder, Colorado 80302            **
  60. **                                    **
  61. *************************************************************************/
  62.  
  63.  
  64. /*
  65. **    These are the structures of the rulebase which will
  66. **    be used to compile the rules into.  
  67. */
  68.  
  69. #define FALSE             0 
  70. #define TRUE              -1 
  71. #define MAX_STRING_BUFF     5000
  72. #define MAX_STR_LEN        100
  73. #define MAX_RULE_STATEMENTS     500
  74. #define MAX_HYPS        250 
  75. #define ANTECEDENT         1
  76. #define CONSEQUENT         2
  77. #define COMMENT_CHAR        '!'
  78. #define    BLANK             0x20
  79. #define EOL            0x0a
  80.  
  81. #define KEY_EOF            -2 
  82. #define LINE_ERROR        -3
  83. #define KEY_WORD_ERROR        -4
  84. #define ERROR             -5    
  85. #define STR_LEN_ERROR        -6
  86.  
  87. /*
  88. **    Other definitions of key words
  89. */
  90.  
  91. #define    AND_N            0
  92. #define    ANDIF_N          1
  93. #define    ANDIFRUN_N       2
  94. #define    ANDNOT_N         3    
  95. #define    ANDNOTRUN_N      4
  96. #define    ANDRUN_N         5
  97. #define    ANDTHEN_N        6 
  98. #define ANDTHENHYP       7
  99. #define    ANDTHENRUN_N     8
  100. #define    ANDTHENRUNHYP_N  9
  101. #define    IF_N            10
  102. #define    IFNOT_N         11
  103. #define    IFNOTRUN_N      12
  104. #define    IFRUN_N         13
  105. #define    THEN_N          14
  106. #define    THENHYP_N         15  
  107. #define THENRUN_N    16
  108. #define THENRUNHYP_N    17
  109.         
  110. /*
  111. **    Flag definitions:
  112. */
  113.  
  114. #define    STRING_TRUE     1
  115. #define    STRING_FALSE     2
  116. #define    ROUTINE_TRUE     3
  117. #define ROUTINE_FALSE     4
  118. #define STRING_TRUE_HYP  5
  119. #define ROUTINE_TRUE_HYP 6
  120.  
  121. #define NUM_KEYWORDS    18
  122.  
  123. struct    rule_statement_r
  124.         {
  125.         int flag ;   /* logical flag for inference engine */
  126.         int string ; /* offset into string buffer */
  127.         };
  128.  
  129.  
  130. /* 
  131. **    rules are compiled into the array rules in the folloiwng form:
  132. **
  133. **    antecedent-group consequent-group 
  134. **    ... 
  135. **    antecedent-group consequent-group
  136. **    end-group
  137. **
  138. **    Each group of consequences and antecedents
  139. **    are compiled in a group like the following:
  140. **
  141. **    flag pointer flag pointer ... flag pointer 0-flag 0-pointer
  142. **
  143. **    The end-group is merely:
  144. **
  145. **    0-flag 0-pointer 0-flag 0-pointer 0-flag 0-pointer
  146. **
  147. **    flags are used by the inference engine to determine what to
  148. **    do with the following string pointer.  
  149. **    string pointers are merely offsets into the string array.
  150. **    The pointers may either point
  151. **    to a string which is a rule statement such as "the animal has wings"
  152. **    or is a UNIX pathname for a particular routine which is to be
  153. **    executed such as "/g1/hageman/Diagnostics/Disk1diag".   This
  154. **    routine will then be executed and will return either a true or
  155. **    false indication.  Latter versions of the inference engin may be
  156. **    capable of returning more than this via some pipe-line mechanism or
  157. **    other.
  158. **
  159. **    Once an anicedent whether string or routine is verified it is placed
  160. **    in either a known-true or known-false stack for later verification 
  161. **    in other rules which use them.  In short they only have to be verified
  162. **    once.
  163. **
  164. **    Examples of a rule structure are:
  165. **
  166. **    IFNOT the animal is a bird
  167. **    AND the animal has wings
  168. **    ANDNOT the animal lives in caves
  169. **    AND the animal is nocternal
  170. **    THEN the animal is a bat
  171. **    IF the animal is a bat
  172. **    ANDRUN /g1/hageman/Src/Expert/speed_of_bat
  173. **    THENHYP the bat is out of hell
  174. **    IF the animal is a bat
  175. **    ANDNOTRUN /g1/hageman/Src/Expert/speed_of_bat
  176. **    THENHYP the bat is out of cave
  177. **
  178. */
  179.