collectAllVariables() public method

public collectAllVariables ( Chain aChain ) : List
aChain AIMA.Core.Logic.FOL.KB.Data.Chain
return List
Ejemplo n.º 1
0
        //
        // PROTECTED METHODS
        //

        // Note: You can subclass and override this method in order
        // to re-implement the OCCUR-CHECK?() to always
        // return false if you want that to be the default
        // behavior, as is the case with Prolog.
        protected bool occurCheck(Dictionary <Variable, Term> theta, Variable var,
                                  FOLNode x)
        {
            if (x is Function)
            {
                List <Variable> varsToCheck = _variableCollector
                                              .collectAllVariables((Function)x);
                if (varsToCheck.Contains(var))
                {
                    return(true);
                }

                // Now need to check if cascading will cause occurs to happen
                // e.g.
                // Loves(SF1(v2),v2)
                // Loves(v3,SF0(v3))
                // or
                // P(v1,SF0(v1),SF0(v1))
                // P(v2,SF0(v2),v2 )
                // or
                // P(v1, F(v2),F(v2),F(v2),v1, F(F(v1)),F(F(F(v1))),v2)
                // P(F(v3),v4, v5, v6, F(F(v5)),v4, F(v3), F(F(v5)))
                return(cascadeOccurCheck(theta, var, varsToCheck,
                                         new List <Variable>(varsToCheck)));
            }
            return(false);
        }
Ejemplo n.º 2
0
        // Note: see page 327.
        public StandardizeApartResult standardizeApart(Sentence aSentence,
                                                       StandardizeApartIndexical standardizeApartIndexical)
        {
            List <Variable> toRename = variableCollector
                                       .collectAllVariables(aSentence);
            Dictionary <Variable, Term> renameSubstitution  = new Dictionary <Variable, Term>();
            Dictionary <Variable, Term> reverseSubstitution = new Dictionary <Variable, Term>();

            foreach (Variable var in toRename)
            {
                Variable v = null;
                do
                {
                    v = new Variable(standardizeApartIndexical.getPrefix()
                                     + standardizeApartIndexical.getNextIndex());
                    // Ensure the new variable name is not already
                    // accidentally used in the sentence
                } while (toRename.Contains(v));

                renameSubstitution.Add(var, v);
                reverseSubstitution.Add(v, var);
            }

            Sentence standardized = substVisitor.subst(renameSubstitution,
                                                       aSentence);

            return(new StandardizeApartResult(aSentence, standardized,
                                              renameSubstitution, reverseSubstitution));
        }