疾病诊断小型专家系统人工智能课程设计报告.doc_第1页
疾病诊断小型专家系统人工智能课程设计报告.doc_第2页
疾病诊断小型专家系统人工智能课程设计报告.doc_第3页
疾病诊断小型专家系统人工智能课程设计报告.doc_第4页
疾病诊断小型专家系统人工智能课程设计报告.doc_第5页
已阅读5页,还剩17页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

疾病诊断小型专家系统 人工智能课程设计报告 智能1001班 傅宝林 0909101217 2013.6.181内容提要 此系统采用专家系统的规则库-推理机技术原理,以医学诊断为背景,旨在作出一个简单的辅助诊断专家系统。系统的框架及界面采用的是Java语言,调用XML里保存的知识库和规则库。此小型的专家系统以肺结核、哮喘、食管癌、骨折等疾病的诊断为例,展示了一个小型专家系统是如何构建的。目录1内容提要22目的和意义43系统的主要内容和功能54设计流程及描述65课程设计体会216参考文献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;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Dimension;import java.awt.Font;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.ArrayList;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.border.LineBorder;public class MainFrame extends JFrame/* * 主界面类 * param args */public static void main(String args) MainFrame main = new MainFrame();main.myShow();private void myShow() exe = new Execution();exe.init();this.setTitle(exe.expert_name+专家系统);this.setSize(380, 250);this.setDefaultCloseOperation(3);this.setResizable(false);this.setLocationRelativeTo(null);this.setLayout(new BorderLayout();JPanel jp_center = new JPanel();jp_center.setBackground(Color.white);jp_center.setPreferredSize(new Dimension(380,250);jp_center.setLayout(null);jl = new JLabel();jl.setText(请回答下列问题:);jl.setFont(new Font(Font.DIALOG,Font.BOLD,25);jl.setForeground(Color.blue);jl.setBounds(10, 10, 200, 30);jta=new JTextArea();JScrollPane js=new JScrollPane(jta);jta.setEditable(false);jta.setBorder(new LineBorder(Color.black);jta.setLineWrap(true);jta.setFont(new Font(Font.DIALOG,Font.BOLD,20);js.setBounds(20, 50, 330, 100);jb1 = new JButton(YES);jb1.setBounds(100, 170, 60, 30);jb1.addActionListener(l);jb2 = new JButton(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);private Problem initProblem()for(int i=0;blems.size();i+)Problem problem = blems.get(i);if(problem.getPremise()=null|problem.getPremise().isIstrue()if(problem.getPremise()!=null)problem.getPremise().setIstrue(false);jta.setText(problem.getContext();blems.remove(problem);return problem;jb1.setEnabled(false);jb2.setEnabled(false);return null;private Execution exe;private JButton jb1,jb2;private JTextArea jta ;private JLabel jl;private Problem problem;private Action l = new Action();class Action implements ActionListenerpublic void actionPerformed(ActionEvent e) if(YES.equals(e.getActionCommand()if(null!=problem.getAnswer_YES()problem.getAnswer_YES().setIstrue(true);else if(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 facts=exe.start();String result=;for(int i=0,n=1;ifacts.size();i+)String des = 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;import java.io.File;import java.io.IOException;import java.io.UnsupportedEncodingException;import .URLDecoder;import java.util.ArrayList;import java.util.HashMap;import javax.swing.JOptionPane;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import javax.xml.parsers.ParserConfigurationException;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.NodeList;import org.xml.sax.SAXException;public class Execution public boolean init()try this.initXML(this.getPath(); catch (ParserConfigurationException e) e.printStackTrace(); catch (SAXException e) this.exit(e.getMessage(); catch (IOException e) e.printStackTrace(); catch (NullPointerException e)this.exit(找不到相应的xml文件,请检查xml文件名是否符合规范);return false;private void initXML(String file) throws ParserConfigurationException, SAXException, IOExceptionDocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();DocumentBuilder builder = dbf.newDocumentBuilder();Document doc=null;trydoc = builder.parse(new File(file);catch(Exception e)this.exit(e.getMessage();Element root = doc.getDocumentElement(); / 获取根元素expert_name=root.getAttribute(name); /取得名字/获取事实factNodeList allfacts = root.getElementsByTagName(facts);NodeList onefacts = (Element)allfacts.item(0).getElementsByTagName(fact);for(int i=0;ionefacts.getLength();i+)Element onefact = (Element)onefacts.item(i);Fact fact = new Fact();tryfact.setName(onefact.getElementsByTagName(name).item(0).getFirstChild().getNodeValue();fact.setDescribe(onefact.getElementsByTagName(describe).item(0).getFirstChild().getNodeValue();catch(NullPointerException e)this.exit(fact中缺少相应标签);facts.put(fact.getName(), fact);/获取推理reasoningNodeList allreasonings = root.getElementsByTagName(reasonings);NodeList onereasonings = (Element)allreasonings.item(0).getElementsByTagName(reasoning);for(int i=0;ionereasonings.getLength();i+)Element onereasoning = (Element)onereasonings.item(i);Reasoning reasoning = new Reasoning();NodeList reasons = onereasoning.getElementsByTagName(reason);if(reasons.getLength()=0)this.exit(reasoning中不可以缺少reason标签);for(int j=0;jreasons.getLength();j+)String name=reasons.item(j).getFirstChild().getNodeValue();if(facts.get(name)!=null)reasoning.getReason().add(facts.get(name);elsethis.exit(reason标签内容不正确,没有对应事实);NodeList results = onereasoning.getElementsByTagName(result);if(results.getLength()=0)this.exit(reasoning中不可以缺少result标签);for(int j=0;jresults.getLength();j+)String name=results.item(j).getFirstChild().getNodeValue();if(facts.get(name)!=null)reasoning.getResult().add(facts.get(name);elsethis.exit(result标签内容不正确,没有对应事实);reasonings.add(reasoning);/获取问题problemNodeList allproblems = root.getElementsByTagName(problems);NodeList oneproblems = (Element)allproblems.item(0).getElementsByTagName(problem);for(int i=0;ioneproblems.getLength();i+)Element oneproblem = (Element)oneproblems.item(i);Problem problem = new Problem();problem.setContext(oneproblem.getElementsByTagName(context).item(0).getFirstChild().getNodeValue();tryproblem.setPremise(facts.get(oneproblem.getElementsByTagName(premise).item(0).getFirstChild().getNodeValue();catch(Exception e)tryproblem.setAnswer_YES(facts.get(oneproblem.getElementsByTagName(answer_YES).item(0).getFirstChild().getNodeValue();catch(Exception e)tryproblem.setAnswer_NO(facts.get(oneproblem.getElementsByTagName(answer_NO).item(0).getFirstChild().getNodeValue();catch(Exception e)problems.add(problem);public void allReasoning()boolean proceed=true;while(proceed)proceed=false;for(Reasoning reasoning:reasonings)reasoning.startReasoning();if(reasoning.startReasoning()proceed=true;public ArrayList start()/this.allReasoning();ArrayList reallyFacts = new ArrayList();for(Fact fact:facts.values()if(fact.isIstrue()reallyFacts.add(fact);return reallyFacts;private void exit(String passage)JOptionPane.showMessageDialog(null, passage);System.exit(0);/查找当前路径private String getPath()String myPath=null;try myPath=URLDecoder.decode(Execution.class.getProtectionDomain().getCodeSource().getLocation().getFile(), UTF-8); catch (UnsupportedEncodingException e) e.printStackTrace();String path=myPath.substring(1,myPath.lastIndexOf(/)+1)+XML/配置文件.xml;return path;public HashMap facts = new HashMap ();public ArrayList reasonings = new ArrayList();public ArrayList problems = new ArrayList();public String expert_name;package 专家系统_V2;/* * 存放事实的类 * author liguanyi * */public class Fact private String name; /名字private boolean istrue=false; /是否成立private String describe; /事实相应表述public String getName() return name;public void setName(String name) = name;public boolean isIstrue() return istrue;public void setIstrue(boolean istrue) this.istrue = istrue;public String getDescribe() return describe;public void setDescribe(String describe) this.describe = describe;package 专家系统_V2;import java.util.ArrayList;/表示推理public class Reasoning private ArrayList reason = new ArrayList(); /前提事实private ArrayList result = new ArrayList(); /结果事实public ArrayList getReason() return reason;public void setReason(ArrayList reason) this.reason = reason;public ArrayList getResult() return result;public void setResult(ArrayList result) this.result = result;public boolean startReasoning()if(reason.size()=0)return false;for(Fact fact:reason)if(!fact.isIstrue()return false;for(Fact fact:reason)fact.setIstrue(false);for(Fact fact:result)fact.setIstrue(true);return true;package 专家系统_V2;public class Problem private Fact premise;private String context;private Fact answer_YES; /结果private Fact answer_NO; /结果public Fact getPremise() return premise;public void setPremise(Fact premise) this.premise = premise;public String getContext() return context;public void setContext(String context) this.context = context;public Fact getAnswer_YES() return answer_YES;public void setAnswer_YES(Fact answerYES) answer_YES = answerYES;public Fact getAnswer_NO() return answer_NO;public void setAnswer_NO(Fact answerNO) answer_NO = answerNO;以下是XML文件(保存事实库和规则库)中部分内容fact1咳嗽fact2胸痛fact3盗汗 fact4食欲不振 fact5消瘦 fact

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论