Symptom Matcher

From UBC Wiki

CPSC 312 — Project 2


Rithikha Rajamohan and Bashara Hussain

What is the problem?

Given a description of disease, we wanted to create a program that identifies the possible diagnosis for a patient. Our program takes in information regarding the patient’s symptoms and their duration, and checks whether they match a certain disease inside of our knowledge base.

What is the something extra?

We added a dynamic knowledge base so that if a patient gives us symptoms which don’t exist in our database, we will use the patient’s answer to extend it. This functionality allows our program to learn from the queries it is asked and grow as it encounters new situations by adding new logical branches.

What did we learn from doing this?

We learnt that Prolog is ideal for natural language processing because it relies on search trees based on logical consequences. The database is an extension of prolog in that it will search for variable bindings that make the patients query true, and if it’s unable to find such a binding, it will backtrack, revert previous actions, and try again with the next alternative.

We also learned about how individual facts, which may not carry much meaning by themselves, can be linked to other parts of the database and other facts to create meaningful relationships.

Through our final project we learned more about difference lists which is a querying technique that we used to split up a given sentence into individual parts, and in our case simplify the sentence to key phrases and terms, in order to interpret the query and provide a logical answer.


We found working with Prolog to be relatively easy as the syntax is simple and concise. Prolog was created specifically for natural language processing programs and parsing and translating human text. The built in backtracking features that Prolog has also made it useful for debugging and trying out different ways of parsing the text and giving back a range of possible diagnoses.

Links to code

Sample Queries

Ive had joint pain for years

I feel I have had concentration issues for years

I have had itchy spots everywhere for over a month

I have had itchy spots everywhere since last week

I have had a fever for over a week

For disease queries not currently in our database, see below:

ex. Query asked: I feel fatigued for years

this will fail, next type in: new(Diagnosis) and then type in the following for each prompt:

- Symptom prompt: fatigued

- Duration prompt: years

- Diagnosis prompt: anemia

then, try running the original query again.