def parse(self, source, refdir=None): """ Parse a mixed FOF/CNF specification with includes. "source" is either a filename or a lexer initialized with the input text. "refdir" is the reference directory for TPTP includes. """ if not isinstance(source, Lexer): source, refdir = tptpLexer(source, refdir) while not source.TestTok(Token.EOFToken): source.CheckLit(["cnf", "fof", "include"]) if source.TestLit("cnf"): clause = parseClause(source) self.addClause(clause) elif source.TestLit("fof"): formula = parseWFormula(source) self.addFormula(formula) else: source.AcceptLit("include") source.AcceptTok(Token.OpenPar) name = source.LookLit()[1:-1] source.AcceptTok(Token.SQString) source.AcceptTok(Token.ClosePar) source.AcceptTok(Token.FullStop) self.parse(name, refdir)
def testClausification(self): """ Test conversion of wrapped formulas into lists of clauses. """ lex = Lexer(self.testformulas) while not lex.TestTok(Token.EOFToken): wf = parseWFormula(lex) clauses = wFormulaClausify(wf) enableDerivationOutput() print("==================") for c in clauses: print(c) toggleDerivationOutput()
def testCNFization(self): """ Test conversion of wrapped formulas into conjunctive normal form. """ lex = Lexer(self.testformulas) while not lex.TestTok(Token.EOFToken): wf = parseWFormula(lex) wf = wFormulaCNF(wf) enableDerivationOutput() self.assertTrue(wf.formula.isCNF()) deriv = wf.orderedDerivation() print("==================") for s in deriv: print(s) toggleDerivationOutput()