public bool isAnswer(Clause aClause)
{
bool isAns = false;
if (answerClause.isEmpty())
{
if (aClause.isEmpty())
{
proofs.Add(new ProofFinal(aClause.getProofStep(),
new Dictionary<Variable, Term>()));
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 ApplicationException(
"Generated an empty clause while looking for an answer, implies original KB or usable is unsatisfiable");
}
if (aClause.isUnitClause()
&& aClause.isDefiniteClause()
&& aClause.getPositiveLiterals()[0]
.getAtomicSentence().getSymbolicName().Equals(
answerLiteral.getAtomicSentence()
.getSymbolicName()))
{
Dictionary<Variable, Term> answerBindings = new Dictionary<Variable, Term>();
List<FOLNode> answerTerms = aClause.getPositiveLiterals()[
0].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(aClause.getProofStep(),
answerBindings));
}
isAns = true;
}
}
if (DateTime.UtcNow.Ticks > finishTime)
{
complete = true;
// Indicate that I have run out of query time
timedOut = true;
}
return isAns;
}