home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / util / inferng / expert.h < prev    next >
Encoding:
C/C++ Source or Header  |  1986-02-01  |  5.1 KB  |  164 lines

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