Advertisement
Griwin

PMZ_Exercise

Nov 11th, 2024 (edited)
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 4.38 KB | Software | 0 0
  1. % simptopmi
  2. symptom(flu, fever).
  3. symptom(flu, cough).
  4. symptom(flu, sore_throat).
  5.  
  6. symptom(cold, runny_nose).
  7. symptom(cold, sneezing).
  8.  
  9. symptom(pneumonia, chest_pain).
  10. symptom(pneumonia, difficulty_breathing).
  11. symptom(pneumonia, persistent_cough).
  12.  
  13. symptom(diabetes, increased_thirst).
  14. symptom(diabetes, blurry_vision).
  15.  
  16. symptom(heart_disease, chest_discomfort).
  17. symptom(heart_disease, shortness_of_breath).
  18.  
  19. % info za pacienti i riskovi faktori
  20. patient(john, fever).
  21. patient(john, cough).
  22. patient(john, sore_throat).
  23.  
  24. patient(peter, increased_thirst).
  25. patient(peter, blurry_vision).
  26.  
  27. patient(alice, fever).
  28. patient(alice, cough).
  29. patient(alice, sore_throat).
  30.  
  31. patient(bob, chest_pain).
  32. patient(bob, difficulty_breathing).
  33. patient(bob, persistent_cough).
  34.  
  35. patient(eva, chest_discomfort).
  36. patient(eva, shortness_of_breath).
  37.  
  38. patient(tom, increased_thirst).
  39. patient(tom, blurry_vision).
  40.  
  41. patient(mary, none). % bez simptomi
  42.  
  43. % hroni4ni zabolqvaniq
  44. has_chronic_condition(john, heart_disease).
  45. has_chronic_condition(mary, none).
  46. has_chronic_condition(peter, diabetes).
  47. has_chronic_condition(alice, none).
  48. has_chronic_condition(bob, none).
  49. has_chronic_condition(eva, heart_disease).
  50. has_chronic_condition(tom, diabetes).
  51.  
  52. % nasledstveni
  53. family_history(john, diabetes).
  54. family_history(peter, heart_disease).
  55. family_history(alice, none).
  56. family_history(bob, none).
  57. family_history(eva, none).
  58. family_history(tom, none).
  59.  
  60. % le4eniq na zabolqvaniq
  61. treatment(flu, rest).
  62. treatment(cold, rest).
  63. treatment(pneumonia, antibiotics).
  64. treatment(diabetes, insulin).
  65. treatment(heart_disease, surgery).
  66.  
  67.  
  68. age_group(john, adult).
  69. age_group(mary, child).
  70. age_group(peter, senior).
  71. age_group(alice, adult).
  72. age_group(bob, adult).
  73. age_group(eva, senior).
  74. age_group(tom, adult).
  75.  
  76. %proverka za simp pri pacienti
  77. has_disease(Patient, Disease) :-
  78.     patient(Patient, Symptom),
  79.     symptom(Disease, Symptom).
  80.  
  81. % proverka za riskovi faktori
  82.  
  83. has_risk_factor(Patient, heart_disease) :-
  84.     has_chronic_condition(Patient, heart_disease).
  85. has_risk_factor(Patient, heart_disease) :-
  86.     age_group(Patient, senior).
  87. has_risk_factor(Patient, Disease) :-
  88.     family_history(Patient, Disease).
  89. has_risk_factor(Patient, Disease) :-
  90.     has_chronic_condition(Patient, Disease).
  91.  
  92.  
  93. diagnose(Patient, pneumonia) :-
  94.     has_disease(Patient, pneumonia),
  95.     (   patient(Patient, chest_pain) ; patient(Patient, difficulty_breathing) ; patient(Patient, persistent_cough) ),
  96.     format("Пациентът ~w има болест pneumonia и има рискови фактори.\n", [Patient]),
  97.     !.
  98.  
  99.  
  100. diagnose(Patient, heart_disease) :-
  101.     has_disease(Patient, heart_disease),
  102.     (   patient(Patient, chest_discomfort) ; patient(Patient, shortness_of_breath) ),
  103.     format("Пациентът ~w има болест heart_disease и има рискови фактори.\n", [Patient]),
  104.     !.
  105.  
  106.  
  107. diagnose(Patient, flu) :-
  108.     has_disease(Patient, flu),
  109.     format("Пациентът ~w има болест flu и има рискови фактори.\n", [Patient]),
  110.     !.
  111.  
  112.  
  113. diagnose(Patient, diabetes) :-
  114.     has_disease(Patient, diabetes),
  115.     format("Пациентът ~w има болест diabetes и има рискови фактори.\n", [Patient]),
  116.     !.
  117.  
  118.  
  119. recommend_treatment(Patient) :-
  120.     has_chronic_condition(Patient, heart_disease),
  121.     treatment(heart_disease, Treatment),
  122.     format("Препоръчва се лечение с: ~w за заболяването heart_disease\n", [Treatment]),
  123.     !.
  124.  
  125. recommend_treatment(Patient) :-
  126.     has_disease(Patient, pneumonia),
  127.     treatment(pneumonia, Treatment),
  128.     format("Препоръчва се лечение с: ~w за заболяването pneumonia\n", [Treatment]),
  129.     !.
  130.  
  131. recommend_treatment(Patient) :-
  132.     has_disease(Patient, flu),
  133.     treatment(flu, Treatment),
  134.     format("Препоръчва се лечение с: ~w за заболяването flu\n", [Treatment]),
  135.     !.
  136.  
  137. recommend_treatment(Patient) :-
  138.     has_disease(Patient, diabetes),
  139.     treatment(diabetes, Treatment),
  140.     format("Препоръчва се лечение с: ~w за заболяването diabetes\n", [Treatment]).
  141.  
  142.  
  143. recommend_treatment(mary) :-
  144.     format("Препоръчва се общо лечение като превенция за здравето на пациента ~w.\n", [mary]).
  145.  
Tags: PMZ_Prolog
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement