//
// 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);
}