popovIliya

Sample Jess diagnostic system

Dec 1st, 2021
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.79 KB | None | 0 0
  1. ;;;======================================================
  2. ;;;     Author Iliya Popov
  3. ;;;     Data created 1.12.2021
  4. ;;;     sample jess diagnostic system
  5. ;;;======================================================
  6.  
  7. ;;****************
  8. ;;* Deffunctions *
  9. ;;****************
  10.  
  11. (deffunction ask-question (?question $?allowed-values)
  12.    (printout t ?question)
  13.    (bind ?answer (read))
  14.    (if (lexemep ?answer)
  15.        then (bind ?answer (lowcase ?answer)))
  16.    (while (not (member$ ?answer ?allowed-values)) do
  17.       (printout t ?question)
  18.       (bind ?answer (read))
  19.       (if (lexemep ?answer)
  20.           then (bind ?answer (lowcase ?answer))))
  21.    ?answer)
  22.  
  23. (deffunction yes-or-no (?question)
  24.    (bind ?response (ask-question ?question да не д н))
  25.    (if (or (eq ?response да) (eq ?response н))
  26.        then да
  27.        else не))
  28.  
  29. ;;;************************
  30. ;;;* Ask the patient rules *
  31. ;;;************************
  32.  
  33. (defrule symptom-constant-hunger "Симптом Непренстанен глад"
  34.    (not (answer ?))
  35.    (not (diagnoses ?))
  36.    =>
  37.    (assert (constant-hunger (yes-or-no "Мъче ли Ви непренстанен глад (да/не)? ")))
  38. )
  39. (defrule symptom-tormenting-thirst "Симптом Мъчителна жажда"
  40.    (not (answer не))
  41.    (not (diagnoses ?))
  42.    =>
  43.    (assert (painful-thirst (yes-or-no "Имате ли мъчителна жажда (да/не)? ")))
  44. )
  45.  
  46. (defrule symptom-dry-mouth "Сухота в устата"
  47.    (not (answer не))
  48.    (not (diagnoses ?))
  49.    =>
  50.    (assert (dry-mouth (yes-or-no "Получавате ли сухота в устата (да/не)? ")))
  51. )
  52.  
  53. ;;;*******************
  54. ;;;* Diagnoses rules *
  55. ;;;*******************
  56.  
  57. (defrule normal-patients-symptoms ""
  58.    (painful-thirst не)
  59.     (constant-hunger не)
  60.     (dry-mouth не)
  61.    (not (diagnoses ?))
  62.    =>
  63.    (assert (diagnoses "Вие не сте болен от диабет тип 1.")))
  64.  
  65. (defrule patients-symptoms ""
  66.    (painful-thirst да)
  67.     (constant-hunger да)
  68.     (dry-mouth да)
  69.    (not (diagnoses ?))
  70.    =>
  71.    (assert (diagnoses "Вие сте болен от диабет тип 1.")))
  72.  
  73. (defrule no-diagnoses ""
  74.   (declare (salience -10))
  75.   (not (diagnoses ?))
  76.   =>
  77.   (assert (diagnoses "
  78. Моля отидете на лекар.")))
  79.  
  80. ;;;********************************
  81. ;;;* Run and conclusion rules     *
  82. ;;;********************************
  83.  
  84. (defrule system-banner ""
  85.   (declare (salience 10))
  86.   =>
  87.   (printout t crlf "Експертна система за дигностициране на пациент за диабет тип 1" crlf))
  88.  
  89. (defrule print-diagnoses ""
  90.   (declare (salience 10))
  91.   (diagnoses ?item)
  92.   =>
  93.   (printout t crlf "
  94. Диагноза:" crlf)
  95.   (printout t " " ?item crlf))
  96.  
  97. (reset)
  98. (run)
Advertisement
Add Comment
Please, Sign In to add comment