Пример #1
0
    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)
Пример #2
0
    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
Пример #3
0
 def visit_annotated_formula(self, obj, **kwargs):
     return problem.AnnotatedFormula(
         logic=obj.children[0],
         name=obj.children[1],
         role=self._ROLE_MAP[obj.children[2]],
         formula=self.visit(obj.children[3], **kwargs),
     )
Пример #4
0
 def parse_annotated_formula(self, anno: dict):
     return problem.AnnotatedFormula(
         formula=self._parse_rec(anno["formula"]),
         name=anno["name"],
         role=self._parse_rec(anno["role"]),
         logic=anno["logic"],
     )
Пример #5
0
 def test_functor(self):
     inp = """cnf(and_definition1,axiom,( and(X,n0) = n0 ))."""
     result = problem.AnnotatedFormula(
         logic="cnf",
         name="and_definition1",
         role=problem.FormulaRole.AXIOM,
         formula=logic.BinaryFormula(
             left=logic.FunctorExpression(
                 functor="and",
                 arguments=[logic.Variable("X"),
                            logic.Constant("n0")]),
             operator=logic.BinaryConnective.EQ,
             right=logic.Constant("n0"),
         ),
     )
     self.check_parser(inp, result)
Пример #6
0
 def test_verum(self):
     inp = """fof(mElmSort,axiom,(
 ! [W0] :
   ( aElement0(W0)
  => $true ) ))."""
     result = problem.AnnotatedFormula(
         logic="fof",
         name="mElmSort",
         role=problem.FormulaRole.AXIOM,
         formula=logic.QuantifiedFormula(
             quantifier=logic.Quantifier.UNIVERSAL,
             variables=[logic.Variable("W0")],
             formula=logic.BinaryFormula(
                 left=logic.PredicateExpression(
                     predicate="aElement0",
                     arguments=[logic.Variable("W0")]),
                 operator=logic.BinaryConnective.IMPLICATION,
                 right=logic.DefinedConstant.VERUM,
             ),
         ),
     )
     self.check_parser(inp, result)
Пример #7
0
    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)
Пример #8
0
    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)