I am trying following code:
disease(flu, [fever, chills, nausea]).
disease(cold, [cough, runny_nose, sore_throat]).
disease(hungover, [headache, nausea, fatigue]).
getSymptoms([Symptom|List]):-
writeln('Enter Symptom:'),
read(Symptom),
dif(Symptom,stop),
getSymptoms(List),
intersection(disease(_,List1), List, Outlist).
getSymptoms([]).
The entry method is from: Creating a list from user input with swi-prolog
The user starts with:
getSymptoms(L).
I need to collect patients symptoms (say following are entered: fever, chills)
I then need to compare this list with symptom list of each disease and find out how many symptoms are common between 2 lists.
The getSymptoms(L)
is collecting symptoms all right but is not giving intersection and returning an empty list:
?- getSymptoms(L).
Enter Symptom:
|: fever.
Enter Symptom:
|: stop.
L = [].
Following also did not work:
intersection(findall(L,disease(_,L),Out), List, Outlist).
How can I correct this? Thanks for your help.
Edit: with code suggested by @wouter_beek, I get:
disease(_, List1),
sort(List1, SList1),
sort(List, SList),
intersection(SList1, SList, OutList).
?- getSymptoms(L).
Enter Symptom:
|: fever.
Enter Symptom:
|: cough.
Enter Symptom:
|: stop.
L = [fever, cough] ;
L = [fever, cough] ;
L = [fever, cough] ;
L = [fever, cough] ;
L = [fever, cough] ;
L = [fever, cough] ;
L = [fever, cough] ;
L = [fever, cough] ;
L = [fever, cough] ;
L = [fever] ;
L = [fever] ;
L = [fever] ;
L = [].
I want disease with number of common symptoms to be shown.