AIMA.Core.Logic.FOL.KB.FOLKnowledgeBase.recursiveFetch C# (CSharp) Method

recursiveFetch() private method

private recursiveFetch ( Term>.Dictionary theta, Literal l, List remainingLiterals, Term>.List possibleSubstitutions ) : void
theta Term>.Dictionary
l AIMA.Core.Logic.FOL.KB.Data.Literal
remainingLiterals List
possibleSubstitutions Term>.List
return void
        private void recursiveFetch(Dictionary<Variable, Term> theta, Literal l,
                List<Literal> remainingLiterals,
                List<Dictionary<Variable, Term>> possibleSubstitutions)
        {

            // Find all substitutions for current predicate based on the
            // substitutions of prior predicates in the list (i.e. SUBST with
            // theta).
            List<Dictionary<Variable, Term>> pSubsts = fetch(subst(theta, l));

            // No substitutions, therefore cannot continue
            if (null == pSubsts)
            {
                return;
            }

            foreach (Dictionary<Variable, Term> psubst in pSubsts)
            {
                // Ensure all prior substitution information is maintained
                // along the chain of predicates (i.e. for shared variables
                // across the predicates).
                foreach(Variable key in theta.Keys)
                {
                    psubst.Add(key,theta[key]);
                }
                if (remainingLiterals.Count == 0)
                {
                    // This means I am at the end of the chain of predicates
                    // and have found a valid substitution.
                    possibleSubstitutions.Add(psubst);
                }
                else
                {
                    // Need to move to the next link in the chain of substitutions
                    Literal first = remainingLiterals[0];
                    List<Literal> rest = remainingLiterals.Skip(1).ToList<Literal>();

                    recursiveFetch(psubst, first, rest, possibleSubstitutions);
                }
            }
        }