def test_problems_1(self): inp = """fof(a1, axiom, p(a) => q(a)). fof(a2, axiom, q(a) => $false). fof(a3, axiom, $true => p(a)). fof(c, conjecture, $false).""" result = [ problem.Problem( premises=[ problem.AnnotatedFormula( logic="fof", name="a1", role=problem.FormulaRole.AXIOM, formula=logic.BinaryFormula( left=logic.PredicateExpression( predicate="p", arguments=[logic.Constant("a")]), operator=logic.BinaryConnective.IMPLICATION, right=logic.PredicateExpression( predicate="q", arguments=[logic.Constant("a")]), ), ), problem.AnnotatedFormula( logic="fof", name="a2", role=problem.FormulaRole.AXIOM, formula=logic.BinaryFormula( left=logic.PredicateExpression( predicate="q", arguments=[logic.Constant("a")]), operator=logic.BinaryConnective.IMPLICATION, right=logic.DefinedConstant.FALSUM, ), ), problem.AnnotatedFormula( logic="fof", name="a3", role=problem.FormulaRole.AXIOM, formula=logic.BinaryFormula( left=logic.DefinedConstant.VERUM, operator=logic.BinaryConnective.IMPLICATION, right=logic.PredicateExpression( predicate="p", arguments=[logic.Constant("a")]), ), ), ], conjecture=problem.AnnotatedFormula( logic="fof", name="c", role=problem.FormulaRole.CONJECTURE, formula=logic.DefinedConstant.FALSUM, ), ) ] self.check_parser(inp, result)
def parse(self, IRI, z="", simple_mode=True, *args, **kwargs): with subprocess.Popen(['java', '-Xmx2048m', '-jar', 'fowl-15.jar'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) as p: gateway = JavaGateway() # create entry point app = gateway.entry_point for line in p.stdout: if "Server started" in str(line): print(line) sentence_enum = [] i = 0 for next_pair in app.translateOntology(IRI): next_annotation = next_pair.getSecond() py_root = OWLParser.parseJavaToPython( node=next_pair.getFirst()) name = "axiom" + str(i) i = i + 1 # if (z == "") or (z in str(py_root)): if True: sentence = problem.AnnotatedFormula( logic="fof", name=name, role=problem.FormulaRole.AXIOM, formula=py_root, annotation=next_annotation) sentence_enum.append(sentence) inferences_enum = [] is_consistent = True i = 0 if not simple_mode: print("Inferences:") for inf in app.getInferences(IRI): i += 1 inferences_enum.append( problem.AnnotatedFormula( logic="fof", name="inference" + str(i), role=problem.FormulaRole.CONJECTURE, formula=OWLParser.parseJavaToPython( node=inf.getFirst()), annotation=inf.getSecond())) is_consistent = app.isConsistent() gateway.shutdown() finalProblem = problem.Problem(sentence_enum, inferences_enum) return finalProblem # sentence_enum, inferences_enum, is_consistent
def test_problems_2_1(self): inp = """fof(a1, axiom, (p(e) & p(b) & p(d)) => $false). fof(a2, axiom, p(e) => p(d)). fof(a3, axiom, $true => p(f)). fof(a4, axiom, p(a) => $false). fof(a5, axiom, p(c) => p(e)). fof(a6, axiom, $true => p(c)). fof(a7, axiom, $true => (f=b)). fof(c, conjecture, $false).""" result = [ problem.Problem( premises=[ problem.AnnotatedFormula( logic="fof", name="a1", role=problem.FormulaRole.AXIOM, formula=logic.BinaryFormula( left=logic.BinaryFormula( left=logic.PredicateExpression( predicate="p", arguments=[logic.Constant("e")]), operator=logic.BinaryConnective.CONJUNCTION, right=logic.BinaryFormula( left=logic.PredicateExpression( predicate="p", arguments=[logic.Constant("b")]), operator=logic.BinaryConnective. CONJUNCTION, right=logic.PredicateExpression( predicate="p", arguments=[logic.Constant("d")]), ), ), operator=logic.BinaryConnective.IMPLICATION, right=logic.DefinedConstant.FALSUM, ), ), problem.AnnotatedFormula( logic="fof", name="a2", role=problem.FormulaRole.AXIOM, formula=logic.BinaryFormula( left=logic.PredicateExpression( predicate="p", arguments=[logic.Constant("e")]), operator=logic.BinaryConnective.IMPLICATION, right=logic.PredicateExpression( predicate="p", arguments=[logic.Constant("d")]), ), ), problem.AnnotatedFormula( logic="fof", name="a3", role=problem.FormulaRole.AXIOM, formula=logic.BinaryFormula( left=logic.DefinedConstant.VERUM, operator=logic.BinaryConnective.IMPLICATION, right=logic.PredicateExpression( predicate="p", arguments=[logic.Constant("f")]), ), ), problem.AnnotatedFormula( logic="fof", name="a4", role=problem.FormulaRole.AXIOM, formula=logic.BinaryFormula( left=logic.PredicateExpression( predicate="p", arguments=[logic.Constant("a")]), operator=logic.BinaryConnective.IMPLICATION, right=logic.DefinedConstant.FALSUM, ), ), problem.AnnotatedFormula( logic="fof", name="a5", role=problem.FormulaRole.AXIOM, formula=logic.BinaryFormula( left=logic.PredicateExpression( predicate="p", arguments=[logic.Constant("c")]), operator=logic.BinaryConnective.IMPLICATION, right=logic.PredicateExpression( predicate="p", arguments=[logic.Constant("e")]), ), ), problem.AnnotatedFormula( logic="fof", name="a6", role=problem.FormulaRole.AXIOM, formula=logic.BinaryFormula( left=logic.DefinedConstant.VERUM, operator=logic.BinaryConnective.IMPLICATION, right=logic.PredicateExpression( predicate="p", arguments=[logic.Constant("c")]), ), ), problem.AnnotatedFormula( logic="fof", name="a7", role=problem.FormulaRole.AXIOM, formula=logic.BinaryFormula( left=logic.DefinedConstant.VERUM, operator=logic.BinaryConnective.IMPLICATION, right=logic.BinaryFormula( left=logic.Constant("f"), operator=logic.BinaryConnective.EQ, right=logic.Constant("b")), ), ), ], conjecture=problem.AnnotatedFormula( logic="fof", name="c", role=problem.FormulaRole.CONJECTURE, formula=logic.DefinedConstant.FALSUM, ), ) ] self.check_parser(inp, result)
def test_problems_2_2(self): inp = """fof(a1, axiom, $true => a=d). fof(a2, axiom, $true => p(g(f(a),b))). fof(a3, axiom, $true => f(d)=b). fof(a4, axiom, $true => g(b,b)=c). fof(a5, axiom, p(c) => $false). fof(c, conjecture, $false).""" result = [ problem.Problem( premises=[ problem.AnnotatedFormula( logic="fof", name="a1", role=problem.FormulaRole.AXIOM, formula=logic.BinaryFormula( left=logic.DefinedConstant.VERUM, operator=logic.BinaryConnective.IMPLICATION, right=logic.BinaryFormula( left=logic.Constant("a"), operator=logic.BinaryConnective.EQ, right=logic.Constant("d")), ), ), problem.AnnotatedFormula( logic="fof", name="a2", role=problem.FormulaRole.AXIOM, formula=logic.BinaryFormula( left=logic.DefinedConstant.VERUM, operator=logic.BinaryConnective.IMPLICATION, right=logic.PredicateExpression( predicate="p", arguments=[ logic.FunctorExpression( functor="g", arguments=[ logic.FunctorExpression( functor="f", arguments=[ logic.Constant("a") ]), logic.Constant("b") ]), ]), ), ), problem.AnnotatedFormula( logic="fof", name="a3", role=problem.FormulaRole.AXIOM, formula=logic.BinaryFormula( left=logic.DefinedConstant.VERUM, operator=logic.BinaryConnective.IMPLICATION, right=logic.BinaryFormula( left=logic.FunctorExpression( functor="f", arguments=[logic.Constant("d")]), operator=logic.BinaryConnective.EQ, right=logic.Constant("b")), ), ), problem.AnnotatedFormula( logic="fof", name="a4", role=problem.FormulaRole.AXIOM, formula=logic.BinaryFormula( left=logic.DefinedConstant.VERUM, operator=logic.BinaryConnective.IMPLICATION, right=logic.BinaryFormula( left=logic.FunctorExpression( functor="g", arguments=[ logic.Constant("b"), logic.Constant("b") ]), operator=logic.BinaryConnective.EQ, right=logic.Constant("c")), ), ), problem.AnnotatedFormula( logic="fof", name="a5", role=problem.FormulaRole.AXIOM, formula=logic.BinaryFormula( left=logic.PredicateExpression( predicate="p", arguments=[logic.Constant("c")]), operator=logic.BinaryConnective.IMPLICATION, right=logic.DefinedConstant.FALSUM, ), ), ], conjecture=problem.AnnotatedFormula( logic="fof", name="c", role=problem.FormulaRole.CONJECTURE, formula=logic.DefinedConstant.FALSUM, ), ) ] self.check_parser(inp, result)
def parse_problem(self, problem: dict) -> problem.Problem: return problem.Problem( premises=[self._parse_rec(p) for p in problem["premises"]], conjecture=self._parse_rec(problem["conjecture"]), imports=self._parse_rec(problem["imports"]), )