


版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、疾病诊断小型专家系统人工智能课程设计报告智能1001班傅宝林09091012172013.6.181内容提要此系统采用专家系统的规则库-推理机技术原理,以医学诊断为 背景,旨在作出一个简单的辅助诊断专家系统。系统的框架及界面采用的是 Java语言,调用XML里保存的知 识库和规则库。此小型的专家系统以肺结核、哮喘、食管癌、骨折等疾病的诊 断为例,展示了一个小型专家系统是如何构建的。目录1内容提要 22目的和意义 43系统的主要内容和功能 54设计流程及描述 65课程设计体会 216参考文献 222目的和意义(1) 加深理解专家系统的结构及开发过程。(2) 初步掌握知识获取的基本方法。(3) 掌
2、握产生式规则知识表示方法及其编程实现方法。(4) 初步掌握知识库的组建方法。3系统的主要内容和功能系统主要以问答的形势询问病情症状, 操作者只需要回答YES或 NO。当一趟询问完成后,系统会基于以上询问得出的事实推理出最 终的诊断结果。功能见以下截图1、2.图2 诊断结果界面4设计流程及描述1)需求分析本设计需要用高级语言编写框架及调用外部的规则库与知识库。方便起见,用java语言编写框架,用XML文件保存。2)知识获取与知识表示知识获取通过医学临床专业的同学及医学诊断专业书籍,确保专家系统的专家性。知识的表示采用的是xml语言,把事实与规则一条条保存。3)知识库的组建知识库分事实库和规则库组
3、建。疾病诊断因为有的病有交叉的症 状,所以逻辑上,从症状到诊断的过程是对一颗二叉树的搜索,当问 题回答的是YES时,就进行深度优先搜索,当回答 NO时,就转到 兄弟节点。对于无关的疾病,则回到根节点重新对下一颗子树进行搜 索。得到一种疾病的确诊就是 result,得到这个叶子节点前遍历过的 节点组成了 reasons.4)推理机制选择/编制采用的是问题引导式推理。在规则库里写的其实不是真正的规则。真正的规则蕴含在问题及前提里。为了不让“专家”问无用的问 题,每个问题都是以某个问题的答案为前提的。 这样组成了内部的因 果关系,所以真正的推理规则只与某一趟提问的最后一个问题的答案 得出的事实有关。
4、5)程序清单package专家系统_V2;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Dime nsion;import java.awt.F ont;import java.awt.eve nt.Act ion Eve nt;import java.awt.eve nt.Act ion Liste ner;import java.util.ArrayList;import javax.swi ng.JButt on;import javax.swi ng.JFrame;import javax.sw i
5、n g.JLabel;import javax.swi ng.JPa nel;import javax.swi ng.JScrollPa ne;import javax.swi ng.JTextArea;import javax.sw in g.border.L in eBorder;public class MainF rame exte nds JFrame*主界面类* param args*/public static void main( Stri ng args) Mai nF rame main = new MainF rame(); mai n.m yShow();private
6、 void myShow() exe = new Executi on();exe.i nit();this.setTitle(exe.expert_name+"专家系统"); this.setSize(380, 250);this.setDefaultCloseOperati on (3);this.setResizable(false);this.setLocati on RelativeTo (n ull);this.setLayout (new BorderLayout();JPa nel jp_ce nter = new JPa nel(); jp_ce nter
7、.setBackgro un d(Color.white);jp_ce nter.setPreferredSize( new Dime nsion(380,250);jp_ce nter.setLayout (n ull);jl = new JLabel();jl.setText(”请回答下列问题:”);jl.setFont(new Font(Font.DIALOG ,Font.BOLD,25);jl.setForegro un d(Color.blue);jl.setBou nds(10, 10, 200, 30);jta=new JTextArea();JScrollPa ne js=ne
8、w JScrollPa ne(jta);jta.setEditable(false);jta.setBorder( new Lin eBorder(Color.black);jta.setL in eWrap(true);jta.setFo nt(new Fon t(Fo nt.DIALOG,Fo nt.BOLD,20);js.setBou nds(20, 50, 330, 100);jb1 = new JButt on ("YES");jb1.setBou nds(100, 170, 60, 30);jb1.addAct ion Liste ner(l);jb2 = ne
9、w JButto n( "NO");jb2.setBou nds(200, 170, 60, 30);jb2.addAct ion Liste ner(l);jp_ce nter.add(jl);jp_ce nter.add(js);jp_ce nter.add(jb1);jp_ce nter.add(jb2);this.add(jp_ce nter,BorderLayout.CENTER);problem=this.i nitProblem(); this.setVisible(true);private Problem ini tProblem()for(i nt i=
10、0;i<blems.size();i+)Problem problem = blems.get(i);if(problem.getPremise()=n ull|problem.getPremise().islstrue() if(problem.getPremise()!=null)problem.getPremise().setlstrue(false);jta.setText(problem.getC on text();blems.remove(problem);return problem;jbl.setE nabled(false);
11、jb2.setE nabled(false);return nu II;private Executio n exe;private JButton jb1,jb2;private JTextArea jta ;private JLabel jl;private Problem problem;private Acti on I = new Actio n();class Actio n impleme nts Actio nListe nerpublic void actio nPeformed(Actio nEvent e) if("YES".equals(e.getA
12、ctio nComma nd() if(n ull!=problem.getA nswer_YES() problem.getA nswer_YES().setlstrue(true);else if("NO".equals(e.getActio nComma nd() System.out.pri ntln ("aaa");if(n ull!=problem.getA nswer_NO() System.out.pri ntln ("aaa"); problem.getA nswer_NO().setlstrue(true);exe
13、.allReas onin g();problem=i nitProblem();if(problem=n ull)ArrayList<Fact> facts=exe.start();String result=""for(i nt i=0,n=1;i<facts.size();i+)String des = facts.get(i).getDescribe();if(!" null".equals(des)result+=i+1+"."+des+"n"n+;jl.setText(”推理结果如下:
14、”); jta.setText(result);jb1.setE nabled(false);jb2.setE nabled(false);return;package专家系统_V2;import java.io.File;import java.i o.I OExcepti on;import java.io. Un supportedE ncodi ngExcepti on;import java .n et.URLDecoder;import java.util.ArrayList;import java.util.HashMap;import javax.swi ng.JOptio n
15、Pane;import javax.xml.parsers.Docume ntBuilder;import javax.xml.parsers.Docume ntBuilderFactory;import javax.xml.parsers.ParserC on figurati on Exceptio n;import org.w3c.dom.Docume nt;import org.w3c.dom.Eleme nt;import org.w3c.dom.NodeList;import org.xml.sax.SAXExceptio n;public class Executi on pub
16、lic boolea n in it()try this.i ni tXML(this.getPath(); catch (ParserC on figurati on Excepti on e) e.pri ntStackTrace(); catch (SAXException e) this.exit(e.getMessage(); catch (IOExcepti on e) e.pri ntStackTrace();xml文件名是否符合规范"); catch (NullPoi nterException e) this.exit("找不到相应的xml文件,请检查 r
17、eturn false;private void initXML(Stringfile) throws ParserConfigurationException, SAXException,lOExcepti onDocume ntBuilderFactory dbf = Docume ntBuilderFactory .newln sta nce();Docume ntBuilder builder = dbf. newDocume ntBuilder();Docume nt doc =nu II;trydoc = builder.parse( new File(file);catch(Ex
18、cepti on e)this.exit(e.getMessage();Eleme nt root = doc.getDocume ntEleme nt(); / 获取根元素expert_ name=root.getAttribute(” name");取得名字获取事实factNodeList allfacts = root.getEleme ntsByTagName("facts");NodeList on efacts = (Eleme nt)allfacts.item(O).getEleme ntsByTagName("fact");fo
19、r(i nt i=0;i< on efacts.getLe ngth();i+)Eleme nt on efact = (Eleme nt)o nefacts.item(i);Fact fact = new Fact();tryfact.setName( on efact.getEleme ntsByTagName(” name").item(0).getFirstChild().getNodeValu e();fact.setDescribe(o nefact.getEleme ntsByTagName("describe").item(0).getFir
20、stChild().getNod eValue();catch(NullPoi nterException e)this.exit("fact中缺少相应标签”);facts.put(fact.getName(), fact);获取推理reasoningNodeList allreas onings = root.getEleme ntsByTagName("reas onin gs");NodeListon ereas onings(Eleme nt)allreas onin gs.item(0).getEleme ntsByTagName("reas
21、onin g");for(i nt i=0;i< on ereas onin gs.getLe ngth();i+)Eleme nt on ereas oning = (Eleme nt)o nereas onin gs.item(i);Reas oning reas oning = new Reas onin g();NodeList reas ons = on ereas onin g.getEleme ntsByTagName("reas on ”);if(reas on s.getLe ngth()=O)this.exit("reasoning 中不
22、可以缺少 reason 标签");for(i nt j=O;j<reas on s.getLe ngth();j+)Stri ng n ame=reas on s.item(j).getFirstChild().getNodeValue();if(facts.get( name)!=nu ll)reas onin g.getReas on( ).add(facts.get (n ame);else this.exit("reason标签内容不正确,没有对应事实”);NodeList results = on ereas onin g.getEleme ntsByTag
23、Name("result"); if(results.getLe ngth()=O)this.exit("reasoning 中不可以缺少 result 标签");for(i nt j=O;j<results.getLe ngth();j+)Stri ng n ame=results.item(j).getFirstChild().getNodeValue();if(facts.get( name)!=nu ll)reas onin g.getResult().add(facts.get (n ame);elsethis.exit("re
24、sult标签内容不正确,没有对应事实 ”);reas onin gs.add(reas onin g);获取问题problemNodeList allproblems = root.getEleme ntsByTagName("problems");NodeListon eproblems(Eleme nt)allproblems.item(0).getEleme ntsByTagName("problem");for(i nt i=0;i< on eproblems.getLe ngth();i+)Eleme nt on eproblem = (
25、Eleme nt)o neproblems.item(i);Problem problem = new Problem();problem.setC on text(o neproblem.getEleme ntsByTagName("c on text").item(O).getFirstChild(). getNodeValue();tryproblem.setPremise(facts.get(o neproblem.getEleme ntsByTagName("premise").item(O).g etFirstChild().getNodeV
26、alue();catch(Excepti on e)tryproblem.setA nswer_YES(facts.get(o neproblem.getEleme ntsByTagName("a nswer_YES") .item(0).getFirstChild().getNodeValue();catch(Excepti on e)tryproblem.setA nswer_NO(facts.get(o neproblem.getEleme ntsByTagName("a nswer_NO").it em(0).getFirstChild().ge
27、tNodeValue();catch(Excepti on e)problems.add(problem);public void allReas onin g()boolea n proceed=true;while(proceed)proceed=false;for(Reas oning reas onin g:reas onin gs)reas onin g.startReas onin g();if(reas onin g.startReas onin g()proceed=true;public ArrayList<Fact> start()/this.allReas o
28、nin g();ArrayList<Fact> reallyFacts = new ArrayList<Fact>();for(Fact fact:facts.values()if(fact.islstrue()reallyFacts.add(fact);retur n reallyFacts;private void exit(Stri ng passage)JOpti onPan e.showMessageDialog( null, passage);System.exit(O);/查找当前路径private String getPath()String myPat
29、h=n ull;try myPath=URLDecoder.decode(Executi on. class.getProtect ion Doma in() .getCodeSource().getL ocatio n().getFile(), "UTF-8"); catch (Un supportedE ncodi ngExcepti on e) e.pri ntStackTrace();String path=myPath.substring(1,myPath.lastlndexOf("/")+1)+"XML/配置文件.xml"
30、return path;public HashMap<Stri ng,Fact> facts = new HashMap<Stri ng,Fact> (); public ArrayList<Reas oning> reas onings = new ArrayList<Reas onin g>(); public ArrayList<Problem> problems = new ArrayList<Problem>();public String expert_ name;package专家系统_V2;*存放事实的类*
31、 author ligua nyi*/public class Fact private String n ame; / 名字private boolea n istrue=false;/ 是否成立private Stri ng describe;/ 事实相应表述public String getName() return n ame;public void setName(Stri ng n ame) this. name = n ame;public boolea n islstrue() return istrue;public void setIstrue(boolea n istru
32、e) this.istrue = istrue;public String getDescribe() retur n describe;public void setDescribe(Stri ng describe) this.describe = describe;import java.util.ArrayList;/表示推理/前提事实/结果事实public class Reas oning private ArrayList<Fact> reas on = new ArrayList<Fact>(); private ArrayList<Fact>
33、 result = new ArrayList<Fact>();public ArrayList<Fact> getReas on() retur n reas on;public void setReas on( ArrayList<Fact> reas on) this.reas on = reas on;public ArrayList<Fact> getResult() return result;public void setResult(ArrayList<Fact> result) this.result = resul
34、t;public boolea n startReas onin g()if(reas on. size()=0)return false;for(Fact fact:reas on)if(!fact.islstrue()return false;for(Fact fact:reas on)fact.setIstrue(false);for(Fact fact:result)fact.setIstrue(true);return true;public class Problem private Fact premise;private String con text;private Fact
35、 an swer_YES;/ 结果private Fact an swer_NO;结果public Fact getPremise() return premise;public void setPremise(Fact premise) this.premise = premise;public Stri ng getCo ntext() return con text;public void setC on text(Stri ng con text) this.c on text = con text;public Fact getA nswer_YES() return an swer
36、_YES;public void setA nswer_YES(Fact an swerYES) an swer_YES = an swerYES;public Fact getA nswer_NO() return an swer_NO;public void setA nswer_NO(Fact an swerNO) an swer_NO = an swerNO;以下是XML文件(保存事实库和规则库)中部分内容<all name="疾病诊断"><facts><fact><n ame>fact1</name<de
37、scribe> 咳嗽 </describe></fact><fact><n ame>fact2</name<describe>胸痛 </describe><n ame>fact3</name<describe>盗汗 </describe></fact><fact><n ame>fact4</name<describe>食欲不振 </describe></fact><fact><
38、;n ame>fact5</name<describe>了肖瘦 </describe></fact><fact><n ame>fact6</name<describe>午后低热 </describe></fact><fact><n ame>fact7</name<describe>肺结核 </describe></fact><fact><n ame>fact9</name<desc
39、ribe> 呼吸困难 </describe></fact><fact><n ame>fact10 </n ame><describe>胸腔积液 </describe></fact><fact><n ame>fact11</name<describe>伴有哮鸣音的呼吸困难 </describe> </fact><fact><n ame>fact12</name<describe>发作性胸闷
40、咳嗽</describe></fact><fact><n ame>fact13</name<describe> 哮喘 </describe></fact><fact><n ame>fact14 </n ame><describe>不盗汗 </describe></fact><fact><n ame>fact15</name<describe>不咳嗽 </describe></
41、fact><fact><n ame>fact16</name<describe>没有伴有哮鸣音的呼吸困难</describe></fact><fact><n ame>fact17</name<describe>上腹痛 </describe></fact><fact><n ame>fact18</name<describe>节律性、周期性疼痛</describe></fact><fact&
42、gt;<n ame>fact19</name<describe> 灼疼 </describe></fact><fact><n ame>fact20 </n ame><describe> 乍屯痛 </describe></fact><fact><n ame>fact21</name<describe>消化性溃疡 </describe></fact><fact><n ame>fact2
43、2</name<describe>上腹不痛 </describe></fact><fact><n ame>fact23</name<describe>胸骨后不适 </describe></fact><fact><n ame>fact24 </n ame><describe>灼烧感 </describe></facts><reas onin gs><reas oning><reas on&
44、gt; fact6</reas on><result>fact7</result></reas oning><reas oning><reas on> fact9</reas on><result>fact10</result></reas oning><reas oning><reas on> fact12</reas on><result>fact13</result></reas oning><
45、;reas oning><reas on> fact20</reas on><result>fact21</result></reas oning><reas oning><reas on> fact27</reas on><result>fact28</result></reas oning><reas oning><reas on> fact32</reas on><result>fact33</re
46、sult></reas oning><reas oning><reas on> fact43</reas on> <result>fact44</result></reas oning><reas oning><reas on> fact47</reas on> <result>fact48</result></reas oning></reas onin gs><problems><problem>
47、;<co ntext> 是否咳嗽? </co ntext><a nswer_YES>fact1</a nswer_YES><a nswer_NO>fact15</a nswer_NO> </problem><problem><premise>fact1</premise><co ntext> 是否胸痛? </co ntext><a nswer_YES>fact2</a nswer_YES></problem><problem><premise>fact2</premise><con text> 是否盗汗? </con text><a nswer_YES>fact3</a nswer_YES><a nswer_N0>fact14</a nswer_NO></proble
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 性能养鱼测试题及答案
- 面向2025年大数据存储的分布式文件系统优化报告
- 水溶液考试题及答案
- 2025南航招聘空姐面试题目及答案
- 聚焦2025新能源汽车租赁行业政策环境与项目合规性分析
- 生态酒厂面试题及答案
- 新能源汽车行业的信息化发展路径研究试题及答案
- 最佳裁判测试题及答案
- 生态修复工程2025年生态系统服务功能评估与生态修复产业协同创新报告
- 生物饲料添加剂市场潜力评估鉴定报告
- 【2025二轮复习】读后续写专题
- 商品房门窗加工合同协议
- 四年级下册数学口算练习题
- 《超重康复之道》课件
- 建筑图纸识图培训
- 飞行员劳动合同模板及条款
- 第中西艺术时空对话 课件 2024-2025学年岭南美版(2024) 初中美术七年级下册
- 高氧潜水考试题及答案
- 2025年二级建造师之二建矿业工程实务通关考试题库带答案解析
- (四调)武汉市2025届高中毕业生四月调研考试 物理试卷(含答案)
- 盲医考试题及答案
评论
0/150
提交评论