public object VisitTermEquality(TermEquality equality, object arg)
        {
            var newTerm1 = (ITerm)equality.Term1.Accept(this, arg);
            var newTerm2 = (ITerm)equality.Term2.Accept(this, arg);

            return(new TermEquality(newTerm1, newTerm2));
        }
Exemplo n.º 2
0
        static void fOL_Demodulation()
        {
            System.Console.WriteLine("-----------------");
            System.Console.WriteLine("Demodulation Demo");
            System.Console.WriteLine("-----------------");
            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addConstant("C");
            domain.addConstant("D");
            domain.addConstant("E");
            domain.addPredicate("P");
            domain.addFunction("F");
            domain.addFunction("G");
            domain.addFunction("H");
            domain.addFunction("J");

            FOLParser parser = new FOLParser(domain);

            Predicate    expression = (Predicate)parser.parse("P(A,F(B,G(A,H(B)),C),D)");
            TermEquality assertion  = (TermEquality)parser.parse("B = E");

            Demodulation demodulation  = new Demodulation();
            Predicate    altExpression = (Predicate)demodulation.apply(assertion, expression);

            System.Console.WriteLine("Demodulate '" + expression + "' with '" + assertion + "' to give");
            System.Console.WriteLine(altExpression.ToString());
            System.Console.WriteLine("and again to give");
            System.Console.WriteLine(demodulation.apply(assertion, altExpression).ToString());
            System.Console.WriteLine("");
        }
Exemplo n.º 3
0
        protected void testEqualityAndSubstitutionAxiomsKBabcdFFASucceeds(
            InferenceProcedure infp)
        {
            FOLKnowledgeBase akb = FOLKnowledgeBaseFactory
                                   .createABCDEqualityAndSubstitutionKnowledgeBase(infp, true);

            List <Term> terms = new List <Term>();

            terms.Add(new Constant("A"));
            Function fa = new Function("F", terms);

            terms = new List <Term>();
            terms.Add(fa);
            TermEquality query = new TermEquality(new Function("F", terms),
                                                  new Constant("A"));

            InferenceResult answer = akb.ask(query);

            Assert.IsTrue(null != answer);
            Assert.IsFalse(answer.isPossiblyFalse());
            Assert.IsTrue(answer.isTrue());
            Assert.IsFalse(answer.isUnknownDueToTimeout());
            Assert.IsFalse(answer.isPartialResultDueToTimeout());
            Assert.IsTrue(1 == answer.getProofs().Count);
            Assert.IsTrue(0 == answer.getProofs()[0].getAnswerBindings()
                          .Count);
        }
Exemplo n.º 4
0
            public object visitTermEquality(TermEquality equality, object arg)
            {
                Term newTerm1 = (Term)equality.getTerm1().accept(this, arg);
                Term newTerm2 = (Term)equality.getTerm2().accept(this, arg);

                return(new TermEquality(newTerm1, newTerm2));
            }
Exemplo n.º 5
0
        public void testSimpleAtomicNonExample()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addConstant("C");
            domain.addConstant("D");
            domain.addConstant("E");
            domain.addPredicate("P");
            domain.addFunction("F");
            domain.addFunction("G");
            domain.addFunction("H");
            domain.addFunction("J");

            FOLParser parser = new FOLParser(domain);

            Predicate    expression = (Predicate)parser.parse("P(A,G(x,B),C)");
            TermEquality assertion  = (TermEquality)parser.parse("G(A,y) = J(y)");

            Predicate altExpression = (Predicate)demodulation.apply(assertion,
                                                                    expression);

            Assert.IsNull(altExpression);
        }
Exemplo n.º 6
0
        public void testBypassReflexivityAxiom()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addConstant("C");
            domain.addPredicate("P");
            domain.addFunction("F");

            FOLParser parser = new FOLParser(domain);

            List <Literal> lits = new List <Literal>();
            Predicate      p1   = (Predicate)parser.parse("P(y, F(A,y))");

            lits.Add(new Literal(p1));

            Clause clExpression = new Clause(lits);

            TermEquality assertion = (TermEquality)parser.parse("x = x");

            Clause altClExpression = demodulation.apply(assertion, clExpression);

            Assert.IsNull(altClExpression);
        }
        protected void testEqualityNoAxiomsKBabcAEqualsCSucceeds(InferenceProcedure infp, bool expectedToFail)
        {
            FOLKnowledgeBase akb = FOLKnowledgeBaseFactory.createABCEqualityKnowledgeBase(infp, false);

            TermEquality query = new TermEquality(new Constant("A"), new Constant("C"));

            InferenceResult answer = akb.ask(query);

            Assert.IsTrue(null != answer);
            if (expectedToFail)
            {
                Assert.IsTrue(answer.isPossiblyFalse());
                Assert.IsFalse(answer.isTrue());
                Assert.IsFalse(answer.isUnknownDueToTimeout());
                Assert.IsFalse(answer.isPartialResultDueToTimeout());
                Assert.IsTrue(0 == answer.getProofs().Size());
            }
            else
            {
                Assert.IsFalse(answer.isPossiblyFalse());
                Assert.IsTrue(answer.isTrue());
                Assert.IsFalse(answer.isUnknownDueToTimeout());
                Assert.IsFalse(answer.isPartialResultDueToTimeout());
                Assert.IsTrue(1 == answer.getProofs().Size());
                Assert.IsTrue(0 == answer.getProofs().Get(0)
                              .getAnswerBindings().Size());
            }
        }
Exemplo n.º 8
0
 public ProofStepClauseDemodulation(Clause demodulated, Clause origClause, TermEquality assertion)
 {
     this.demodulated = demodulated;
     this.origClause  = origClause;
     this.assertion   = assertion;
     this.predecessors.Add(origClause.getProofStep());
 }
        protected void testEqualityAndSubstitutionNoAxiomsKBabcdFFASucceeds(InferenceProcedure infp, bool expectedToFail)
        {
            FOLKnowledgeBase akb = FOLKnowledgeBaseFactory.createABCDEqualityAndSubstitutionKnowledgeBase(infp, false);

            ICollection <Term> terms = CollectionFactory.CreateQueue <Term>();

            terms.Add(new Constant("A"));
            Function fa = new Function("F", terms);

            terms = CollectionFactory.CreateQueue <Term>();
            terms.Add(fa);
            TermEquality query = new TermEquality(new Function("F", terms), new Constant("A"));

            InferenceResult answer = akb.ask(query);

            Assert.IsTrue(null != answer);
            if (expectedToFail)
            {
                Assert.IsTrue(answer.isPossiblyFalse());
                Assert.IsFalse(answer.isTrue());
                Assert.IsFalse(answer.isUnknownDueToTimeout());
                Assert.IsFalse(answer.isPartialResultDueToTimeout());
                Assert.IsTrue(0 == answer.getProofs().Size());
            }
            else
            {
                Assert.IsFalse(answer.isPossiblyFalse());
                Assert.IsTrue(answer.isTrue());
                Assert.IsFalse(answer.isUnknownDueToTimeout());
                Assert.IsFalse(answer.isPartialResultDueToTimeout());
                Assert.IsTrue(1 == answer.getProofs().Size());
                Assert.IsTrue(0 == answer.getProofs().Get(0)
                              .getAnswerBindings().Size());
            }
        }
Exemplo n.º 10
0
        public AtomicSentence apply(TermEquality assertion,
                                    AtomicSentence expression)
        {
            AtomicSentence altExpression = null;

            IdentifyCandidateMatchingTerm icm = getMatchingSubstitution(assertion
                                                                        .getTerm1(), expression);

            if (null != icm)
            {
                Term replaceWith = substVisitor.subst(
                    icm.getMatchingSubstitution(), assertion.getTerm2());
                // Want to ignore reflexivity axiom situation, i.e. x = x
                if (!icm.getMatchingTerm().Equals(replaceWith))
                {
                    ReplaceMatchingTerm rmt = new ReplaceMatchingTerm();

                    // Only apply demodulation at most once on each call.
                    altExpression = rmt.replace(expression, icm.getMatchingTerm(),
                                                replaceWith);
                }
            }

            return(altExpression);
        }
Exemplo n.º 11
0
        public void testSimpleClauseNonExample()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addConstant("C");
            domain.addPredicate("P");
            domain.addFunction("F");

            FOLParser parser = new FOLParser(domain);

            ICollection <Literal> lits = CollectionFactory.CreateQueue <Literal>();
            Predicate             p1   = (Predicate)parser.parse("P(y, F(A,y))");

            lits.Add(new Literal(p1));

            Clause clExpression = new Clause(lits);

            TermEquality assertion = (TermEquality)parser.parse("F(x,B) = C");

            Clause altClExpression = demodulation.apply(assertion, clExpression);

            Assert.IsNull(altClExpression);
        }
Exemplo n.º 12
0
 public ProofStepClauseParamodulation(Clause paramodulated,
                                      Clause topClause, Clause equalityClause, TermEquality assertion)
 {
     this.paramodulated  = paramodulated;
     this.topClause      = topClause;
     this.equalityClause = equalityClause;
     this.assertion      = assertion;
     this.predecessors.Add(topClause.GetProofStep());
     this.predecessors.Add(equalityClause.GetProofStep());
 }
Exemplo n.º 13
0
 public object visitTermEquality(TermEquality equality, object arg)
 {
     foreach (Term t in equality.getArgs())
     {
         // Finish processing if have found a match
         if (null != matchingTerm)
         {
             break;
         }
         t.accept(this, null);
     }
     return(equality);
 }
Exemplo n.º 14
0
        public object visitTermEquality(TermEquality equality, object arg)
        {
            ArgData ad = (ArgData)arg;

            if (ad.negated)
            {
                ad.clauses.Get(ad.clauses.Size() - 1).addNegativeLiteral(equality);
            }
            else
            {
                ad.clauses.Get(ad.clauses.Size() - 1).addPositiveLiteral(equality);
            }
            return(equality);
        }
Exemplo n.º 15
0
        public Object visitTermEquality(TermEquality equality, Object arg)
        {
            ArgData ad = (ArgData)arg;

            if (ad.negated)
            {
                ad.clauses[ad.clauses.Count - 1].addNegativeLiteral(equality);
            }
            else
            {
                ad.clauses[ad.clauses.Count - 1].addPositiveLiteral(equality);
            }
            return(equality);
        }
Exemplo n.º 16
0
        public object VisitTermEquality(TermEquality equality, object arg)
        {
            ArgData ad = (ArgData)arg;

            if (ad.Negated)
            {
                ad.Clauses[ad.Clauses.Count - 1].AddNegativeLiteral(equality);
            }
            else
            {
                ad.Clauses[ad.Clauses.Count - 1].AddPositiveLiteral(equality);
            }
            return(equality);
        }
Exemplo n.º 17
0
 public void testTermEquality2()
 {
     try
     {
         TermEquality te = (TermEquality)parser
                           .parse("BrotherOf(John) = x)");
         Assert.AreEqual(te, new TermEquality(
                             getBrotherOfFunction(new Constant("John")), new Variable(
                                 "x")));
     }
     catch (RuntimeException)
     {
         Assert.Fail("RuntimeException thrown");
     }
 }
Exemplo n.º 18
0
 public void testTermEquality()
 {
     try
     {
         TermEquality te = (TermEquality)parser
                           .parse("BrotherOf(John) = EnemyOf(Saladin)");
         Assert.AreEqual(te.ToString(), (new TermEquality(
                                             getBrotherOfFunction(new Constant("John")),
                                             getEnemyOfFunction())).ToString());
     }
     catch (ApplicationException)
     {
         Assert.Fail("RuntimeException thrown");
     }
 }
Exemplo n.º 19
0
        public Clause apply(TermEquality assertion, Clause clExpression)
        {
            Clause altClExpression = null;

            foreach (Literal l1 in clExpression.getLiterals())
            {
                AtomicSentence altExpression = apply(assertion, l1
                                                     .getAtomicSentence());
                if (null != altExpression)
                {
                    // I have an alternative, create a new clause
                    // with the alternative and return
                    List <Literal> newLits = new List <Literal>();
                    foreach (Literal l2 in clExpression.getLiterals())
                    {
                        if (l1.Equals(l2))
                        {
                            newLits.Add(l1.newInstance(altExpression));
                        }
                        else
                        {
                            newLits.Add(l2);
                        }
                    }
                    // Only apply demodulation at most once on
                    // each call.
                    altClExpression = new Clause(newLits);
                    altClExpression.setProofStep(new ProofStepClauseDemodulation(
                                                     altClExpression, clExpression, assertion));
                    if (clExpression.isImmutable())
                    {
                        altClExpression.setImmutable();
                    }
                    if (!clExpression.isStandardizedApartCheckRequired())
                    {
                        altClExpression.setStandardizedApartCheckNotRequired();
                    }
                    break;
                }
            }

            return(altClExpression);
        }
Exemplo n.º 20
0
        public void testSimpleAtomicExamples()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addConstant("C");
            domain.addConstant("D");
            domain.addConstant("E");
            domain.addPredicate("P");
            domain.addFunction("F");
            domain.addFunction("G");
            domain.addFunction("H");
            domain.addFunction("J");

            FOLParser parser = new FOLParser(domain);

            Predicate expression = (Predicate)parser
                                   .parse("P(A,F(B,G(A,H(B)),C),D)");
            TermEquality assertion = (TermEquality)parser.parse("B = E");

            Predicate altExpression = (Predicate)demodulation.apply(assertion,
                                                                    expression);

            Assert.IsFalse(expression.Equals(altExpression));
            Assert
            .AreEqual("P(A,F(E,G(A,H(B)),C),D)", altExpression
                      .ToString());

            altExpression = (Predicate)demodulation
                            .apply(assertion, altExpression);

            Assert
            .AreEqual("P(A,F(E,G(A,H(E)),C),D)", altExpression
                      .ToString());

            assertion = (TermEquality)parser.parse("G(x,y) = J(x)");

            altExpression = (Predicate)demodulation.apply(assertion, expression);

            Assert.AreEqual("P(A,F(B,J(A),C),D)", altExpression.ToString());
        }
Exemplo n.º 21
0
        public void testSimpleClauseExamples()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addConstant("C");
            domain.addConstant("D");
            domain.addConstant("E");
            domain.addPredicate("P");
            domain.addPredicate("Q");
            domain.addPredicate("W");
            domain.addFunction("F");
            domain.addFunction("G");
            domain.addFunction("H");
            domain.addFunction("J");

            FOLParser parser = new FOLParser(domain);

            List <Literal> lits = new List <Literal>();
            Predicate      p1   = (Predicate)parser.parse("Q(z, G(D,B))");
            Predicate      p2   = (Predicate)parser.parse("P(x, G(A,C))");
            Predicate      p3   = (Predicate)parser.parse("W(z,x,u,w,y)");

            lits.Add(new Literal(p1));
            lits.Add(new Literal(p2));
            lits.Add(new Literal(p3));

            Clause clExpression = new Clause(lits);

            TermEquality assertion = (TermEquality)parser.parse("G(x,y) = x");

            Clause altClExpression = demodulation.apply(assertion, clExpression);

            Assert.AreEqual("[P(x,G(A,C)), Q(z,D), W(z,x,u,w,y)]",
                            altClExpression.ToString());

            altClExpression = demodulation.apply(assertion, altClExpression);

            Assert.AreEqual("[P(x,A), Q(z,D), W(z,x,u,w,y)]", altClExpression
                            .ToString());
        }
Exemplo n.º 22
0
        protected static void abcEqualityNoAxiomDemo(InferenceProcedure ip)
        {
            StandardizeApartIndexicalFactory.flush();

            FOLKnowledgeBase kb = FOLKnowledgeBaseFactory.createABCEqualityKnowledgeBase(ip, false);

            string kbStr = kb.ToString();

            TermEquality query = new TermEquality(new Constant("A"), new Constant("C"));

            InferenceResult answer = kb.ask(query);

            System.Console.WriteLine("ABC Equality No Axiom Knowledge Base:");
            System.Console.WriteLine(kbStr);
            System.Console.WriteLine("Query: " + query);
            foreach (Proof p in answer.getProofs())
            {
                System.Console.Write(ProofPrinter.printProof(p));
                System.Console.WriteLine("");
            }
        }
Exemplo n.º 23
0
        public List <Clause> apply(Clause c1, Clause c2, bool standardizeApart)
        {
            List <Clause> paraExpressions = new List <Clause>();

            for (int i = 0; i < 2; i++)
            {
                Clause topClause, equalityClause;
                if (i == 0)
                {
                    topClause      = c1;
                    equalityClause = c2;
                }
                else
                {
                    topClause      = c2;
                    equalityClause = c1;
                }

                foreach (Literal possEqLit in equalityClause.getLiterals())
                {
                    // Must be a positive term equality to be used
                    // for paramodulation.
                    if (possEqLit.isPositiveLiteral() &&
                        possEqLit.getAtomicSentence() is TermEquality)
                    {
                        TermEquality assertion = (TermEquality)possEqLit
                                                 .getAtomicSentence();

                        // Test matching for both sides of the equality
                        for (int x = 0; x < 2; x++)
                        {
                            Term toMatch, toReplaceWith;
                            if (x == 0)
                            {
                                toMatch       = assertion.getTerm1();
                                toReplaceWith = assertion.getTerm2();
                            }
                            else
                            {
                                toMatch       = assertion.getTerm2();
                                toReplaceWith = assertion.getTerm1();
                            }

                            foreach (Literal l1 in topClause.getLiterals())
                            {
                                IdentifyCandidateMatchingTerm icm = getMatchingSubstitution(
                                    toMatch, l1.getAtomicSentence());

                                if (null != icm)
                                {
                                    Term replaceWith = substVisitor.subst(icm
                                                                          .getMatchingSubstitution(),
                                                                          toReplaceWith);

                                    // Want to ignore reflexivity axiom situation,
                                    // i.e. x = x
                                    if (icm.getMatchingTerm().Equals(replaceWith))
                                    {
                                        continue;
                                    }

                                    ReplaceMatchingTerm rmt = new ReplaceMatchingTerm();

                                    AtomicSentence altExpression = rmt.replace(l1
                                                                               .getAtomicSentence(), icm
                                                                               .getMatchingTerm(), replaceWith);

                                    // I have an alternative, create a new clause
                                    // with the alternative and the substitution
                                    // applied to all the literals before returning
                                    List <Literal> newLits = new List <Literal>();
                                    foreach (Literal l2 in topClause.getLiterals())
                                    {
                                        if (l1.Equals(l2))
                                        {
                                            newLits
                                            .Add(l1
                                                 .newInstance((AtomicSentence)substVisitor
                                                              .subst(
                                                                  icm
                                                                  .getMatchingSubstitution(),
                                                                  altExpression)));
                                        }
                                        else
                                        {
                                            newLits
                                            .Add(substVisitor
                                                 .subst(
                                                     icm
                                                     .getMatchingSubstitution(),
                                                     l2));
                                        }
                                    }
                                    // Assign the equality clause literals,
                                    // excluding
                                    // the term equality used.
                                    foreach (Literal l2 in equalityClause.getLiterals())
                                    {
                                        if (possEqLit.Equals(l2))
                                        {
                                            continue;
                                        }
                                        newLits.Add(substVisitor.subst(icm
                                                                       .getMatchingSubstitution(), l2));
                                    }

                                    // Only apply paramodulation at most once
                                    // for each term equality.
                                    Clause nc = null;
                                    if (standardizeApart)
                                    {
                                        sApart.standardizeApart(newLits,
                                                                _emptyLiteralList, _saIndexical);
                                        nc = new Clause(newLits);
                                    }
                                    else
                                    {
                                        nc = new Clause(newLits);
                                    }
                                    nc
                                    .setProofStep(new ProofStepClauseParamodulation(
                                                      nc, topClause, equalityClause,
                                                      assertion));
                                    if (c1.isImmutable())
                                    {
                                        nc.setImmutable();
                                    }
                                    if (!c1.isStandardizedApartCheckRequired())
                                    {
                                        c1.setStandardizedApartCheckNotRequired();
                                    }
                                    paraExpressions.Add(nc);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            return(paraExpressions);
        }
Exemplo n.º 24
0
        public IInferenceResult Ask(FOLKnowledgeBase KB, ISentence alpha) 
        {
            ISet<Clause> sos = new HashedSet<Clause>();
            ISet<Clause> usable = new HashedSet<Clause>();

            // Usable set will be the set of clauses in the KB,
            // are assuming this is satisfiable as using the
            // ISet of Support strategy.
            //foreach (var standardizedC in KB.GetAllClauses().Select(c => KB.StandardizeApart(c)))
            foreach (var standardizedC in KB.GetAllClauses())
            {
                standardizedC.SetStandardizedApartCheckNotRequired();
                usable.UnionWith(standardizedC.GetFactors());
            }

            // Ensure reflexivity axiom is added to usable if using paramodulation.
            if (this.UseParamodulation) 
            {
                // Reflexivity Axiom: x = x
                var reflexivityAxiom = new TermEquality(new Variable("x"), new Variable("x"));
                var reflexivityClause = new Clause();
                reflexivityClause.AddLiteral(new Literal(reflexivityAxiom));
                reflexivityClause = KB.StandardizeApart(reflexivityClause);
                reflexivityClause.SetStandardizedApartCheckNotRequired();
                usable.Add(reflexivityClause);
            }

            ISentence notAlpha = new NotSentence(alpha);
            // Want to use an answer literal to pull
            // query variables where necessary
            var answerLiteral = KB.CreateAnswerLiteral(notAlpha);
            var answerLiteralVariables = KB
                    .CollectAllVariables(answerLiteral.AtomicSentence);
            var answerClause = new Clause();

            if (answerLiteralVariables.Count > 0) {
                ISentence notAlphaWithAnswer = new ConnectedSentence(Connectors.Or,
                        notAlpha, answerLiteral.AtomicSentence);
               // foreach (var standardizedC in
              //      KB.ConvertToClauses(notAlphaWithAnswer).Select(KB.StandardizeApart))
                  foreach (var standardizedC in
                      KB.ConvertToClauses(notAlphaWithAnswer))
                   {
                       Clause c = KB.StandardizeApart(standardizedC);
                       c.SetProofStep(new ProofStepGoal(c));
                       c.SetStandardizedApartCheckNotRequired();
                       sos.UnionWith(c.GetFactors());
                   }

                answerClause.AddLiteral(answerLiteral);
            } 
            else 
            {
                //foreach (var standardizedC in
                //    KB.ConvertToClauses(notAlpha).Select(KB.StandardizeApart)) 
                foreach (var standardizedC in
                    KB.ConvertToClauses(notAlpha))
                {
                    Clause c = KB.StandardizeApart(standardizedC);
                    c.SetProofStep(new ProofStepGoal(c));
                    c.SetStandardizedApartCheckNotRequired();
                    sos.UnionWith(standardizedC.GetFactors());
                }
            }

            // Ensure all subsumed clauses are removed
            usable.ExceptWith(SubsumptionElimination.FindSubsumedClauses(usable));
            sos.ExceptWith(SubsumptionElimination.FindSubsumedClauses(sos));

            var ansHandler = new OTTERAnswerHandler(answerLiteral,
                    answerLiteralVariables, answerClause, this.MaxQueryTime);

            var idxdClauses = new IndexedClauses(LightestClauseHeuristic, sos, usable);

            return this.Otter(ansHandler, idxdClauses, sos, usable);
        }
Exemplo n.º 25
0
 public Object visitTermEquality(TermEquality equality, Object arg)
 {
     return(arg);
 }
Exemplo n.º 26
0
 public object VisitTermEquality(TermEquality equality, object arg)
 {
     return(equality);
 }
Exemplo n.º 27
0
 public object visitTermEquality(TermEquality equality, object arg)
 {
     equality.getTerm1().accept(this, arg);
     equality.getTerm2().accept(this, arg);
     return(equality);
 }
Exemplo n.º 28
0
 public Object visitTermEquality(TermEquality equality, Object arg)
 {
     throw new InvalidOperationException("Should not be called");
 }
        // START-InferenceProcedure
        public InferenceResult ask(FOLKnowledgeBase KB, Sentence alpha)
        {
            List <Clause> sos    = new List <Clause>();
            List <Clause> usable = new List <Clause>();

            // Usable set will be the set of clauses in the KB,
            // are assuming this is satisfiable as using the
            // Set of Support strategy.
            foreach (Clause c in KB.getAllClauses())
            {
                Clause c2 = KB.standardizeApart(c);
                c2.setStandardizedApartCheckNotRequired();
                usable.AddRange(c2.getFactors());
            }

            // Ensure reflexivity axiom is added to usable if using paramodulation.
            if (isUseParamodulation())
            {
                // Reflexivity Axiom: x = x
                TermEquality reflexivityAxiom = new TermEquality(new Variable("x"),
                                                                 new Variable("x"));
                Clause reflexivityClause = new Clause();
                reflexivityClause.addLiteral(new Literal(reflexivityAxiom));
                reflexivityClause = KB.standardizeApart(reflexivityClause);
                reflexivityClause.setStandardizedApartCheckNotRequired();
                usable.Add(reflexivityClause);
            }

            Sentence notAlpha = new NotSentence(alpha);
            // Want to use an answer literal to pull
            // query variables where necessary
            Literal         answerLiteral          = KB.createAnswerLiteral(notAlpha);
            List <Variable> answerLiteralVariables = KB
                                                     .collectAllVariables(answerLiteral.getAtomicSentence());
            Clause answerClause = new Clause();

            if (answerLiteralVariables.Count > 0)
            {
                Sentence notAlphaWithAnswer = new ConnectedSentence(Connectors.OR,
                                                                    notAlpha, answerLiteral.getAtomicSentence());
                foreach (Clause c in KB.convertToClauses(notAlphaWithAnswer))
                {
                    Clause c2 = KB.standardizeApart(c);
                    c2.setProofStep(new ProofStepGoal(c2));
                    c2.setStandardizedApartCheckNotRequired();
                    sos.AddRange(c2.getFactors());
                }

                answerClause.addLiteral(answerLiteral);
            }
            else
            {
                foreach (Clause c in KB.convertToClauses(notAlpha))
                {
                    Clause c2 = KB.standardizeApart(c);
                    c2.setProofStep(new ProofStepGoal(c2));
                    c2.setStandardizedApartCheckNotRequired();
                    sos.AddRange(c2.getFactors());
                }
            }

            // Ensure all subsumed clauses are removed
            foreach (Clause c in SubsumptionElimination.findSubsumedClauses(usable))
            {
                usable.Remove(c);
            }
            foreach (Clause c in SubsumptionElimination.findSubsumedClauses(sos))
            {
                sos.Remove(c);
            }

            OTTERAnswerHandler ansHandler = new OTTERAnswerHandler(answerLiteral,
                                                                   answerLiteralVariables, answerClause, maxQueryTime);

            IndexedClauses idxdClauses = new IndexedClauses(
                getLightestClauseHeuristic(), sos, usable);

            return(otter(ansHandler, idxdClauses, sos, usable));
        }
Exemplo n.º 30
0
 public object VisitTermEquality(TermEquality equality, object arg)
 {
     equality.Term1.Accept(this, arg);
     equality.Term2.Accept(this, arg);
     return(equality);
 }