Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
* function FOL-FC-ASK(KB, alpha) returns a substitution or false
* inputs: KB, the knowledge base, a set of first order definite clauses
* alpha, the query, an atomic sentence
* local variables: new, the new sentences inferred on each iteration
*
* repeat until new is empty
* new <- {}
* for each rule in KB do
* (p1 ˆ ... ˆ pn => q) <- STANDARDIZE-VARAIBLES(rule)
* for each theta such that SUBST(theta, p1 ˆ ... ˆ pn) = SUBST(theta, p'1 ˆ ... ˆ p'n)
* for some p'1,...,p'n in KB
* q' <- SUBST(theta, q)
* if q' does not unify with some sentence already in KB or new then
* add q' to new
* theta <- UNIFY(q', alpha)
* if theta is not fail then return theta
* add new to KB
* return false
*
*
* Figure 9.3 A conceptually straightforward, but very inefficient
* forward-chaining algo- rithm. On each iteration, it adds to KB all the atomic
* sentences that can be inferred in one step from the implication sentences and
* the atomic sentences already in KB. The function STANDARDIZE-VARIABLES
* replaces all variables in its arguments with new ones that have not been used
* before.
*
* @author Ciaran O'Reilly
*
*/
public class FOLFCAsk implements InferenceProcedure {
public FOLFCAsk() {
}
//
// START-InferenceProcedure
/**
* FOL-FC-ASK returns a substitution or false.
*
* @param KB
* the knowledge base, a set of first order definite clauses
* @param query
* the query, an atomic sentence
*
* @return a substitution or false
*/
public InferenceResult ask(FOLKnowledgeBase KB, Sentence query) {
// Assertions on the type of queries this Inference procedure
// supports
if (!(query instanceof AtomicSentence)) {
throw new IllegalArgumentException(
"Only Atomic Queries are supported.");
}
FCAskAnswerHandler ansHandler = new FCAskAnswerHandler();
Literal alpha = new Literal((AtomicSentence) query);
// local variables: new, the new sentences inferred on each iteration
List newSentences = new ArrayList();
// Ensure query is not already a know fact before
// attempting forward chaining.
Set