コード例 #1
0
            public bool IsAnswer(Clause aClause) 
            {
                bool isAns = false;

                if (answerClause.IsEmpty())
                {
                    if (aClause.IsEmpty()) 
                    {
                        proofs.Add(new ProofFinal(aClause.GetProofStep(), new Dictionary<Variable, ITerm>()));
                        complete = true;
                        isAns = true;
                    }
                } else 
                {
                    if (aClause.IsEmpty()) 
                    {
                        // This should not happen
                        // as added an answer literal to sos, which
                        // implies the database (i.e. premises) are
                        // unsatisfiable to begin with.
                        throw new InvalidOperationException(
                                "Generated an empty clause while looking for an answer, implies original KB or usable is unsatisfiable");
                    }

                    if (aClause.IsUnitClause()
                            && aClause.IsDefiniteClause()
                            && aClause.GetPositiveLiterals()[0].AtomicSentence.GetSymbolicName().Equals(
                                            this.answerLiteral.AtomicSentence.GetSymbolicName())
                        )
                    {
                        IDictionary<Variable, ITerm> answerBindings = new Dictionary<Variable, ITerm>();
                        IList<ITerm> answerTerms =
                            aClause.GetPositiveLiterals()[0].AtomicSentence.GetArgs().Cast<ITerm>().ToList();
                        var idx = 0;
                        foreach (Variable v in this.answerLiteralVariables)
                        {
                            answerBindings[v] = answerTerms[idx];
                            idx++;
                        }
                        bool addNewAnswer = this.proofs.All(p => !p.GetAnswerBindings().Equals(answerBindings));
                        if (addNewAnswer)
                        {
                            this.proofs.Add(new ProofFinal(aClause.GetProofStep(), answerBindings));
                        }
                        isAns = true;
                    }
                }

                var ts = DateTime.Now - DateTime.MinValue;
                if (ts.TotalMilliseconds > finishTime) 
                {
                    this.complete = true;

                    // Indicate that I have run out of query time
                    this.timedOut = true;
                }

                return isAns;
            }
コード例 #2
0
        public Clause GetStandardizeApartResult(Clause clause, IStandardizeApartIndexical standardizeApartIndexical)
        {
            var toRename = variableCollector.CollectAllVariables(clause);
            IDictionary <Variable, ITerm> renameSubstitution = new Dictionary <Variable, ITerm>();

            foreach (var var in toRename)
            {
                Variable v = null;
                do
                {
                    v = new Variable(standardizeApartIndexical.GetPrefix()
                                     + standardizeApartIndexical.GetNextIndex());
                    // Ensure the new variable name is not already
                    // accidentally used in the sentence
                } while (toRename.Contains(v));

                renameSubstitution[var] = v;
            }

            if (renameSubstitution.Count > 0)
            {
                var literals = clause.GetLiterals().Select(l => this.substVisitor.Subst(renameSubstitution, l)).ToList();

                var renamed = new Clause(literals);
                renamed.SetProofStep(new ProofStepRenaming(renamed, clause.GetProofStep()));
                return(renamed);
            }

            return(clause);
        }
コード例 #3
0
 public ProofStepClauseDemodulation(Clause demodulated, Clause origClause,
                                    TermEquality assertion)
 {
     this.demodulated = demodulated;
     this.origClause  = origClause;
     this.assertion   = assertion;
     this.predecessors.Add(origClause.GetProofStep());
 }
コード例 #4
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());
 }
コード例 #5
0
 public ProofStepClauseBinaryResolvent(Clause resolvent, Clause parent1,
                                       Clause parent2, IDictionary <Variable, ITerm> subst, IDictionary <Variable, ITerm> renameSubst)
 {
     this.resolvent   = resolvent;
     this.parent1     = parent1;
     this.parent2     = parent2;
     this.subst       = subst;
     this.renameSubst = renameSubst;
     this.predecessors.Add(parent1.GetProofStep());
     this.predecessors.Add(parent2.GetProofStep());
 }
コード例 #6
0
 public override string GetJustification()
 {
     return(String.Format("Paramodulation: {0}, {1}, [{2}]", topClause.GetProofStep().GetStepNumber()
                          , equalityClause.GetProofStep().GetStepNumber(), assertion));
 }
コード例 #7
0
 public override string GetJustification()
 {
     return("Factor of " + factorOf.GetProofStep().GetStepNumber());
 }
コード例 #8
0
 public ProofStepClauseFactor(Clause factor, Clause factorOf)
 {
     this.factor   = factor;
     this.factorOf = factorOf;
     this.predecessors.Add(factorOf.GetProofStep());
 }
コード例 #9
0
 public override string GetJustification()
 {
     return("Demodulation: " + origClause.GetProofStep().GetStepNumber()
            + ", [" + assertion + "]");
 }
コード例 #10
0
 public override string GetJustification() {
     return "Chain from Clause: "
             + fromClause.GetProofStep().GetStepNumber();
 }
コード例 #11
0
 public ProofStepChainFromClause(Chain chain, Clause fromClause) {
     this.chain = chain;
     this.fromClause = fromClause;
     this.predecessors.Add(fromClause.GetProofStep());
 }