Question: import csv import clips # Load datasets def load _ csv ( file _ path ) : data = [ ] with open ( file

import csv
import clips
# Load datasets
def load_csv(file_path):
data =[]
with open(file_path, 'r') as file:
reader = csv.reader(file)
next(reader) # Skip header
for row in reader:
data.append(row)
return data
# Load CSV data
disease_symptom_data = load_csv('Dataset/dataset.csv')
disease_desc_data = load_csv('Dataset/symptom_Description.csv')
symptom_precaution_data = load_csv('Dataset/symptom_precaution.csv')
symptom_severity_data = load_csv('Dataset/symptom-severity.csv')
disease_symptom_mapping ={}
for row in disease_symptom_data:
disease = row[0]
symptoms =[symptom for symptom in row[1:] if symptom]
disease_symptom_mapping[disease]= symptoms
# Load symptom-disease mapping
symptom_disease_mapping ={}
for row in disease_symptom_data:
disease = row[0]
symptoms =[symptom for symptom in row[1:] if symptom]
for symptom in symptoms:
if symptom in symptom_disease_mapping:
symptom_disease_mapping[symptom].append(disease)
else:
symptom_disease_mapping[symptom]=[disease]
# Load symptom descriptions
symptom_descriptions ={}
for row in disease_desc_data:
symptom_descriptions[row[0]]= row[1]
# Load symptom precautions
symptom_precautions ={}
for row in symptom_precaution_data:
symptom_precautions[row[0]]= row[1:]
symptom_severity ={}
for row in symptom_severity_data:
symptom_severity[row[0]]= int(row[1])
# Define templates
template_Disease =("""
(deftemplate Disease
(slot name)
(multislot symptoms)
(slot description (type STRING))
(multislot precautions))
""")
template_Symptom =("""
(deftemplate Symptom
(slot name)
(multislot diseases)
(slot description (type STRING))
(multislot precautions)
(slot severity (type INTEGER)))
""")
template_DiagnosedDisease =("""
(deftemplate DiagnosedDisease
(slot name))
""")
# Initialize CLIPS environment
env = clips.Environment()
env.build(template_Disease)
env.build(template_Symptom)
env.build(template_DiagnosedDisease)
disease_facts =[]
symptom_facts =[]
templateDisease = env.find_template("Disease")
templatesymptom = env.find_template("Symptom")
# Assert Symptom facts
for symptom, diseases in symptom_disease_mapping.items():
description = symptom_descriptions.get(disease,[])
precautions = symptom_precautions.get(disease,[])
severity = symptom_severity.get(symptom,0)
fact = templatesymptom.assert_fact(name=symptom, diseases=diseases, description=description, precautions=precautions, severity=severity)
symptom_facts.append(fact)
# Assert Disease facts
for disease, symptoms in disease_symptom_mapping.items():
description = symptom_descriptions.get(disease,"")
precautions = symptom_precautions.get(disease,[])
fact = templateDisease.assert_fact(name=disease, symptoms=symptoms, description=description, precautions=precautions)
disease_facts.append(fact)
# Define inference rule using CLIPS Python API
infer_disease =("""
(defrule infer-disease
(not (diagnosed))
(Symptom (name ?symptom)(severity ?severity&:(>=?severity 0)))
(Symptom (name ?symptom2)(severity ?severity&:(>=?severity 0)))
(Disease (symptoms $?disease_symptoms)(precautions $?precautions)(name ?disease)(description ?description))
(test (member$ ?symptom ?disease_symptoms))
=>
(assert (DiagnosedDisease (name ?disease)))
(printout t "Diagnosed Disease: "?disease crlf)
(printout t "Symptom: " $?disease_symptoms crlf)
(printout t "Precautions: "?precautions crlf)
(printout t "Description: "?description crlf)
(assert (diagnosed))
(printout t "Diagnosed Disease asserted." crlf)
)
""")
env.build(infer_disease)
template = env.find_template('Symptom')
# List of symptoms
symptoms_to_assert =[" acidity"]
# Iterate over the list of symptoms
for symptom in symptoms_to_assert:
# Assert a fact for each symptom
fact = template.assert_fact(name=symptom)
assert fact['name']== symptom
env.run()
Develop a user interface for your expert system using a Python library of your choice, such as Tkinter, This interface can be a desktop GUI
1) The interface should be interactive: prompting users to input/choose their symptoms and providing them with relevant information about diseases, including names, symptoms, precautions, and descriptions.
2) The symptom list should be dynamic: after a user responds to or selects a symptom, the list should be updated to exclude any irrelevant symptoms. The symptom list is sorted based on their severity.
b
Every symptom has a white space before their first later make sure that it is being added once a symptom has been chosen in the GUI use

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!