Python PyKnow 诊断引擎示例 - 诊断常见疾病
处理一下bug将代码发过来\n\npython\nfrom pyknow import *\n\nclass Symptom(Fact):\n """症状事实类"""\n pass\n\nclass Disease(Fact):\n """疾病事实类"""\n pass\n\nclass DiagnosisEngine(KnowledgeEngine):\n """诊断引擎类"""\n\n @Rule(Disease('flu') & Symptom('cough') & Symptom('fever'))\n def diagnose_flu(self):\n self.declare(Disease('Influenza'))\n\n @Rule(Disease('cold') & Symptom('cough') & Symptom('sore throat'))\n def diagnose_cold(self):\n self.declare(Disease('Common Cold'))\n\n @Rule(Disease('allergy') & Symptom('sneezing') & Symptom('itchy eyes'))\n def diagnose_allergy(self):\n self.declare(Disease('Allergic Rhinitis'))\n\n @Rule(Disease('unknown') & Symptom('unknown'))\n def diagnose_unknown(self):\n self.declare(Disease('Unknown Disease'))\n\n# 实例化诊断引擎\nengine = DiagnosisEngine()\n\n# 用户输入症状信息\nengine.reset()\nengine.declare(Symptom('cough'))\nengine.declare(Symptom('fever'))\n\n# 运行推理引擎\nengine.run()\n\n# 输出诊断结果\nfor fact in engine.facts:\n if isinstance(fact, Disease):\n print("Diagnosis: ", fact)\n
原文地址: https://www.cveoy.top/t/topic/pwQu 著作权归作者所有。请勿转载和采集!