// END-InferenceProcedure // // // PRIVATE METHODS // /** * <code> * function FOL-BC-ASK(KB, goals, theta) returns a set of substitutions * input: KB, a knowledge base * goals, a list of conjuncts forming a query (theta already applied) * theta, the current substitution, initially the empty substitution {} * </code> */ private List <List <ProofStepBwChGoal> > folbcask(FOLKnowledgeBase KB, BCAskAnswerHandler ansHandler, List <Literal> goals, Dictionary <Variable, Term> theta) { List <List <ProofStepBwChGoal> > thisLevelProofSteps = new List <List <ProofStepBwChGoal> >(); // local variables: answers, a set of substitutions, initially empty // if goals is empty then return {theta} if (goals.Count == 0) { thisLevelProofSteps.Add(new List <ProofStepBwChGoal>()); return(thisLevelProofSteps); } // qDelta <- SUBST(theta, FIRST(goals)) Literal qDelta = KB.subst(theta, goals[0]); // for each sentence r in KB where // STANDARDIZE-APART(r) = (p1 ^ ... ^ pn => q) foreach (Clause r in KB.getAllDefiniteClauses()) { Clause r2 = KB.standardizeApart(r); // and thetaDelta <- UNIFY(q, qDelta) succeeds Dictionary <Variable, Term> thetaDelta = KB.unify(r2.getPositiveLiterals() [0].getAtomicSentence(), qDelta.getAtomicSentence()); if (null != thetaDelta) { // new_goals <- [p1,...,pn|REST(goals)] List <Literal> newGoals = new List <Literal>(r2 .getNegativeLiterals()); newGoals.AddRange(goals.Skip(1)); // answers <- FOL-BC-ASK(KB, new_goals, COMPOSE(thetaDelta, // theta)) U answers Dictionary <Variable, Term> composed = compose(KB, thetaDelta, theta); List <List <ProofStepBwChGoal> > lowerLevelProofSteps = folbcask( KB, ansHandler, newGoals, composed); ansHandler.addProofStep(lowerLevelProofSteps, r2, qDelta, composed); thisLevelProofSteps.AddRange(lowerLevelProofSteps); } } // return answers return(thisLevelProofSteps); }
// END-InferenceProcedure // // // PRIVATE METHODS // /** * <code> * function FOL-BC-ASK(KB, goals, theta) returns a set of substitutions * input: KB, a knowledge base * goals, a list of conjuncts forming a query (theta already applied) * theta, the current substitution, initially the empty substitution {} * </code> */ private List<List<ProofStepBwChGoal>> folbcask(FOLKnowledgeBase KB, BCAskAnswerHandler ansHandler, List<Literal> goals, Dictionary<Variable, Term> theta) { List<List<ProofStepBwChGoal>> thisLevelProofSteps = new List<List<ProofStepBwChGoal>>(); // local variables: answers, a set of substitutions, initially empty // if goals is empty then return {theta} if (goals.Count==0) { thisLevelProofSteps.Add(new List<ProofStepBwChGoal>()); return thisLevelProofSteps; } // qDelta <- SUBST(theta, FIRST(goals)) Literal qDelta = KB.subst(theta, goals[0]); // for each sentence r in KB where // STANDARDIZE-APART(r) = (p1 ^ ... ^ pn => q) foreach (Clause r in KB.getAllDefiniteClauses()) { Clause r2 = KB.standardizeApart(r); // and thetaDelta <- UNIFY(q, qDelta) succeeds Dictionary<Variable, Term> thetaDelta = KB.unify(r2.getPositiveLiterals() [0].getAtomicSentence(), qDelta.getAtomicSentence()); if (null != thetaDelta) { // new_goals <- [p1,...,pn|REST(goals)] List<Literal> newGoals = new List<Literal>(r2 .getNegativeLiterals()); newGoals.AddRange(goals.Skip(1)); // answers <- FOL-BC-ASK(KB, new_goals, COMPOSE(thetaDelta, // theta)) U answers Dictionary<Variable, Term> composed = compose(KB, thetaDelta, theta); List<List<ProofStepBwChGoal>> lowerLevelProofSteps = folbcask( KB, ansHandler, newGoals, composed); ansHandler.addProofStep(lowerLevelProofSteps, r2, qDelta, composed); thisLevelProofSteps.AddRange(lowerLevelProofSteps); } } // return answers return thisLevelProofSteps; }
/** * <code> * function FOL-BC-ASK(KB, goals, theta) returns a set of substitutions * input: KB, a knowledge base * goals, a list of conjuncts forming a query (theta already applied) * theta, the current substitution, initially the empty substitution {} * </code> */ private ICollection <ICollection <ProofStepBwChGoal> > folbcask(FOLKnowledgeBase KB, BCAskAnswerHandler ansHandler, ICollection <Literal> goals, IMap <Variable, Term> theta) { ICollection <ICollection <ProofStepBwChGoal> > thisLevelProofSteps = CollectionFactory.CreateQueue <ICollection <ProofStepBwChGoal> >(); // local variables: answers, a set of substitutions, initially empty // if goals is empty then return {theta} if (goals.IsEmpty()) { thisLevelProofSteps.Add(CollectionFactory.CreateQueue <ProofStepBwChGoal>()); return(thisLevelProofSteps); } // qDelta <- SUBST(theta, FIRST(goals)) Literal qDelta = KB.subst(theta, goals.Get(0)); // for each sentence r in KB where // STANDARDIZE-APART(r) = (p1 ^ ... ^ pn => q) foreach (Clause rIter in KB.getAllDefiniteClauses()) { Clause r = rIter; r = KB.standardizeApart(r); // and thetaDelta <- UNIFY(q, qDelta) succeeds IMap <Variable, Term> thetaDelta = KB.unify(r.getPositiveLiterals() .Get(0).getAtomicSentence(), qDelta.getAtomicSentence()); if (null != thetaDelta) { // new_goals <- [p1,...,pn|REST(goals)] ICollection <Literal> newGoals = CollectionFactory.CreateQueue <Literal>(r.getNegativeLiterals()); newGoals.AddAll(goals.subList(1, goals.Size())); // answers <- FOL-BC-ASK(KB, new_goals, COMPOSE(thetaDelta, // theta)) U answers IMap <Variable, Term> composed = compose(KB, thetaDelta, theta); ICollection <ICollection <ProofStepBwChGoal> > lowerLevelProofSteps = folbcask( KB, ansHandler, newGoals, composed); ansHandler.addProofStep(lowerLevelProofSteps, r, qDelta, composed); thisLevelProofSteps.AddAll(lowerLevelProofSteps); } } // return answers return(thisLevelProofSteps); }
/** * Returns a set of substitutions * * @param KB * a knowledge base * @param query * goals, a list of conjuncts forming a query * * @return a set of substitutions */ public InferenceResult ask(FOLKnowledgeBase KB, Sentence query) { // Assertions on the type queries this Inference procedure // supports if (!(query is AtomicSentence)) { throw new IllegalArgumentException("Only Atomic Queries are supported."); } ICollection <Literal> goals = CollectionFactory.CreateQueue <Literal>(); goals.Add(new Literal((AtomicSentence)query)); BCAskAnswerHandler ansHandler = new BCAskAnswerHandler(); ICollection <ICollection <ProofStepBwChGoal> > allProofSteps = folbcask(KB, ansHandler, goals, CollectionFactory.CreateInsertionOrderedMap <Variable, Term>()); ansHandler.setAllProofSteps(allProofSteps); return(ansHandler); }
// // START-InferenceProcedure public InferenceResult ask(FOLKnowledgeBase KB, Sentence query) { // Assertions on the type queries this Inference procedure // supports if (!(query is AtomicSentence)) { throw new ArgumentException( "Only Atomic Queries are supported."); } List<Literal> goals = new List<Literal>(); goals.Add(new Literal((AtomicSentence)query)); BCAskAnswerHandler ansHandler = new BCAskAnswerHandler(); List<List<ProofStepBwChGoal>> allProofSteps = folbcask(KB, ansHandler, goals, new Dictionary<Variable, Term>()); ansHandler.setAllProofSteps(allProofSteps); return ansHandler; }
public IInferenceResult Ask(FOLKnowledgeBase kb, ISentence query) { // Assertions on the type queries this Inference procedure // supports if (!(query is IAtomicSentence)) { throw new ArgumentOutOfRangeException("query", "Only Atomic Queries are supported."); } IList <Literal> goals = new List <Literal>(); goals.Add(new Literal((IAtomicSentence)query)); var ansHandler = new BCAskAnswerHandler(); IList <IList <ProofStepBwChGoal> > allProofSteps = this.Folbcask(kb, ansHandler, goals, new Dictionary <Variable, ITerm>()); ansHandler.SetAllProofSteps(allProofSteps); return(ansHandler); }
// START-InferenceProcedure /** * Returns a set of substitutions * * @param KB * a knowledge base * @param query * goals, a list of conjuncts forming a query * * @return a set of substitutions */ public InferenceResult ask(FOLKnowledgeBase KB, Sentence query) { // Assertions on the type queries this Inference procedure // supports if (!(query is AtomicSentence)) { throw new ArgumentException( "Only Atomic Queries are supported."); } List <Literal> goals = new List <Literal>(); goals.Add(new Literal((AtomicSentence)query)); BCAskAnswerHandler ansHandler = new BCAskAnswerHandler(); List <List <ProofStepBwChGoal> > allProofSteps = folbcask(KB, ansHandler, goals, new Dictionary <Variable, Term>()); ansHandler.setAllProofSteps(allProofSteps); return(ansHandler); }