2

I have the code below in Prolog and I made a GUI in Java.

In this gui I have some checkboxes with symptoms and I want to pass only clicked symptoms in the list of findDiseases predicate. Can anyone tell me how I can do that? The only thing that I know is how to call start predicate..

start:-
   findDiseases([headache,weakness,heartbeat], Diseases),
   one_occurrence(Diseases, DiseasesNoDup),
   write(DiseasesNoDup).

findDiseases(PositiveSymptoms, Diseases) :-
   findDiseases(PositiveSymptoms, Diseases, []).

findDiseases([], Answer, Answer).
findDiseases([H|T], Diseases, Answer) :-
   findall(
      Disease,
      (
         kb(Disease,Simptoms_list,Feauture_list),
         (member(H,Simptoms_list);member(H,Feauture_list))
      ),
      As),
   append(As, Answer, NewAnswer),
   findDiseases(T, Diseases, NewAnswer).

% kb(diagnosis,symptoms_list,features_list).    
kb(iron_defficiency,
   [headache, dizziness, cold, weakness, fatigue, heartbeat, loose_concentration, swelling_tongue, breath],
   [gender, pregnancy, vitamin_poor_diet, fe, feritin, b12, hb, hct, mcv, plt, wbc, rtc]
).

kb(thalassemia,
   [loose_appetite, painful_spleen, pale_skin],
   [gender, pregnancy, parent1, parent2, face_features, fe, feritin, b12, hb, hct, mcv, plt, wbc, hbf, hba1, hba2, rtc]
).

kb(minor_thalassemia,
   [headache, fatigue, weakness, pale_skin, swelling_tongue, cold, heartbeat, loose_concentration, breath, dizziness],
   [vitamin_poor_diet, gender, pregnancy, parent1, parent2, hbaf, hba2, fe, feritin, b12, hb, hct, mcv, plt, wbc, rtc]
).

kb(drepanocytocis,
   [headache, weakness, fatigue, pale_skin, swelling_tongue, cold, loose_concentration, breath, dizziness, heartbeat, ulcers, painful_spleen, pain_in_extrimity],
   [gender, pregnancy, vitamin_poor_diet, shape_rbc, hbs, hbf, fe, feritin, b12, hb, hct, mcv, plt, wbc, rtc]
).


yposynolo([X],[X]).
yposynolo([H|Tail],[X]) :-
   (H==X),
   yposynolo(Tail,[X]).

yposynolo([X],[H|Tail]) :- member(X,[H|Tail]).

yposynolo([H1|Tail1],[H2|Tail2]) :-
   member(H1,[H2|Tail2]),
   yposynolo(Tail1,[H2|Tail2]).

same_elements(List1,List2) :-
   yposynolo(List1,List2),
   yposynolo(List2,List1).

unique_appearance([X]).
unique_appearance([H|Tail]) :-
   (\+member(H,Tail)),
   unique_appearance(Tail).

one_occurrence([H1|Tail1],[H2|Tail2]) :-
   same_elements([H1|Tail1],[H2|Tail2]),
   unique_appearance([H2|Tail2]).
false
  • 10,264
  • 13
  • 101
  • 209
Debbie Mp
  • 163
  • 1
  • 11
  • What are you using ? SWI-Prolog and JPL, or Jekejeke, PrologCafe, tuProlog, or what else ? – CapelliC Mar 11 '16 at 09:14
  • SWI-Prolog and JPL – Debbie Mp Mar 11 '16 at 09:26
  • Have you taken a look at the [javadoc for Query](http://www.swi-prolog.org/packages/jpl/java_api/javadoc/jpl/Query.html)? – SQB Mar 11 '16 at 11:30
  • I know how to pass parameters but my problem is how to pass only the checked symptoms.. If i click at headache and fatigue , then pass only headache and fatigue nothing more.. how can i tell this in java? – Debbie Mp Mar 11 '16 at 11:33
  • Ah, so this is really a Java question, not a Prolog question. Basically, just loop through all of your checkboxes and only add the checked ones to your array of parameters to pass. – SQB Mar 11 '16 at 12:01
  • Can you give me an example of this loop? – Debbie Mp Mar 11 '16 at 12:12
  • This question seems fixated on the Prolog, but it's a question about how to iterate through your checkboxes. What Java user interface kit are you using? Perhaps show a sample of code you have in that area. But this should be very simple. Checkbox objects have a "checked" state. ou can look this up in the online Java documentation. – lurker Mar 11 '16 at 15:11
  • I am using netbeans... I am thinking to define a string array and when a checkbox is selected then array = array + checkbox value... but I don't know if this works.. – Debbie Mp Mar 11 '16 at 19:20
  • Perhaps you can have a look at [this](http://stackoverflow.com/questions/8930101/get-all-selected-checkboxes-in-java) question for getting the selected checkboxes. Another way is to use an ItemListener, specified in [this](http://stackoverflow.com/a/30355599/1153801) question. – SND Mar 26 '16 at 10:29
  • I use an arraylist and Item State Changed listener for every checkbox and when a checkbox is selected i add the text of it to the list. – Debbie Mp Mar 28 '16 at 06:45

0 Answers0