Advertisement
VladimirKostovsky

PROLOG_lab2_var5(NT)

Feb 20th, 2024
1,586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 1.84 KB | None | 0 0
  1. % Domains
  2. list = list
  3.  
  4. % Predicates
  5. nondeterm medicine(symbol, integer, list, list, integer, symbol).
  6. nondeterm recommended_medicine(list, integer, symbol).
  7. nondeterm has_contraindications(symbol, list).
  8. nondeterm patient_has(symbol).
  9.  
  10. % Clauses
  11. patient_has('Pregnancy').
  12. patient_has('Peptic ulcer disease').
  13. patient_has('Allergy').
  14. % Add more facts as needed
  15.  
  16. % Contraindications for medicines
  17. has_contraindications('Aspirin', ['Pregnancy']).
  18. has_contraindications('Paracetamol', []).
  19. has_contraindications('Ibuprofen', ['Peptic ulcer disease']).
  20. has_contraindications('Cetirizine', ['Pregnancy']).
  21. has_contraindications('Amoxicillin', ['Allergy']).
  22. has_contraindications('Loratadine', []).
  23.  
  24. % Medicine facts
  25. medicine('Aspirin', 18, ['Headache', 'Fever'], ['Pregnancy'], 50, 'Available').
  26. medicine('Paracetamol', 12, ['Headache', 'Fever'], [], 30, 'Available').
  27. medicine('Ibuprofen', 16, ['Headache', 'Toothache'], ['Peptic ulcer disease'], 40, 'Available').
  28. medicine('Cetirizine', 6, ['Allergy'], ['Pregnancy'], 25, 'Available').
  29. medicine('Amoxicillin', 20, ['Throat', 'Fever'], ['Allergy'], 60, 'Available').
  30. medicine('Loratadine', 10, ['Allergy'], [], 35, 'Not available').
  31.  
  32. % Recommended medicines rules
  33. recommended_medicine(Symptoms, Age, Medicine) :-
  34.     medicine(Medicine, AgeLimit, Symptoms, Contraindications, _, 'Available'),
  35.     Age >= AgeLimit,
  36.     not(has_contraindications(Medicine, Contraindications)).
  37.  
  38. % Check for contraindications
  39. has_contraindications(_, []) :- !.
  40. has_contraindications(Medicine, [Contraindication | Rest]) :-
  41.     patient_has(Contraindication),
  42.     write('Contraindication for '), write(Medicine), write(': '), writeln(Contraindication),
  43.     has_contraindications(Medicine, Rest).
  44.  
  45. % Goal
  46. goal
  47.     recommended_medicine(['Fever'], 22, Medicine).
  48.  
  49. % ERRORS:
  50. % E;Test_Goal, pos: 11, 3 Illegal keyword
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement