001 package aima.logic.fol.kb; 002 003 import aima.logic.fol.domain.DomainFactory; 004 import aima.logic.fol.domain.FOLDomain; 005 import aima.logic.fol.inference.InferenceProcedure; 006 007 /** 008 * @author Ciaran O'Reilly 009 * 010 */ 011 public class FOLKnowledgeBaseFactory { 012 013 public static FOLKnowledgeBase createKingsKnowledgeBase( 014 InferenceProcedure infp) { 015 FOLKnowledgeBase kb = new FOLKnowledgeBase(DomainFactory.kingsDomain(), 016 infp); 017 kb.tell("((King(x) AND Greedy(x)) => Evil(x))"); 018 kb.tell("King(John)"); 019 kb.tell("King(Richard)"); 020 kb.tell("Greedy(John)"); 021 022 return kb; 023 } 024 025 public static FOLKnowledgeBase createWeaponsKnowledgeBase( 026 InferenceProcedure infp) { 027 FOLKnowledgeBase kb = new FOLKnowledgeBase(DomainFactory 028 .weaponsDomain(), infp); 029 kb 030 .tell("( (((American(x) AND Weapon(y)) AND Sells(x,y,z)) AND Hostile(z)) => Criminal(x))"); 031 kb.tell(" Owns(Nono, M1)"); 032 kb.tell(" Missile(M1)"); 033 kb.tell("((Missile(x) AND Owns(Nono,x)) => Sells(West,x,Nono))"); 034 kb.tell("(Missile(x) => Weapon(x))"); 035 kb.tell("(Enemy(x,America) => Hostile(x))"); 036 kb.tell("American(West)"); 037 kb.tell("Enemy(Nono,America)"); 038 039 return kb; 040 } 041 042 public static FOLKnowledgeBase createLovesAnimalKnowledgeBase( 043 InferenceProcedure infp) { 044 FOLKnowledgeBase kb = new FOLKnowledgeBase(DomainFactory 045 .lovesAnimalDomain(), infp); 046 047 kb 048 .tell("FORALL x (FORALL y (Animal(y) => Loves(x, y)) => EXISTS y Loves(y, x))"); 049 kb 050 .tell("FORALL x (EXISTS y (Animal(y) AND Kills(x, y)) => FORALL z NOT(Loves(z, x)))"); 051 kb.tell("FORALL x (Animal(x) => Loves(Jack, x))"); 052 kb.tell("(Kills(Jack, Tuna) OR Kills(Curiosity, Tuna))"); 053 kb.tell("Cat(Tuna)"); 054 kb.tell("FORALL x (Cat(x) => Animal(x))"); 055 056 return kb; 057 } 058 059 public static FOLKnowledgeBase createRingOfThievesKnowledgeBase( 060 InferenceProcedure infp) { 061 FOLKnowledgeBase kb = new FOLKnowledgeBase(DomainFactory 062 .ringOfThievesDomain(), infp); 063 064 // s(x) => ~c(x) One who skis never gets caught 065 kb.tell("(Skis(x) => NOT(Caught(x)))"); 066 // c(x) => ~s(x) Those who are caught don't ever ski 067 kb.tell("(Caught(x) => NOT(Skis(x)))"); 068 // p(x,y) & c(y) => s(x) Jailbird parents have skiing kids 069 kb.tell("((Parent(x,y) AND Caught(y)) => Skis(x))"); 070 // s(x) & f(x,y) => s(y) All friends ski together 071 kb.tell("(Skis(x) AND Friend(x,y) => Skis(y))"); 072 // f(x,y) => f(y,x) Friendship is symmetric 073 kb.tell("(Friend(x,y) => Friend(y,x))"); 074 // FACTS 075 // 1. { p(Mike,Joe) } Premise 076 kb.tell("Parent(Mike, Joe)"); 077 // 2. { p(Janet,Joe) } Premise 078 kb.tell("Parent(Janet,Joe)"); 079 // 3. { p(Nancy,Mike) } Premise 080 kb.tell("Parent(Nancy,Mike)"); 081 // 4. { p(Ernie,Janet) } Premise 082 kb.tell("Parent(Ernie,Janet)"); 083 // 5. { p(Bert,Nancy) } Premise 084 kb.tell("Parent(Bert,Nancy)"); 085 // 6. { p(Red,Ernie) } Premise 086 kb.tell("Parent(Red,Ernie)"); 087 // 7. { f(Red,Bert) } Premise 088 kb.tell("Friend(Red,Bert)"); 089 // 8. { f(Drew,Nancy) } Premise 090 kb.tell("Friend(Drew,Nancy)"); 091 // 9. { c(Mike) } Premise 092 kb.tell("Caught(Mike)"); 093 // 10. { c(Ernie) } Premise 094 kb.tell("Caught(Ernie)"); 095 096 return kb; 097 } 098 099 // Note: see - 100 // http://logic.stanford.edu/classes/cs157/2008/lectures/lecture15.pdf 101 // slide 12 for where this test example was taken from. 102 public static FOLKnowledgeBase createABCEqualityKnowledgeBase( 103 InferenceProcedure infp, boolean includeEqualityAxioms) { 104 FOLDomain domain = new FOLDomain(); 105 domain.addConstant("A"); 106 domain.addConstant("B"); 107 domain.addConstant("C"); 108 109 FOLKnowledgeBase kb = new FOLKnowledgeBase(domain, infp); 110 111 kb.tell("B = A"); 112 kb.tell("B = C"); 113 114 if (includeEqualityAxioms) { 115 // Reflexivity Axiom 116 kb.tell("x = x"); 117 // Symmetry Axiom 118 kb.tell("(x = y => y = x)"); 119 // Transitivity Axiom 120 kb.tell("((x = y AND y = z) => x = z)"); 121 } 122 123 return kb; 124 } 125 126 // Note: see - 127 // http://logic.stanford.edu/classes/cs157/2008/lectures/lecture15.pdf 128 // slide 16,17, and 18 for where this test example was taken from. 129 public static FOLKnowledgeBase createABCDEqualityAndSubstitutionKnowledgeBase( 130 InferenceProcedure infp, boolean includeEqualityAxioms) { 131 FOLDomain domain = new FOLDomain(); 132 domain.addConstant("A"); 133 domain.addConstant("B"); 134 domain.addConstant("C"); 135 domain.addConstant("D"); 136 domain.addPredicate("P"); 137 domain.addFunction("F"); 138 139 FOLKnowledgeBase kb = new FOLKnowledgeBase(domain, infp); 140 141 kb.tell("F(A) = B"); 142 kb.tell("F(B) = A"); 143 kb.tell("C = D"); 144 kb.tell("P(A)"); 145 kb.tell("P(C)"); 146 147 if (includeEqualityAxioms) { 148 // Reflexivity Axiom 149 kb.tell("x = x"); 150 // Symmetry Axiom 151 kb.tell("(x = y => y = x)"); 152 // Transitivity Axiom 153 kb.tell("((x = y AND y = z) => x = z)"); 154 // Function F Substitution Axiom 155 kb.tell("((x = y AND F(y) = z) => F(x) = z)"); 156 // Predicate P Substitution Axiom 157 kb.tell("((x = y AND P(y)) => P(x))"); 158 } 159 160 return kb; 161 } 162 }