L9. Matching Program in Java

Slides:



Advertisements
Similar presentations
Functional Programming Lecture 10 - type checking.
Advertisements

Some Prolog Prolog is a logic programming language
First-Order Logic.
Inference Rules Universal Instantiation Existential Generalization
Standard Logical Equivalences
Inference in first-order logic Chapter 9. Outline Reducing first-order inference to propositional inference Unification Generalized Modus Ponens Forward.
分決定グラフに基づく記号 モデル検査 BDD における論理演算 2. f  p =  f p S  p = S – S p 3. f p  q =f p  f q S p  q = S p  S q f p  q =f p  f q S p  q = S p  S.
Chapter 3 DATA: TYPES, CLASSES, AND OBJECTS. Chapter 3 Data Abstraction Abstract data types allow you to work with data without concern for how the data.
Inference and Reasoning. Basic Idea Given a set of statements, does a new statement logically follow from this. For example If an animal has wings and.
Horn Form A sentence is in Horn form if and only if ….
Is Charlie Brown a Loser? Do you think you know your real character? Do you actually know, for example, the good and bad points about yourself? It is.
SPIN. Seach Optimization Exhaustive search requires so much time and memory to perform verification realistically, must perform some shortcuts –reduce.
1 L11. An Example of Backward Chaining Program in Java An Rule Base System in Java RuleBaseSystem.java CarShop.data.
SPSSによるHosmer-Lemeshow検定について
7.n次の行列式   一般的な(n次の)行列式の定義には、数学的な概念がいろいろ必要である。まずそれらを順に見ていく。
9.線形写像.
時間的に変化する信号. 普通の正弦波 は豊富な情報を含んでいません これだけではラジオのような複雑な情報 を送れない 振幅 a あるいは角速度 ω を時間的に変化 させて情報を送る.
情報処理A 第10回 Excelの使い方 その3.
5.連立一次方程式.
清水彰一 写真の表示. はじめに 画像を Photo Albums から選択し表示するアプリ 手順 1. Xcode でプロジェクトの作成 2. Interface Builder で UI 部品を配置 3. Xcode で必要なクラスを定義 4. 各 UI 部品の結びつきのための変数を IBOutlet.
素数判定法 2011/6/20.
1章 行列と行列式.
フーリエ級数. 一般的な波はこのように表せる a,b をフーリエ級数とい う 比率:
Excelによる積分.
1 6.低次の行列式とその応用. 2 行列式とは 行列式とは、正方行列の特徴を表す一つのスカ ラーである。すなわち、行列式は正方行列からスカ ラーに写す写像の一種とみなすこともできる。 正方行列 スカラー(実数) の行列に対する行列式を、 次の行列式という。 行列 の行列式を とも表す。 行列式と行列の記号.
計算のスピードアップ コンピュータでも、sin、cosの計算は大変です 足し算、引き算、掛け算、割り算は早いです
4.プッシュダウンオートマトンと 文脈自由文法の等価性
1 9.線形写像. 2 ここでは、行列の積によって、写像を 定義できることをみていく。 また、行列の積によって定義される写 像の性質を調べていく。
通信路(7章).
結城諒 司 吉田成 樹 完成予定図 O N! 7セグLE D ランダム表 示 OF F ? 数字が出たら 勝ち!!
3.正方行列(単位行列、逆行列、対称行列、交代行列)
プログラミング演習B ML編 第3回 2010/6/15 (コミ) 2010/6/16 (情報・知能) 住井 ~sumii/class/proenb2010/ml3/
C言語応用 構造体.
プログラミング演習B ML編 第3回 2006/7/4 (通信コース) 2006/7/12 (情報コース) 住井 ~sumii/class/proenb2006/ml3/
Inference in First-Order Logic
Kitenet の解析 (110118) 九州大学 工学部 電気情報工学科 岡村研究室 久保 貴哉.
Inference in First-Order Logic Inference Rules with Quantifiers The three new inference rules are as follows: Universal Elimination: For any sentence ,
Vocabulary Chapter 6.
99/08/29Jafee 99 Lattice Calculation for Forward LIBOR Model Tadashi Uratani Hosei University and Makoto Utsunomiya Bank of Tokyo-Mitsubishi.
First-Order Logic Semantics Reading: Chapter 8, , FOL Syntax and Semantics read: FOL Knowledge Engineering read: FOL.
知能ソフトウェア特論 項書換え系(3) 合流性 Term Rewriting Systems(3) Confluence Intelligent Software.
Joining Adjectives て form for い adjectives and な adjectives.
11 Artificial Intelligence CS 165A Thursday, November 1, 2007  First-order logic (Ch 8)  Inference in FOL (Ch 9) 1.
1 Unification ( 統一 ) Forward Chaining ( 前向き仮説推理 ) Backward Chaining ( 後ろ向き仮説推理 ) Unification ( 統一 ) Forward Chaining ( 前向き仮説推理 ) Backward Chaining ( 後ろ向き仮説推理.
111 Artificial Intelligence CS 165A Tuesday, November 6, 2007  Inference in FOL (Ch 9) 1.
CS Introduction to AI Tutorial 8 Resolution Tutorial 8 Resolution.
1ApatiraUthman 2AtphasoukJason 3ChauMinh 4CohenDavid 5CookNathan 6de GuzmanArmand 7EdgcombAlex 8GarciaSteven 9HichbornGeoffrey 10HuiCharles 11KazemiAzadeh.
1 Unification ( 統一 ) Forward Chaining ( 前向き推論 ) Backward Chaining ( 後ろ向き推論 ) Unification ( 統一 ) Forward Chaining ( 前向き推論 ) Backward Chaining ( 後ろ向き推論 )
Artificial Intelligence 7. Making Deductive Inferences Course V231 Department of Computing Imperial College, London Jeremy Gow.
1 Inference in First Order Logic CS 171/271 (Chapter 9) Some text and images in these slides were drawn from Russel & Norvig’s published material.
ECE457 Applied Artificial Intelligence R. Khoury (2007)Page 1 Implication Truth Table If α is true, then β must be true for the implication to be true.
Wumpus World 1 Wumpus and 1 pile of gold in a pit-filled cave Starts in [1,1] facing right - Random cave Percepts: [smell, breeze, gold, bump, scream]
Inference in First Order Logic. Outline Reducing first order inference to propositional inference Unification Generalized Modus Ponens Forward and backward.
1 Forward Chaining based rule base system. Reasoning with Rules  Knowledge represented as if-then rules –Natural –Easy to understand –Each rule as a.
RELATIVE CLAUSES Adjectival Clauses/Modifiers. RELATIVE CLAUSES A relative clause is the part of a sentence which describes a noun Eg. The cake (which)
雪 ゆき. 雪や こんこ ゆき.
L3. Knowledge Representation and Matching in Java Matching.java Unify.java.
L An Example of Forward Chaining Program in Java
Where is Wumpus Propositional logic (cont…) Reasoning where is wumpus
L7. Logic for knowledge representation
Effective Propositional Logic Search
L9. Planning Agents L7_exAnswer and explanation Review
10. A rule based system Forward Chaining based rule base system.
Inference in first-order logic part 1
L7. Logic for knowledge representation
L An Example of Forward Chaining Program in Java
Inference in first-order logic part 1
Unification Unification (Unify.java) Doing exercises.
L9. Matching Program in Java
L10. Unify Program in Java Unify.java.
Presentation transcript:

L9. Matching Program in Java Matching.java Solutions to L8ex using Vector Matsumoto’s solution2

Unify Unification function, Unify, is to take two atomic sentences p and q and return a substitution that would make p and q look the same. A substitute  unifies atomic sentences p and q if p  =q  For example, p q  ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Knows(John, x) | Knows(John, Jane) | {x/Jane} Knows(John, x) | Knows(y, OJ) | {y/John, x/OJ} Knows(John, x) | Knows(y, Mother(y)) | {y/John, x/Mother(John)} e.g., Unify(Knows(John, x), Knows(John, Jane)) = {x/Jane} Idea: Unify rule premises with known facts, apply unifier to conclusion. e.g., if we know q and Knows(John, x) Likes(John, x) then we can conclude Likes(John, Jane) Likes(John, OJ) Likes(John, Mother(John)) Premise 前提

The three new inference rules added to FOL R(8) Universal-Elimination: For any sentence , variable v, and ground term g: e. g.,  x Likes(x, IceCream), we can use the substitute {x/Rose} and infer Like(Rose, IceCream). R(9) Existential-Elimination: For any sentence , variable v, and constant symbol k that does not appear elsewhere in the knowledge base: e. g.,  x Kill(x, Victim), we can infer Kill(Murderer, Victim), as long as Murderer does not appear elsewhere in the knowledge base. R(10) Existential-Introduction: For any sentence , variable v that does not occur in , and ground term g that does occur in : e. g., from Likes(Rose, IceCream) we can infer  x Likes(x, IceCream). SUBST({v/g}, )  v  Ground term is a term that contains no variables.  v/g SUBST({v/k}, )  v   k  v SUBST({g/v}, ) 

Example of proof Bob is a buffalo | 1. Buffalo(Bob) Pat is a pig | 2. Pig(Pat) Buffaloes outrun pigs | 3.  x, y Buffalo(x)  Pig(y)  Faster(x,y) ---------------------------------------------------------------------------------------------------- Bob outruns Pat --------------------------------------------------------------------------------------------------- Apply R(3) to 1 And 2 | 4. Buffalo(Bob)  Pig(Pat) Apply R(8) to 3 {x/Bob, y/Pat} | 5. Buffalo(Bob)  Pig(Pat)  Faster(Bob,Pat) Apply R(1) to 4 And 5 | 6. Faster(Bob,Pat)

String matching: string1 = string2 e.g. “rose” = “rose” if string1.equals(string2) “I am Rose” = “I am Rose” “I am ?x” = “I am Rose” “I am ?x” = “?y am Rose” I = ?y am = am ?x = Rose 40: // 同じなら成功 41: if(string1.equals(string2)) return true; ? Check? String  Tokens 36: public boolean matching(String string1,String string2){ 37: System.out.println(string1); 38: System.out.println(string2);   // 同じなら成功 41: if(string1.equals(string2)) return true;   // 各々トークンに分ける 44: st1 = new StringTokenizer(string1); 45: st2 = new StringTokenizer(string2);   // 数が異なったら失敗 48: if (st1.countTokens() != st2.countTokens()) 49: return false; 51: int length = st1.countTokens(); // 定数同士 52: for (int i = 0 ; i < length; i++){ 53: if (!tokenMatching(st1.nextToken(),st2.nextToken())){   // トークンが一つでもマッチングに失敗したら失敗 55: return false; 56: } 57: }

Token matching: token1 = token2 e.g. two strings’ matching, “I am ?x” = “?y am Rose” Three pairs of tokens’ matching: I = ?y am = am ?x = Rose 64: boolean tokenMatching(String token1,String token2){ 65: if(token1.equals(token2)) return true; 66: if( var(token1) && !var(token2)) 67: return varMatching(token1,token2); 68: if(!var(token1) && var(token2)) 69: return varMatching(token2,token1); 70: return false; 71: } 73: boolean varMatching(String vartoken,String token){ 74: if(vars.containsKey(vartoken)){ 75: if(token.equals(vars.get(vartoken))){ 76: return true; 77: } else { 78: return false; 79: } 80: } else { 81: vars.put(vartoken,token); 82: } 83: return true; 84: } 86: boolean var(String str1){ 87: // 先頭が ? なら変数 88: return str1.startsWith("?"); 89: } 27: Matcher(){ 28: vars = new Hashtable(); 29: }

Exercise Test cases: 3 4 1. Input Matching.java source (from keyboard, do not use copy) 2. Understand it (read carefully) 3. Run the program (for various strings) 4. Modify the program so that the modified program is not sensitive to uppercase and lowercase Test cases: 3 4 "i am rose" "I am RoSe " F T "I am ?x" "I am Rose " T T "I am ?x" "I Am Rose " F T "I ?x ?x" "I am am " T T "I ?x ?x" "I am AM " F T "I ?x ?x" "I am rose " F F