Вы находитесь на странице: 1из 2

d i a g n o s e :− h y p o t h e s i z e ( D i s e a s e ) ,

w r i t e ( ’ I g u e s s t h a t you a r e s u f f e r i n g from : ’) ,
write ( Disease ) ,
nl ,
undo .

/∗ h y p o t h e s e s t o be t e s t e d ∗/
hypothesize ( malaria ) :− m a l a r i a , ! .
h y p o t h e s i z e ( dengue ) :− dengue , ! .
hypothesize ( tuberculosis ) :− t u b e r c u l o s i s , ! .
h y p o t h e s i z e ( unknown ) . /∗ no d i a g n o s i s ∗/

/∗ d i s e a s e i d e n t i f i c a t i o n r u l e s ∗/
m a l a r i a :− f e v e r ,
headache ,
muscle pain ,
chills ,
v e r i f y ( vomiting ) .

dengue :− fever ,
headache ,
muscle pain ,
verify ( skin rash ) ,
verify ( joint pain ).

t u b e r c u l o s i s :− f e v e r ,
chills ,
verify ( weight loss ) ,
v e r i f y ( weakness ) ,
v e r i f y ( bad cough ) .

/∗ c l a s s i f i c a t i o n r u l e s ∗/
fever :− v e r i f y ( h i g h f e v e r ) , ! .
fever :− v e r i f y ( f e v e r w i t h c h i l l s ) .

headache :− v e r i f y ( h e a d a c h e i n t h e m o r n i n g ) , ! .
headache :− v e r i f y ( v o m i t i n g ) ,
verify ( shaking chills ).

muscle pain :− verify ( full body pain ) , ! .


muscle pain :− fever ,
headache .
c h i l l s :− fever , ! .
c h i l l s :− verify ( weight loss ).
/∗ how t o ask q u e s t i o n s ∗/
ask ( Q u e s t i o n ) :−
w r i t e ( ’ Does t h e p a t i e n t have t h e f o l l o w i n g symptoms : ’) ,
write ( Question ) ,
write ( ’? ’) ,
r e a d ( Response ) ,
nl ,
( ( Response == y e s ; Response == y )
−>
a s s e r t ( yes ( Question ) ) ;
a s s e r t ( no ( Q u e s t i o n ) ) , f a i l ) .

:− dynamic y e s / 1 , no / 1 .

/∗ How t o v e r i f y something ∗/
v e r i f y ( S ) :−
( yes (S)
−>
true ;
( no ( S )
−>
fail ;
ask ( S ) ) ) .

/∗ undo a l l y e s /no a s s e r t i o n s ∗/
undo :− r e t r a c t ( y e s ( ) ) , f a i l .
undo :− r e t r a c t ( no ( ) ) , f a i l .
undo .
Enter the prolog environment and execute our Expert System.
prolog medex.pl
?− d i a g n o s e .
Does t h e p a t i e n t have t h e f o l l o w i n g symptoms : h i g h f e v e r ? y .

Does t h e p a t i e n t have t h e f o l l o w i n g symptoms : h e a d a c h e i n t h e m o r n i n g ? y .

Does t h e p a t i e n t have t h e f o l l o w i n g symptoms : f u l l b o d y p a i n ? n .

Does t h e p a t i e n t have t h e f o l l o w i n g symptoms : v o m i t i n g ? n .

Does t h e p a t i e n t have t h e f o l l o w i n g symptoms : s k i n r a s h ? y .

Does t h e p a t i e n t have t h e f o l l o w i n g symptoms : j o i n t p a i n ? y .

I g u e s s t h a t you a r e s u f f e r i n g from : dengue


true .

?− d i a g n o s e .
Does t h e p a t i e n t have t h e f o l l o w i n g symptoms : h i g h f e v e r ? y .

Does t h e p a t i e n t have t h e f o l l o w i n g symptoms : h e a d a c h e i n t h e m o r n i n g ? n .

Does t h e p a t i e n t have t h e f o l l o w i n g symptoms : v o m i t i n g ? n .

Does t h e p a t i e n t have t h e f o l l o w i n g symptoms : w e i g h t l o s s ? y .

Does t h e p a t i e n t have t h e f o l l o w i n g symptoms : weakness ? y .

Does t h e p a t i e n t have t h e f o l l o w i n g symptoms : bad cough ? y .

I g u e s s t h a t you a r e s u f f e r i n g from : t u b e r c u l o s i s
true .

Try other combinations. Don’t forget the dot.

Вам также может понравиться