def resolutionKB(): nP = Arguments("P", negative=True) nQ = Arguments("Q", negative=True) Sentence1 = CnfSentence([nP, Q_symbol]) Sentence2 = CnfSentence([P_symbol]) return [Sentence1, Sentence2]
def createCnfSentence(people, isLiar=False): argument1 = literals[people[0]].getNegativeArg() sentences = [] for p in people[1:]: lit = literals[p] sentences.append(CnfSentence([argument1, lit if not isLiar else lit.getNegativeArg()])) sourcePeople = literals[people[0]] if not isLiar: p2, p3 = literals[people[1]].getNegativeArg(), literals[people[2]].getNegativeArg() sentences.append(CnfSentence([sourcePeople, p2, p3])) else: p2, p3 = literals[people[1]], literals[people[2]] sentences.append(CnfSentence([sourcePeople, p2, p3])) return sentences
def resolutionKB(): sentences = [] sentences.append(CnfSentence([P_1_1.getNegativeArg()])) sentences.append(CnfSentence([B_1_1.getNegativeArg(), P_1_2, P_2_1])) sentences.append(CnfSentence([P_1_2.getNegativeArg(), B_1_1])) sentences.append(CnfSentence([P_2_1.getNegativeArg(), B_1_1])) sentences.append(CnfSentence([B_2_1.getNegativeArg(), P_1_1, P_2_2, P_3_1])) sentences.append(CnfSentence([B_2_1, P_1_1.getNegativeArg()])) sentences.append(CnfSentence([B_2_1, P_2_2.getNegativeArg()])) sentences.append(CnfSentence([B_2_1, P_3_1.getNegativeArg()])) sentences.append(CnfSentence([B_1_1.getNegativeArg()])) sentences.append(CnfSentence([B_2_1])) return sentences
def resolutionKBPartb(): """ :return: CNF sentences knowledge base of part b """ cnfsentences = list() cnfsentences.append( CnfSentence([Amy.getNegativeArg(), Cal.getNegativeArg()])) cnfsentences.append(CnfSentence([Cal, Amy])) cnfsentences.append(CnfSentence([Bob.getNegativeArg(), Amy])) cnfsentences.append(CnfSentence([Bob.getNegativeArg(), Cal])) cnfsentences.append( CnfSentence([Amy.getNegativeArg(), Bob, Cal.getNegativeArg()])) cnfsentences.append(CnfSentence([Cal.getNegativeArg(), Bob])) cnfsentences.append(CnfSentence([Cal, Bob.getNegativeArg()])) return cnfsentences
def resolutionKB(): # The resolution cnfsentences knowledge base cnfsentences = [] cnfsentences.append(CnfSentence([mythical.getNegativeArg(), immortal])) cnfsentences.append(CnfSentence([mythical, mammal])) cnfsentences.append(CnfSentence([mythical, immortal.getNegativeArg()])) cnfsentences.append(CnfSentence([horned, immortal.getNegativeArg()])) cnfsentences.append(CnfSentence([horned, mammal.getNegativeArg()])) cnfsentences.append(CnfSentence([horned.getNegativeArg(), magical])) return cnfsentences
def resolutionKBParta(): """ :return: Cnf sentences knowledge base for part a """ cnfsentences = [] cnfsentences.append(CnfSentence([Cal, Amy.getNegativeArg()])) cnfsentences.append( CnfSentence([Bob.getNegativeArg(), Cal.getNegativeArg()])) cnfsentences.append(CnfSentence([Bob, Cal])) cnfsentences.append( CnfSentence([Cal.getNegativeArg(), Bob, Amy.getNegativeArg()])) cnfsentences.append(CnfSentence([Cal, Bob.getNegativeArg()])) cnfsentences.append(CnfSentence([Cal, Amy])) return cnfsentences
def resolutionKBParta(): KB = [] # sentence0 KB.append(CnfSentence(Door.values())) # sentence1 KB.append(CnfSentence([priest["A"].getNegativeArg(), Door["X"]])) KB.append(CnfSentence([priest["A"], Door["X"].getNegativeArg()])) # sentence2 KB.append(CnfSentence([priest["B"].getNegativeArg(), Door["Y"], Door["Z"]])) KB.append(CnfSentence([priest["B"], Door["Y"].getNegativeArg()])) KB.append(CnfSentence([priest["B"], Door["Z"].getNegativeArg()])) # sentence3 C = priest["C"] A = priest["A"] B = priest["B"] KB.append(CnfSentence([C.getNegativeArg(), A])) KB.append(CnfSentence([C.getNegativeArg(), B])) KB.append(CnfSentence([A.getNegativeArg(), B.getNegativeArg(), C])) # sentence4 D = priest["D"] X = Door["X"] Y = Door["Y"] KB.append(CnfSentence([D.getNegativeArg(), X])) KB.append(CnfSentence([D.getNegativeArg(), Y])) KB.append(CnfSentence([D, X.getNegativeArg(), Y.getNegativeArg()])) # sentence5 Z = Door["Z"] E = priest["E"] KB.append(CnfSentence([E.getNegativeArg(), X])) KB.append(CnfSentence([E.getNegativeArg(), Z])) KB.append(CnfSentence([E, X.getNegativeArg(), Z.getNegativeArg()])) # sentence6 F = priest["F"] KB.append(CnfSentence([F.getNegativeArg(), D, E])) KB.append(CnfSentence([F, D.getNegativeArg()])) KB.append(CnfSentence([F, E.getNegativeArg()])) # sentence7 G = priest["G"] KB.append(CnfSentence([G.getNegativeArg(), C.getNegativeArg(), F])) KB.append(CnfSentence([G, C])) KB.append(CnfSentence([G, F.getNegativeArg()])) # sentence8 H = priest["H"] KB.append(CnfSentence([G.getNegativeArg(), H.getNegativeArg(), A])) KB.append(CnfSentence([H, G])) KB.append(CnfSentence([H])) KB.append(CnfSentence([H, A.getNegativeArg()])) return KB
def resolutionKBPartb(): KB = [] # sentence0 KB.append(CnfSentence(Door.values())) # sentence1 A = priest["A"] G = priest["G"] KB.append(CnfSentence([priest["A"].getNegativeArg(), Door["X"]])) KB.append(CnfSentence([priest["A"], Door["X"].getNegativeArg()])) # sentence8 H = priest["H"] KB.append(CnfSentence([G.getNegativeArg(), H.getNegativeArg(), A])) KB.append(CnfSentence([H, G])) KB.append(CnfSentence([H])) KB.append(CnfSentence([H, A.getNegativeArg()])) # fragment1 C = priest["C"] KB.append(CnfSentence([C.getNegativeArg(), A])) KB.append(CnfSentence([C.getNegativeArg(), T])) KB.append(CnfSentence([A.getNegativeArg(), T.getNegativeArg(), C])) # fragment2 KB.append(CnfSentence([G.getNegativeArg(), C.getNegativeArg(), Q])) KB.append(CnfSentence([C, G])) KB.append(CnfSentence([Q.getNegativeArg(), G])) return KB