Exemplo n.º 1
0
        // Note: see page 327.
        public StandardizeApartResult GetStandardizeApartResult(ISentence aSentence,
                                                                IStandardizeApartIndexical standardizeApartIndexical)
        {
            var toRename = variableCollector.CollectAllVariables(aSentence);
            IDictionary <Variable, ITerm> renameSubstitution  = new Dictionary <Variable, ITerm>();
            IDictionary <Variable, ITerm> reverseSubstitution = new Dictionary <Variable, ITerm>();

            foreach (var 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[var] = v;
                reverseSubstitution[v]  = var;
            }

            var standardized = substVisitor.Subst(renameSubstitution, aSentence);

            return(new StandardizeApartResult(aSentence, standardized,
                                              renameSubstitution, reverseSubstitution));
        }
Exemplo n.º 2
0
        // 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(IDictionary <Variable, ITerm> theta, Variable var, IFOLNode x)
        {
            if (x is Function)
            {
                var 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(this.CascadeOccurCheck(theta, var, varsToCheck,
                                              new HashedSet <Variable>(varsToCheck)));
            }
            return(false);
        }