|
|
pl:miw:2009:miw09_xtt_clips [2009/08/25 13:41] jsi08 |
pl:miw:2009:miw09_xtt_clips [2019/06/27 15:50] |
====== MIW 2009 XTT_CLIPS ====== | |
*Zrealizował: [[mfabia@student.agh.edu.pl|Maciej Fabia]] (4RI) | |
| |
Analyze how to design CLIPS and Jess rules with XTT2. | |
Model HeKatE cases in Clips/Jess | |
| |
====== Prezentacja ====== | |
[[pl:miw:2009:miw09_xtt_clips:prezentacja|Prezentacja wyników projektowych]] | |
| |
====== Sprawozdanie ====== | |
===== Przykłady systemów ekspertowych w CLIPS ===== | |
Aby uruchomić program w CLIPS, należy: | |
- otworzyć plik z rozszerzeniem "clp", | |
- wybrać z menu Buffer->Load Buffer, | |
- Execution->Run. | |
| |
Jeśli uruchamiamy program ponownie, musimy wyczyścić listę faktów poleceniem Execution->Reset. | |
| |
==== Prosty system wybierający metodę leczenia ==== | |
| |
=== Przeznaczenie === | |
System poszerza bazę wiedzy zadając pytania na temat stanu zdrowia chorego. W zależności od udzielonych | |
odpowiedzi potrafi zdiagnozować grypę, odrę, alergię, oraz zaleca odpowiednią terapię. | |
| |
| |
=== Właściwości === | |
System posiada 15 reguł, w tym: | |
* 4 reguły bezargumentowe - są aktywowane po każdym uruchomieniu programu. Każda z nich zadaje pytanie i po uzyskaniu odpowiedzi wstawia odpowiedni fakt, | |
* 5 reguł jednoargumentowych, | |
* 5 reguł dwuargumentowe, | |
* 1 reguła trójargumentowa. | |
| |
Do liczby argumentów nie wliczałem deklaracji priorytetów. | |
| |
Trzy reguły posiadają zmodyfikowany priorytet: | |
* "Measles" - diagnozowanie odry. Posiada podwyższony priotytet, ponieważ w pozostałych regułach założono, że chory nie choruje na odrę. | |
* "Allergy1" - obniżony priorytet. Jest sprawdzana jako ostatnia spośród reguł diagnozujących. | |
* "None" - obniżony priotytet. Sprawdza, czy zdiagnozowano chorobę. Jeśli nie, zaleca wizytę u lekarza. Do poprawnego działania musi zostać aktywowana na końcu. | |
| |
=== Kod programu=== | |
<code> | |
(defrule GetTemperature | |
=> | |
(printout t "Enter patient temperature: ") | |
(bind ?response (read)) | |
(assert (temperature ?response))) | |
| |
(defrule GetSpots | |
=> | |
(printout t "Does the patient have spots (yes or no): ") | |
(bind ?response (read)) | |
(assert (spots ?response))) | |
| |
(defrule GetRash | |
=> | |
(printout t "Does the patient have a rash (yes or no): ") | |
(bind ?response (read)) | |
(assert (rash ?response))) | |
| |
(defrule GetSoreThroat | |
=> | |
(printout t "Does the patient have a sore throat (yes or no): ") | |
(bind ?response (read)) | |
(assert (sore_throat ?response))) | |
| |
; We can also ask for certain information only if necessary. For example, | |
; it doesn't make sense to ask whether the patient has been innoculated | |
; unless there is a possiblity of measles. | |
| |
(defrule GetInnoculated | |
(fever high) | |
(spots yes) | |
=> | |
(printout t "Has the patient been innoculated for measles (yes or no): ") | |
(bind ?response (read)) | |
(assert (innoculated ?response))) | |
| |
; Rules for concluding fever from temperature. | |
| |
; Note that these rules find the patient temperature, and then bind | |
; it to ?t. The next part uses the test keyword to evaluate the | |
; conditional expression as true or false. | |
| |
(defrule Fever1 | |
(temperature ?t) | |
(test (>= ?t 101)) | |
=> | |
(assert (fever high)) | |
(printout t "High fever diagnosed" crlf)) | |
| |
(defrule Fever2 | |
(temperature ?t) | |
(test (and (< ?t 101) (> ?t 98.6))) | |
=> | |
(assert (fever mild)) | |
(printout t "Mild fever diagnosed" crlf)) | |
| |
; Rules for determining diagnosis on the basis of patient symptoms | |
; Salience added to give this rule priority | |
| |
(defrule Measles | |
(declare (salience 100)) | |
(spots yes) | |
(innoculated no) | |
(fever high) | |
=> | |
(assert (diagnosis measles)) | |
(printout t "Measles diagnosed" crlf)) | |
| |
; Modified to only fire if no measles | |
| |
(defrule Allergy1 | |
(declare (salience -100)) | |
(and (spots yes) | |
(not (diagnosis measles))) | |
=> | |
(assert (diagnosis allergy)) | |
(printout t "Allergy diagnosed from spots and lack of measles" crlf)) | |
| |
(defrule Allergy2 | |
(rash yes) | |
=> | |
(assert (diagnosis allergy)) | |
(printout t "Allergy diagnosed from rash" crlf)) | |
| |
(defrule Flu | |
(sore_throat yes) | |
(fever mild|high) | |
=> | |
(assert (diagnosis flu)) | |
(printout t "Flu diagnosed" crlf)) | |
| |
; Rules for recommedaing treatments on the basis of | |
; Diagnosis facts created. | |
| |
(defrule Penicillin | |
(diagnosis measles) | |
=> | |
(assert (treatment penicillin)) | |
(printout t "Penicillin prescribed" crlf)) | |
| |
(defrule Allergy_pills | |
(diagnosis allergy) | |
=> | |
(assert (treatment allergy_shot)) | |
(printout t "Allergy shot prescribed" crlf)) | |
| |
(defrule Bed_rest | |
(diagnosis flu) | |
=> | |
(assert (treatment bed_rest)) | |
(printout t "Bed rest prescribed" crlf)) | |
| |
(defrule None | |
(declare (salience -100)) | |
(not (diagnosis ?)) | |
=> | |
(printout t "No diagnosis possible -- consult human expert" crlf)) | |
</code> | |
| |
====== Spotkania ====== | |
[[pl:miw:2009:miw09_xtt_clips:spotkania|Notatki ze spotkań projektowych]] | |
| |
====== Materiały ====== | |