1 / 28

Multipurpose ITS

Multipurpose ITS. Implementation Document 20021169 김계현 IM Lab. System Overview. Completed Modules. Main. class ITS static void main (String[] args) static void learn (KnowledgeBase kb, KnowledgeGenerator kg) static void teach (KnowledgeBase kb, KnowledgeGenerator kg, Planner planner).

gafna
Download Presentation

Multipurpose ITS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Multipurpose ITS Implementation Document 20021169 김계현 IM Lab.

  2. System Overview

  3. Completed Modules

  4. Main • class ITS • static void main(String[] args) • static void learn(KnowledgeBase kb, KnowledgeGenerator kg) • static void teach(KnowledgeBase kb, KnowledgeGenerator kg, Planner planner)

  5. Knowledge Base

  6. Knowledge Base (cont’d) • class KnowledgeBase • Concept addConcept(String name); • Relation addRelation(String name); • Fact addFact(String name, String[] premises, String[] conjunction, int n); • Rule addRule(Vector basis, String[] premises, String[][] terms, String conclusion, String[] cterms); • Fact ask(String relation, String[] terms); • void execute(); • void print();

  7. Fact

  8. Fact (cont’d) • class Concept • class Relation • void addRule(Rule rule); • void addFact(Fact fact); • void focusOn(); • boolean isTrue(Fact fact); • boolean isAlreadyDerived(Fact fact); • boolean isContradicted(Fact fact); • void on(IEngine ie, Fact fact); • boolean equals(Object item); • void print(Logger log, int depth);

  9. Fact (cont’d) • class Fact • void print(Logger log, int depth); • Fact negates(); • boolean equals(Object item); • void on(IEngine ie);

  10. Rule

  11. Rule (cont’d) • class Rule • void print(Logger log, int depth); • void on(IEngine ie, Fact fact);

  12. Inference Engine

  13. Inference Engine (cont’d) • class IEngine • void setQuery(Fact query) • void infer() • Vector getLies() • Vector getContradictions() • void accept(Fact accepted) • void contradict(Fact contradicted) • void addOn(…)

  14. Inference Engine (cont’d) • switch-on된 node들에 대해 breadth-first search • 각각의 관계는 다음과 같다. • Concept : 그 자신이 속한 모든 Fact들을 on • Fact : 자신에게 속한 모든 Concept들과 Relation을 on • Relation : 해당 relation이 조건부가 되는 모든 Rule들을 on • Rule : 결론부로서 derive된 Fact를 on • 이 과정을, 더 이상 추가로 on되는 node가 없을 때까지 반복한다.

  15. Inference Engine (cont’d) • public void on(IEngine ie, Fact fact) • // 새로 들어온 fact를 print • // 해당 fact의 concept들을 substitutes에 add • // i번째 premise와 match하는 경우 • // premise와 negation이 반대인 경우 전혀 가치없는 fact이므로 그대로 종료 • // 알맞은 substitutes 공간에 fact의 concept들을 각각 add • // 애초에 premise의 해당 term이 variable이 아니라 constant concept이면 add 안함 • // 그 외에도 중복되지 않는 경우에 한해서만 add • // 새로 add된 concept이 먼저 check가 되도록 맨 앞에 add함 • // 다른 premise에 대해서는 볼 일이 없으므로 loop를 탈출 • // 아직 모든 premise가 on되지 않은 경우, conclusion은 무조건 false이므로 그대로 종료. • // 단, negative premise에 대해서는 check하지 않음. 하나라도 참인 fact가 derive되면 해당 premise가 on되어 버리므로... • // 각 variable이 현재 가지고 있는 모든 substitute들의 조합을 가지고 주어진 rule을 만족하는지 check하는 것이므로, • // 아래와 같이 전체 iteration 횟수 n을 구함 • // substitute가 하나도 없는 variable이 있으면 rule match가 안되므로 그대로 종료 • // 모든 가능한 substitute의 조합에 대해 rule match를 수행 • // loopVariable[i] : i번째 variable의 substitute들 중에 몇 번째 concept을 현재 iteration에서의 조합으로 취할지를 가리킴 • // ex> loopVairable[0], [1], [2]가 각각 3, 4, 5 라면, substitutes[0], [1], [2] 에서 각각 3, 4, 5번째 concept을 취하는 것. • // 이것이 끝까지 true이면, 해당 iteration에서의 조합이 올바른 fact임을 의미 • // rule match는 각 premise에 대해 수행되며, 모든 premise에서 true가 나와야 올바른 fact가 됨 • // 해당 premise에서 사용되는 variable/concept들의 index • // test할 조합을 만듦 • // index 값에 따라 usedConcept 또는 substitutes에서 concept을 가져와 조합을 만듦 • // test할 조합을 print • // test를 수행. 이때 isTrue 대신 isAlreadyDerived를 쓰는 편이 검사할 fact의 개수가 적어서 더 빠르다. • // Concept-relation network의 장점 중 하나가 바로, 기존의 모든 fact들에 대해 검사할 필요가 없다는 점임 • // 위에서 선택한 substitute의 조합이 모든 premise에 대해 true가 나온 경우 • // conclusion에 대한 fact를 만듦 • // match된 이 rule과, 이 rule로부터 derive된 fact를 print • // 다음 iteration에서의 concept의 조합을 계산 • // 가장 마지막 variable부터 개수를 늘려줌 • // n자리 10진수에 1을 더했을 때를 생각하면 됨 • // 현재 숫자가 1188이라면, 1188 + 1 = 1189로 맨 끝자리만 계산하면 되지만, 1189 + 1 = 1190 으로 • // 1의자리는 0으로 만들고, 다시 10의자리에 1을 더해줘야 함. 1199 + 1 = 1200 의 경우도 마찬가지.

  16. Knowledge Generator

  17. Knowledge Generator (cont’d) • class KnowledgeGenerator • Vector conjunctConcepts(Vector conjuncted, String added) • Fact[] addFacts(KnowledgeBase kb, Vector premises) • Vector premiseZero(Vector conjuncted, String relation, boolean isNegated); • Vector premiseN(Vector conjuncted, String rconj, String relation, String[] tconj, Vector[] targets, boolean isNegated); • Vector buildRule(Vector conditions, Vector matched, Vector unmatched); • Rule[] addRule(KnowledgeBase kb, Vector vectoredRules); • int setN(Vector conjuncted); • String negates(String relation); • int readInt();

  18. Natural Language Recognizer

  19. NLR (cont’d) • <YYINITIAL> ({LETTER}|{DIGIT}|_)* { • … • else if(yytext().equals("if") | yytext().equals("If")) • tokenID = sym.IF; • else if(yytext().equals("but") | • yytext().equals("But") | • yytext().equals("However") | • yytext().equals("however") | • yytext().equals("even though") • | yytext().equals("Even though") • | yytext().equals("Nevertheless") • | yytext().equals("nevertheless")) • tokenID = sym.BUT; • … • }

  20. NLR (cont’d) • paragraph ::= statementList • statementList ::= statementList statement | statement • statement ::= facts:fs endmark {: parser.kg.addFacts(parser.kb, fs); :} | rule:r endmark {: parser.kg.addRule(parser.kb, r); :} | error endmark

  21. NLR (cont’d) • concept ::= concept ID | ID • facts ::= facts ANDOP fact | fact • conjunctedConcepts ::= conjunctedConcepts COMMA concept

  22. NLR (cont’d) • fact ::= conjunctedConcepts IS concept | conjunctedConcepts IS concept OF conjunctedConcepts | conjunctedConcepts DO ID conjunctedConcepts … • rule ::= IF facts THEN facts | IF facts THEN facts ELSE facts

  23. Planner • class Planner • Fact[] addQueries(KnowledgeBase kb, Vector premises);

  24. Example • C:\...\code>java ITS • (0: load, 1: save, 2: learn, 3: teach, 4: exit) ? 2 • West and is American. • East is criminal & East did sell sugar to China. • sugar is food. • China is hostile. • Scud, DaePoDong and Patriot are missile & Axe and Knife, Sasimi are weapon. • Nono is enemy of America. • West did sell Scud to Nono. • if _x is missilethen _x is weapon. • if _x is enemy of Americathen _x is hostile. • if _x did sell _y to _z & _x is American & _y is weapon & _z is hostilethen _x is criminal.

  25. Example (cont’d) • *** Contents of Knowledge Base *** • Facts: • West is American • ... • Scud is missile • Axe is weapon • East did sell sugar to China • sugar is food • China is hostile • Nono is enemy of America • West did sell Scud to Nono • Rules: • ( missile ) => weapon • ( enemy ) => hostile • ( sell American weapon hostile ) => criminal • (0: load, 1: save, 2: learn, 3: teach, 4: exit) ? 1

  26. Example (cont’d) • (0: load, 1: save, 2: learn, 3: teach, 4: exit) ? 3 • West is criminal. • On Concept: West • On Relation: • West is American • On Relation: • West did sell Scud to Nono • ... • Iteration 0: • Scud is missile • *** On ConnectPremise *** • ( missile ) => weapon • *** Newly Derived Fact *** • Scud is weapon

  27. Example (cont’d) • On Concept: America • Newly Added: • Nono is enemy of America • Iteration 0: • Nono is enemy of America • *** On ConnectPremise *** • ( enemy ) => hostile • *** Newly Derived Fact *** • Nono is hostile • ...

  28. Example (cont’d) • Iteration 0: • West did sell Scud to Nono • West is American • Scud is weapon • Nono is hostile • *** On ConnectPremise *** • ( sell American weapon hostile ) => criminal • *** Newly Derived Fact *** • West is criminal • ... • On Relation: • West is criminal • ** TrulyAccepted ** • West is criminal • ALL TRUE • (0: load, 1: save, 2: learn, 3: teach, 4: exit) ? 4 • C:\...\code>

More Related