def testResPositions(self): """ Test the the function returning all possible literal positions of possible resolution partner works. The default version should return the clause/position pairs of all literals in the clause set. """ lexer = Lexer(self.spec) clauses = ClauseSet() clauses.parse(lexer) lexer = Lexer("hates(X,agatha)") lit = parseLiteral(lexer) pos = clauses.getResolutionLiterals(lit) self.assertTrue(len(pos), 21) print(pos)
def testResIndexedPositions(self): """ Test the the function returning all possible literal positions of possible resolution partner vie indexing works. The indexed version should return the clause/position pairs of all literals with opposite polarity and the same top symbol as the query literal. """ lexer = Lexer(self.spec) clauses = IndexedClauseSet() clauses.parse(lexer) lexer = Lexer("hates(X,agatha)") lit = parseLiteral(lexer) pos = clauses.getResolutionLiterals(lit) self.assertTrue(len(pos), 6) print(pos)
def parseUnitaryFormula(lexer): """ Parse a "unitary" formula (following TPTP-3 syntax terminology). This can be the first unitary formula of a binary formula, of course. """ if lexer.TestTok([Token.Universal, Token.Existential]): quantor = lexer.LookLit() lexer.Next() lexer.AcceptTok(Token.OpenSquare) res = parseQuantified(lexer, quantor) elif lexer.TestTok(Token.OpenPar): lexer.AcceptTok(Token.OpenPar) res = parseFormula(lexer) lexer.AcceptTok(Token.ClosePar) elif lexer.TestTok(Token.Negation): lexer.AcceptTok(Token.Negation) subform = parseUnitaryFormula(lexer) res = Formula("~", subform, None) else: lit = parseLiteral(lexer) res = Formula("", lit, None) return res