示例#1
0
        // Note: see page 327.
        public StandardizeApartResult standardizeApart(Sentence sentence,
                                                       StandardizeApartIndexical standardizeApartIndexical)
        {
            List <Variable>             toRename            = variableCollector.collectAllVariables(sentence);
            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,
                                                       sentence);

            return(new StandardizeApartResult(sentence, standardized,
                                              renameSubstitution, reverseSubstitution));
        }
示例#2
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);
        }