public bool isAnswer(Chain nearParent)
{
bool isAns = false;
if (answerChain.isEmpty())
{
if (nearParent.isEmpty())
{
proofs.Add(new ProofFinal(nearParent.getProofStep(),
new Dictionary<Variable, Term>()));
complete = true;
isAns = true;
}
}
else
{
if (nearParent.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 ApplicationException(
"Generated an empty chain while looking for an answer, implies original KB is unsatisfiable");
}
if (1 == nearParent.getNumberLiterals()
&& nearParent.getHead().getAtomicSentence()
.getSymbolicName().Equals(
answerChain.getHead()
.getAtomicSentence()
.getSymbolicName()))
{
Dictionary<Variable, Term> answerBindings = new Dictionary<Variable, Term>();
List<FOLNode> answerTerms = nearParent.getHead()
.getAtomicSentence().getArgs();
int idx = 0;
foreach (Variable v in answerLiteralVariables)
{
answerBindings.Add(v, (Term) answerTerms[idx]);
idx++;
}
bool addNewAnswer = true;
foreach (Proof.Proof p in proofs)
{
if (p.getAnswerBindings().Equals(answerBindings))
{
addNewAnswer = false;
break;
}
}
if (addNewAnswer)
{
proofs.Add(new ProofFinal(nearParent.getProofStep(),
answerBindings));
}
isAns = true;
}
}
if (DateTime.Now.Ticks > finishTime)
{
complete = true;
// Indicate that I have run out of query time
timedOut = true;
}
return isAns;
}