2019年疾病診斷小型專家系統(tǒng)人工智能課程報告_第1頁
2019年疾病診斷小型專家系統(tǒng)人工智能課程報告_第2頁
2019年疾病診斷小型專家系統(tǒng)人工智能課程報告_第3頁
2019年疾病診斷小型專家系統(tǒng)人工智能課程報告_第4頁
2019年疾病診斷小型專家系統(tǒng)人工智能課程報告_第5頁
已閱讀5頁,還剩15頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、疾病診斷小型專家系統(tǒng)人工智能課程設計報告智能1001班傅寶林09091012172013.6.181內(nèi)容提要此系統(tǒng)采用專家系統(tǒng)的規(guī)則庫-推理機技術原理,以醫(yī)學診斷為背景,旨在作出一個簡單的輔助診斷專家系統(tǒng)。系統(tǒng)的框架及界面采用的是Java語言,調(diào)用XML里保存的知識庫和規(guī)則庫。此小型的專家系統(tǒng)以肺結核、哮喘、食管癌、骨折等疾病的診斷為例,展示了一個小型專家系統(tǒng)是如何構建的。目錄1內(nèi)容提要22目的和意義43系統(tǒng)的主要內(nèi)容和功能54設計流程及描述65課程設計體會216參考文獻222目的和意義(1)加深理解專家系統(tǒng)的結構及開發(fā)過程。(2)初步掌握知識獲取的基本方法。(3)掌握產(chǎn)生式規(guī)則知識表示方法及

2、其編程實現(xiàn)方法。(4)初步掌握知識庫的組建方法。3系統(tǒng)的主要內(nèi)容和功能系統(tǒng)主要以問答的形勢詢問病情癥狀,操作者只需要回答YES或NO。當一趟詢問完成后,系統(tǒng)會基于以上詢問得出的事實推理出最終的診斷結果。圖2診斷結果界面4設計流程及描述1)需求分析本設計需要用高級語言編寫框架及調(diào)用外部的規(guī)則庫與知識庫。方便起見,用java語言編寫框架,用XML文件保存。2)知識獲取與知識表示知識獲取通過醫(yī)學臨床專業(yè)的同學及醫(yī)學診斷專業(yè)書籍,確保專家系統(tǒng)的專家性。知識的表示采用的是xml語言,把事實與規(guī)則一條條保存。3)知識庫的組建知識庫分事實庫和規(guī)則庫組建。疾病診斷因為有的病有交叉的癥狀,所以邏輯上,從癥狀到診

3、斷的過程是對一顆二叉樹的搜索,當問題回答的是YES時,就進行深度優(yōu)先搜索,當回答NO時,就轉到兄弟節(jié)點。對于無關的疾病,則回到根節(jié)點重新對下一顆子樹進行搜索。得到一種疾病的確診就是result,得到這個葉子節(jié)點前遍歷過的節(jié)點組成了reasons.4)推理機制選擇/編制采用的是問題引導式推理。在規(guī)則庫里寫的其實不是真正的規(guī)則。真正的規(guī)則蘊含在問題及前提里。為了不讓“專家”問無用的問題,每個問題都是以某個問題的答案為前提的。這樣組成了內(nèi)部的因果關系,所以真正的推理規(guī)則只與某一趟提問的最后一個問題的答案得出的事實有關。5)程序清單package專家系統(tǒng)_V2;importjava.awt.Borde

4、rLayout;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;

5、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+"專家系統(tǒng)");this.setSize(

6、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(&

7、quot;請回答下列問題:");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.BO

8、LD,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,B

9、orderLayout.CENTER);problem=this.initProblem();this.setVisible(true);privateProbleminitProblem()for(inti=0;i<blems.size();i+)Problemproblem=blems.get(i);if(problem.getPremise()=null|problem.getPremise().isIstrue()if(problem.getPremise()!=null)problem.getPremise().setIstrue(false);jt

10、a.setText(problem.getContext();blems.remove(problem);returnproblem;)jbl.setEnabled(false);jb2.setEnabled(false);returnnull;)privateExecutionexe;privateJButtonjb1,jb2;privateJTextAreajta;privateJLabeljl;privateProblemproblem;privateActionl=newAction();classActionimplementsActionListenerpublicv

11、oidactionPerformed(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"

12、;);problem.getAnswer_NO().setIstrue(true);exe.allReasoning();problem=initProblem();if(problem=null)ArrayList<Fact>facts=exe.start();Stringresult=""for(inti=0,n=1;i<facts.size();i+)Stringdes=facts.get(i).getDescribe();if(!"null".equals(des)result+=i+1+"."+des+&q

13、uot;'n"n+;jl.setText("推理結果如下:");jta.setText(result);jb1.setEnabled(false);jb2.setEnabled(false);return;)package專家系統(tǒng)_V2;importjava.io.File;importjava.io.IOException;importjava.io.UnsupportedEncodingException;.URLDecoder;importjava.util.ArrayList;importjava.util.HashMap;importjavax.

14、swing.JOptionPane;importjavax.xml.parsers.DocumentBuilder;importjavax.xml.parsers.DocumentBuilderFactory;importjavax.xml.parsers.ParserCon巾gurationException;importorg.w3c.dom.Document;importorg.w3c.dom.Element;importorg.w3c.dom.NodeList;importorg.xml.sax.SAXException;publicclassExecutionpublicboolea

15、ninit()trythis.initXML(this.getPath();catch(ParserConfigurationExceptione)e.printStackTrace();catch(SAXExceptione)this.exit(e.getMessage();catch(IOExceptione)e.printStackTrace();catch(NullPointerExceptione)this.exit("找不到相應的xml文件,請檢查xml文件名是否符合規(guī)范");returnfalse;privatevoidinitXML(Stringfile)t

16、hrowsParserConfigurationException,SAXException,IOExceptionDocumentBuilderFactorydbf=DocumentBuilderFactory.newInstance();DocumentBuilderbuilder=dbf.newDocumentBuilder();Documentdoc=null;trydoc=builder.parse(newFile(file);catch(Exceptione)this.exit(e.getMessage();Elementroot=doc.getDocumentElement();

17、/獲取根元素expert_name=root.getAttribute("name");取得名字獲取事實factNodeListallfacts=root.getElementsByTagName("facts");NodeListonefacts=(Element)allfacts.item(0).getElementsByTagName("fact");for(inti=0;i<onefacts.getLength();i+)Elementonefact=(Element)onefacts.item(i);Factfact=

18、newFact();tryfact.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.get

19、Name(),fact);獲取推理reasoningNodeListallreasonings=root.getElementsByTagName("reasonings");NodeListonereasonings(Element)allreasonings.item(0).getElementsByTagName("reasoning");for(inti=0;i<onereasonings.getLength();i+)Elementonereasoning=(Element)onereasonings.item(i);Reasoningr

20、easoning=newReasoning();NodeListreasons=onereasoning.getElementsByTagName("reason");if(reasons.getLength()=0)this.exit("reasoning中不可以缺少reason標簽)for(intj=0;j<reasons.getLength();j+)Stringname=reasons.item(j).getFirstChild().getNodeValue();if(facts.get(name)!=null)reasoning.getReason

21、().add(facts.get(name);elsethis.exit("reason標簽內(nèi)容不正確,沒有對應事實");NodeListresults=onereasoning.getElementsByTagName("result");if(results.getLength()=0)this.exit("reasoning中不可以缺少result標簽");for(intj=0;j<results.getLength();j+)Stringname=results.item(j).getFirstChild().getNo

22、deValue();if(facts.get(name)!=null)reasoning.getResult().add(facts.get(name);elsethis.exit("result標簽內(nèi)容不正確,沒有對應事實");reasonings.add(reasoning);獲取問題problemNodeListallproblems=root.getElementsByTagName("problems");NodeListoneproblems(Element)allproblems.item(0).getElementsByTagName(&

23、quot;problem");for(inti=0;i<oneproblems.getLength();i+)Elementoneproblem=(Element)oneproblems.item(i);Problemproblem=newProblem();problem.setContext(oneproblem.getElementsByTagName("context").item(0).getFirstChild().getNodeValue();tryproblem.setPremise(facts.get(oneproblem.getEleme

24、ntsByTagName("premise").item(0).getFirstChild().getNodeValue();catch(Exceptione)tryproblem.setAnswer_YES(facts.get(oneproblem.getElementsByTagName("answer_YES").item(0).getFirstChild().getNodeValue();catch(Exceptione)tryproblem.setAnswer_NO(facts.get(oneproblem.getElementsByTagNa

25、me("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<F

26、act>start()/this.allReasoning();ArrayList<Fact>reallyFacts=newArrayList<Fact>();for(Factfact:facts.values()if(fact.isIstrue()reallyFacts.add(fact);)returnreallyFacts;privatevoidexit(Stringpassage)JOptionPane.showMessageDialog(null,passage);System.exit(0);)查找當前路徑privateStringgetPath()S

27、tringmyPath=null;trymyPath=URLDecoder.decode(Execution.class.getProtectionDomain().getCodeSource().getLocation().getFile(),"UTF-8");catch(UnsupportedEncodingExceptione)e.printStackTrace();Stringpath=myPath.substring(1,myPath.lastIndexOf("/")+1)+"XML/配置文件.xml"returnpath;

28、publicHashMap<String,Fact>facts=newHashMap<String,Fact>();publicArrayList<Reasoning>reasonings=newArrayList<Reasoning>();publicArrayList<Problem>problems=newArrayList<Problem>();publicStringexpert_name;)package專家系統(tǒng)_V2;/* 存放事實的類* authorliguanyi* /publicclassFactpri

29、vateStringname;名字privatebooleanistrue=false;是否成立privateStringdescribe;事實相應表述publicStringgetName()returnname;)publicvoidsetName(Stringname)=name;)publicbooleanisIstrue()returnistrue;)publicvoidsetIstrue(booleanistrue)this.istrue=istrue;)publicStringgetDescribe()returndescribe;)publicvoidsetD

30、escribe(Stringdescribe)this.describe=describe;)package專家系統(tǒng)_V2;importjava.util.ArrayList;/表示推理publicclassReasoningprivateArrayList<Fact>reason=newArrayList<Fact>();前提事實privateArrayList<Fact>result=newArrayList<Fact>();/結果事實publicArrayList<Fact>getReason()returnreason;pub

31、licvoidsetReason(ArrayList<Fact>reason)this.reason=reason;publicArrayList<Fact>getResult()returnresult;publicvoidsetResult(ArrayList<Fact>result)this.result=result;publicbooleanstartReasoning()if(reason.size()=0)returnfalse;for(Factfact:reason)if(!fact.isIstrue()returnfalse;for(Fac

32、tfact:reason)fact.setIstrue(false);for(Factfact:result)fact.setIstrue(true);returntrue;package專家系統(tǒng)_V2;publicclassProblemprivateFactpremise;privateStringcontext;privateFactanswer_YES;結果privateFactanswer_NO;結果publicFactgetPremise()returnpremise;publicvoidsetPremise(Factpremise)this.premise=premise;pub

33、licStringgetContext()returncontext;publicvoidsetContext(Stringcontext)this.context=context;publicFactgetAnswer_YES()returnanswer_YES;publicvoidsetAnswer_YES(FactanswerYES)answer_YES=answerYES;publicFactgetAnswer_NO()returnanswer_NO;publicvoidsetAnswer_NO(FactanswerNO)answer_NO=answerNO;以下是XML文件(保存事實

34、庫和規(guī)則庫)中部分內(nèi)容<allname="疾病診斷”><facts><fact><name>fact1</name>describe咳嗽</describe></fact><fact><name>fact2</name><describe>胸痛</describe></fact><fact><name>fact3</name><describe>盜,f</describe>

35、;</fact><fact><name>fact4</name>describe>食欲不振</describe></fact><fact><name>fact5</name><describe>消瘦</describe></fact><fact><name>fact6</name><describe>午后低熱</describe></fact><fact><

36、name>fact7</name><describe>肺結核</describe></fact><fact><name>fact9</name><describe>呼吸困難</describe></fact><fact><name>fact10</name><describe>胸腔積液</describe></fact><fact><name>fact11</name&

37、gt;<describe>伴有哮鳴音的呼吸困難</describe></fact><fact><name>fact12</name><describe>發(fā)作性胸悶咳嗽</describe></fact><fact><name>fact13</name><describe>哮喘</describe></fact><fact><name>fact14</name><describ

38、e>不盜汗</describe></fact><fact><name>fact15</name><describe>不咳嗽</describe></fact><fact><name>fact16</name>describe沒有伴有哮鳴音的呼吸困難</describe></fact><fact><name>fact17</name><describe>上腹痛</describe&g

39、t;</fact><fact><name>fact18</name><describe>節(jié)律性、周期性疼痛</describe></fact><fact><name>fact19</name><describe>灼疼</describe></fact><fact><name>fact20</name><describe>專屯痛</describe></fact><

40、fact><name>fact21</name><describe>消化性潰瘍</describe></fact><fact><name>fact22</name><describe>上腹不痛</describe></fact><fact><name>fact23</name><describe>胸骨后不適</describe></fact><fact><name>fact24</name><describe>灼燒感</describe></facts><reasonings><reasoning><reason>fact6</reason><result>fact7</result></reasoning><reasoning><reason>fact9</reason><result>fact10</re

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論