疾病诊断小型专家系统人工智能课程报告doc.docx
- 文档编号:4642407
- 上传时间:2022-12-07
- 格式:DOCX
- 页数:23
- 大小:50.51KB
疾病诊断小型专家系统人工智能课程报告doc.docx
《疾病诊断小型专家系统人工智能课程报告doc.docx》由会员分享,可在线阅读,更多相关《疾病诊断小型专家系统人工智能课程报告doc.docx(23页珍藏版)》请在冰豆网上搜索。
疾病诊断小型专家系统人工智能课程报告doc
疾病诊断小型专家系统
——人工智能课程设计报告
智能1001班
傅宝林
0909101217
2013.6.18
1内容提要
此系统采用专家系统的规则库-推理机技术原理,以医学诊断为背景,旨在作出一个简单的辅助诊断专家系统。
系统的框架及界面采用的是Java语言,调用XML里保存的知识库和规则库。
此小型的专家系统以肺结核、哮喘、食管癌、骨折等疾病的诊断为例,展示了一个小型专家系统是如何构建的。
1内容提要……………………………………………………………2
2目的和意义…………………………………………………………4
3系统的主要内容和功能……………………………………………5
4设计流程及描述……………………………………………………6
5课程设计体会………………………………………………………21
6参考文献……………………………………………………………22
2目的和意义
(1)加深理解专家系统的结构及开发过程。
(2)初步掌握知识获取的基本方法。
(3)掌握产生式规则知识表示方法及其编程实现方法。
(4)初步掌握知识库的组建方法。
3系统的主要内容和功能
系统主要以问答的形势询问病情症状,操作者只需要回答YES或NO。
当一趟询问完成后,系统会基于以上询问得出的事实推理出最终的诊断结果。
功能见以下截图1、2.
图1问询界面
图2诊断结果界面
4设计流程及描述
1)需求分析
本设计需要用高级语言编写框架及调用外部的规则库与知识库。
方便起见,用java语言编写框架,用XML文件保存。
2)知识获取与知识表示
知识获取通过医学临床专业的同学及医学诊断专业书籍,确保专家系统的专家性。
知识的表示采用的是xml语言,把事实与规则一条条保存。
3)知识库的组建
知识库分事实库和规则库组建。
疾病诊断因为有的病有交叉的症状,所以逻辑上,从症状到诊断的过程是对一颗二叉树的搜索,当问题回答的是YES时,就进行深度优先搜索,当回答NO时,就转到兄弟节点。
对于无关的疾病,则回到根节点重新对下一颗子树进行搜索。
得到一种疾病的确诊就是result,得到这个叶子节点前遍历过的节点组成了reasons.
4)推理机制选择/编制
采用的是问题引导式推理。
在规则库里写的其实不是真正的规则。
真正的规则蕴含在问题及前提里。
为了不让“专家”问无用的问题,每个问题都是以某个问题的答案为前提的。
这样组成了内部的因果关系,所以真正的推理规则只与某一趟提问的最后一个问题的答案得出的事实有关。
5)程序清单
package专家系统_V2;
importjava.awt.BorderLayout;
importjava.awt.Color;
importjava.awt.Dimension;
importjava.awt.Font;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.util.ArrayList;
importjavax.swing.JButton;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JPanel;
importjavax.swing.JScrollPane;
importjavax.swing.JTextArea;
importjavax.swing.border.LineBorder;
publicclassMainFrameextendsJFrame{
/**
*主界面类
*@paramargs
*/
publicstaticvoidmain(String[]args){
MainFramemain=newMainFrame();
main.myShow();
}
privatevoidmyShow(){
exe=newExecution();
exe.init();
this.setTitle(exe.expert_name+"专家系统");
this.setSize(380,250);
this.setDefaultCloseOperation(3);
this.setResizable(false);
this.setLocationRelativeTo(null);
this.setLayout(newBorderLayout());
JPaneljp_center=newJPanel();
jp_center.setBackground(Color.white);
jp_center.setPreferredSize(newDimension(380,250));
jp_center.setLayout(null);
jl=newJLabel();
jl.setText("请回答下列问题:
");
jl.setFont(newFont(Font.DIALOG,Font.BOLD,25));
jl.setForeground(Color.blue);
jl.setBounds(10,10,200,30);
jta=newJTextArea();
JScrollPanejs=newJScrollPane(jta);
jta.setEditable(false);
jta.setBorder(newLineBorder(Color.black));
jta.setLineWrap(true);
jta.setFont(newFont(Font.DIALOG,Font.BOLD,20));
js.setBounds(20,50,330,100);
jb1=newJButton("YES");
jb1.setBounds(100,170,60,30);
jb1.addActionListener(l);
jb2=newJButton("NO");
jb2.setBounds(200,170,60,30);
jb2.addActionListener(l);
jp_center.add(jl);
jp_center.add(js);
jp_center.add(jb1);
jp_center.add(jb2);
this.add(jp_center,BorderLayout.CENTER);
problem=this.initProblem();
this.setVisible(true);
}
privateProbleminitProblem(){
for(inti=0;i Problemproblem=exe.problems.get(i); if(problem.getPremise()==null||problem.getPremise().isIstrue()){ if(problem.getPremise()! =null){ problem.getPremise().setIstrue(false); } jta.setText(problem.getContext()); exe.problems.remove(problem); returnproblem; } } jb1.setEnabled(false); jb2.setEnabled(false); returnnull; } privateExecutionexe; privateJButtonjb1,jb2; privateJTextAreajta; privateJLabeljl; privateProblemproblem; privateActionl=newAction(); classActionimplementsActionListener{ publicvoidactionPerformed(ActionEvente){ if("YES".equals(e.getActionCommand())){ if(null! =problem.getAnswer_YES()){ problem.getAnswer_YES().setIstrue(true); } }elseif("NO".equals(e.getActionCommand())){ System.out.println("aaa"); if(null! =problem.getAnswer_NO()){ System.out.println("aaa"); problem.getAnswer_NO().setIstrue(true); } } exe.allReasoning(); problem=initProblem(); if(problem==null){ ArrayList Stringresult=""; for(inti=0,n=1;i Stringdes=facts.get(i).getDescribe(); if(! "null".equals(des)){ result+=i+1+"."+des+"\n"; n++; } } jl.setText("推理结果如下: "); jta.setText(result); jb1.setEnabled(false); jb2.setEnabled(false); return; } } } } package专家系统_V2; importjava.io.File; importjava.io.IOException; importjava.io.UnsupportedEncodingException; import.URLDecoder; importjava.util.ArrayList; importjava.util.HashMap; importjavax.swing.JOptionPane; importjavax.xml.parsers.DocumentBuilder; importjavax.xml.parsers.DocumentBuilderFactory; importjavax.xml.parsers.ParserConfigurationException; importorg.w3c.dom.Document; importorg.w3c.dom.Element; importorg.w3c.dom.NodeList; importorg.xml.sax.SAXException; publicclassExecution{ publicbooleaninit(){ try{ this.initXML(this.getPath()); }catch(ParserConfigurationExceptione){ e.printStackTrace(); }catch(SAXExceptione){ this.exit(e.getMessage()); }catch(IOExceptione){ e.printStackTrace(); }catch(NullPointerExceptione){ this.exit("找不到相应的xml文件,请检查xml文件名是否符合规范"); } returnfalse; } privatevoidinitXML(Stringfile)throwsParserConfigurationException,SAXException,IOException{ DocumentBuilderFactorydbf=DocumentBuilderFactory.newInstance(); DocumentBuilderbuilder=dbf.newDocumentBuilder(); Documentdoc=null; try{ doc=builder.parse(newFile(file)); }catch(Exceptione){ this.exit(e.getMessage()); } Elementroot=doc.getDocumentElement();//获取根元素 expert_name=root.getAttribute("name");//取得名字 //获取事实fact NodeListallfacts=root.getElementsByTagName("facts"); NodeListonefacts=((Element)allfacts.item(0)).getElementsByTagName("fact"); for(inti=0;i Elementonefact=(Element)onefacts.item(i); Factfact=newFact(); try{ fact.setName(onefact.getElementsByTagName("name").item(0).getFirstChild().getNodeValue()); fact.setDescribe(onefact.getElementsByTagName("describe").item(0).getFirstChild().getNodeValue()); }catch(NullPointerExceptione){ this.exit("fact中缺少相应标签"); } facts.put(fact.getName(),fact); } //获取推理reasoning NodeListallreasonings=root.getElementsByTagName("reasonings"); NodeListonereasonings=((Element)allreasonings.item(0)).getElementsByTagName("reasoning"); for(inti=0;i Elementonereasoning=(Element)onereasonings.item(i); Reasoningreasoning=newReasoning(); NodeListreasons=onereasoning.getElementsByTagName("reason"); if(reasons.getLength()==0){ this.exit("reasoning中不可以缺少reason标签"); } for(intj=0;j Stringname=reasons.item(j).getFirstChild().getNodeValue(); if(facts.get(name)! =null){ reasoning.getReason().add(facts.get(name)); }else{ this.exit("reason标签内容不正确,没有对应事实"); } } NodeListresults=onereasoning.getElementsByTagName("result"); if(results.getLength()==0){ this.exit("reasoning中不可以缺少result标签"); } for(intj=0;j Stringname=results.item(j).getFirstChild().getNodeValue(); if(facts.get(name)! =null){ reasoning.getResult().add(facts.get(name)); }else{ this.exit("result标签内容不正确,没有对应事实"); } } reasonings.add(reasoning); } //获取问题problem NodeListallproblems=root.getElementsByTagName("problems"); NodeListoneproblems=((Element)allproblems.item(0)).getElementsByTagName("problem"); for(inti=0;i Elementoneproblem=(Element)oneproblems.item(i); Problemproblem=newProblem(); problem.setContext(oneproblem.getElementsByTagName("context").item(0).getFirstChild().getNodeValue()); try{problem.setPremise(facts.get(oneproblem.getElementsByTagName("premise").item(0).getFirstChild().getNodeValue())); }catch(Exceptione){} try{problem.setAnswer_YES(facts.get(oneproblem.getElementsByTagName("answer_YES").item(0).getFirstChild().getNodeValue())); }catch(Exceptione){} try{problem.setAnswer_NO(facts.get(oneproblem.getElementsByTagName("answer_NO").item(0).getFirstChild().getNodeValue())); }catch(Exceptione){} problems.add(problem); } } publicvoidallReasoning(){ booleanproceed=true; while(proceed){ proceed=false; for(Reasoningreasoning: reasonings){ reasoning.startReasoning(); if(reasoning.startReasoning()){ proceed=true; } } } } publicArrayList //this.allReasoning(); ArrayList for(Factfact: facts.values()){ if(fact.isIstrue()){ reallyFacts.add(fact); } } returnreallyFacts; } privatevoidexit(Stringpassage){ JOptionPane.showMessageDialog(null,passage); System.exit(0); } //查找当前路径 privateStringgetPath(){ StringmyPath=null; try{ myPath=URLDecoder.decode(Execution.class.getProtectionDomain().getCodeSource().getLocation().getFile(),"UTF-8"); }catch(UnsupportedEncodingExceptione){ e.printStackTrace(); } Stringpath=myPath.substring(1,myPath.lastIndexOf("/")+1)+"XML/配置文件.xml"; returnpath; } publicHashMap publicArrayList publicArrayList publicStringexpert_name; } package专家系统_V2; /** *存放事实的类 *@authorliguanyi * */ publicclassFact{ privateStringname;//名字 privatebooleanistrue=
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 疾病诊断 小型 专家系统 人工智能 课程 报告 doc