1

I have a Prolog knowledge base with some "symptom" facts called facts.pl. Here is an example of my KB:

symptom("Typhoid", "muscle_pain").
symptom("Typhoid", "bloating").
symptom("Meningitis", "headache").
symptom("Meningitis", "fever").
symptom("Meningitis", "stiff neck" ).
symptom("Measles", "cough").
symptom("Measles", "runny_nose").

I have written a short prolog program in another file called "diseaseSearch.pl". This program consults facts.pl and is supposed to allow the user to enter a disease name and prints the disease's corresponding symptoms to the screen.

My code:

:- write('loading disease database'), nl.
:- [facts].
:- write('disease database loaded'), nl, nl.

getsymptoms:-
    write('>   Enter a diseae name followed by a period.'), nl,
    write('For Example: Measles'), nl,
    write('Disease Name?:'),
    read(Input), nl,
    symptom(Input,Output),
    write(Output).

If I enter "Measles." the output should be "cough" and "runny_nose". However, with the code above no matter which disease I enter it always returns the result from the first fact which is "muscle_pain". SWI output found here

I found a similar method from an online tutorial, I am trying to learn the basics of Prolog input and output right now. Am I on the right track? Some tips to solve this problem would be greatly appreciated!

false
  • 10,264
  • 13
  • 101
  • 209
Braxvan
  • 67
  • 14
  • 1
    Do you really enter "Measles"? Or do you enter Measles without the quotation marks? – Ben373 Nov 12 '17 at 21:58
  • Measles. without the quotation marks. Is there a better way I could annotate that to make it more clear? (I also have an image attached to show how it should be entered to the program). – Braxvan Nov 12 '17 at 22:00
  • 1
    [Related](https://stackoverflow.com/a/8309945/772868). – false Nov 12 '17 at 22:02

1 Answers1

1

I guess you are entering Measles without " " and prolog takes it as a variables. Either you should enter it with "". If you enter Measles then it's a variables but if you enter "Measles" then it's a term.

If you want to enter without annotations then you need to make a database in which you have all terms(means that they start with small letter) then you don't need annotation.

Luai Ghunim
  • 976
  • 7
  • 14