Report of Introduction and methods Explination.docx
This code is an implementation of an expert system which is Applying Forward Chaining using the
experta library in Python. The system prompts the user with a series of questions regarding their
symptoms, and then uses rules to determine what disease the user might have based on their
The system is able to identify 14 diseases: Jaundice, Alzheimer's, Arthritis, Asthmas, Corona Virus,
Diabetes, Epilepsy, Glaucoma, Heart Disease, Head Stroke, Hyper Hypothyroidism, Hypothermia
Jaundice, Sinusitis and Tuberculosis, and discuss each disease after detect the disease of the user and
help them about the next step they should do. The rules for each disease are defined using a series of
Fact objects that represent the user's symptoms. If all of the facts for a given rule match the user's
symptoms, the system declares a Fact object representing the matched disease.
Overall, this Project appears to be a simple implementation of an expert system, but it only covers a very
limited range of diseases and symptoms.
The __init__ method of the Greetings class initializes the object with a symptom map, a function to call if
no disease is matched, a function to get treatments, and a function to get details about the matched
The system uses a series of Rule objects to match the user's symptoms to a disease. The @Rule
decorator is used to define each rule, and the Fact class is used to represent a user's response to a
symptom. The salience parameter is used to give priority to certain rules over others.
The DefFacts decorator is used to define initial facts and actions for the system. In this case, the system
introduces itself and prompts the user for input.
The preprocess() function reads in the disease information from the text files and creates several
dictionaries that map from symptoms to diseases, from diseases to descriptions, and from diseases to
treatments. These dictionaries are then used by the other functions to provide the diagnostic output.
The identify_disease() function takes in one or more symptoms as arguments, creates a list of those
symptoms, converts that list to a string, looks up the disease associated with that string in the symptom
map dictionary, and returns the name of the disease.
The get_details() and get_treatments() functions take in a disease name as an argument and return the
description and treatments for that disease, respectively.
The if_not_matched() function is called when the symptom input doesn't match any disease in the
system. It takes in a disease name (which is actually "None" in this case) and uses the get_details() and
get_treatments() functions to print information about the most probable disease based on the
symptoms that were input.
2. The if __name__ == "__main__": block initializes the program by calling preprocess() to load the disease
information and create the necessary dictionaries. It then creates an instance of the Greetings class
(which is defined in the greetings.py file) and enters a loop that allows the user to input symptoms and
receive diagnostic output. The loop continues until the user enters "no" when asked if they would like to
diagnose more symptoms.