Question: import csv import clips # Load datasets def load _ csv ( file _ path ) : data = [ ] with open ( file
import csv
import clips
# Load datasets
def loadcsvfilepath:
data
with openfilepath, r as file:
reader csvreaderfile
nextreader # Skip header
for row in reader:
data.appendrow
return data
# Load CSV data
diseasesymptomdata loadcsvDatasetdatasetcsv
diseasedescdata loadcsvDatasetsymptomDescription.csv
symptomprecautiondata loadcsvDatasetsymptomprecaution.csv
symptomseveritydata loadcsvDatasetsymptomseverity.csv
diseasesymptommapping
for row in diseasesymptomdata:
disease row
symptoms symptom for symptom in row: if symptom
diseasesymptommappingdisease symptoms
# Load symptomdisease mapping
symptomdiseasemapping
for row in diseasesymptomdata:
disease row
symptoms symptom for symptom in row: if symptom
for symptom in symptoms:
if symptom in symptomdiseasemapping:
symptomdiseasemappingsymptomappenddisease
else:
symptomdiseasemappingsymptomdisease
# Load symptom descriptions
symptomdescriptions
for row in diseasedescdata:
symptomdescriptionsrow row
# Load symptom precautions
symptomprecautions
for row in symptomprecautiondata:
symptomprecautionsrow row:
symptomseverity
for row in symptomseveritydata:
symptomseverityrow introw
# Define templates
templateDisease
deftemplate Disease
slot name
multislot symptoms
slot description type STRING
multislot precautions
templateSymptom
deftemplate Symptom
slot name
multislot diseases
slot description type STRING
multislot precautions
slot severity type INTEGER
templateDiagnosedDisease
deftemplate DiagnosedDisease
slot name
# Initialize CLIPS environment
env clips.Environment
env.buildtemplateDisease
env.buildtemplateSymptom
env.buildtemplateDiagnosedDisease
diseasefacts
symptomfacts
templateDisease env.findtemplateDisease
templatesymptom env.findtemplateSymptom
# Assert Symptom facts
for symptom, diseases in symptomdiseasemapping.items:
description symptomdescriptions.getdisease
precautions symptomprecautions.getdisease
severity symptomseverity.getsymptom
fact templatesymptom.assertfactnamesymptom, diseasesdiseases, descriptiondescription, precautionsprecautions, severityseverity
symptomfacts.appendfact
# Assert Disease facts
for disease, symptoms in diseasesymptommapping.items:
description symptomdescriptions.getdisease
precautions symptomprecautions.getdisease
fact templateDisease.assertfactnamedisease, symptomssymptoms, descriptiondescription, precautionsprecautions
diseasefacts.appendfact
# Define inference rule using CLIPS Python API
inferdisease
defrule inferdisease
not diagnosed
Symptom name symptomseverity severity&:severity
Symptom name symptomseverity severity&:severity
Disease symptoms $diseasesymptomsprecautions $precautionsname diseasedescription description
test member$ symptom diseasesymptoms
assert DiagnosedDisease name disease
printout t "Diagnosed Disease: disease crlf
printout t "Symptom: $diseasesymptoms crlf
printout t "Precautions: precautions crlf
printout t "Description: description crlf
assert diagnosed
printout t "Diagnosed Disease asserted." crlf
env.buildinferdisease
template env.findtemplateSymptom
# List of symptoms
symptomstoassert acidity"
# Iterate over the list of symptoms
for symptom in symptomstoassert:
# Assert a fact for each symptom
fact template.assertfactnamesymptom
assert factname 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
The interface should be interactive: prompting users to inputchoose their symptoms and providing them with relevant information about diseases, including names, symptoms, precautions, and descriptions.
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
