示例#1
0
        public Predicate ReplaceFunctor(Atom functorToBeReplaced, Atom functorToReplaceWith)
        {
            Atom newFunctor;

            if (Functor == functorToBeReplaced)
            {
                newFunctor = new Atom(functorToReplaceWith.TheString);
            }
            else
            {
                newFunctor = Functor.DeepCopy() as Atom;
            }

            var newArguments = new Term[Arguments.Count()];

            for (int i = 0; i < Arguments.Count(); i++)
            {
                var pred = Arguments[i] as Predicate;
                if (pred != null)
                {
                    newArguments[i] = pred.ReplaceFunctor(functorToBeReplaced,
                                                          functorToReplaceWith);
                }
                else
                {
                    newArguments[i] = Arguments[i].DeepCopy();
                }
            }

            return(new Predicate(newFunctor, newArguments));
        }
示例#2
0
        public override Term DeepCopy()
        {
            var newArguments = new Term[Arguments.Count()];

            for (int x = 0; x < Arguments.Count(); x++)
            {
                newArguments[x] = Arguments[x].DeepCopy();
            }

            return(new Predicate(Functor.DeepCopy() as Atom, newArguments));
        }
示例#3
0
        public Predicate RemoveFunctor(Atom functorToBeRemoved)
        {
            Atom newFunctor;

            Term[] newArguments;

            if (Functor == functorToBeRemoved)
            {
                var firstArgPred = Arguments[0] as Predicate;
                if (firstArgPred != null)
                {
                    newFunctor   = new Atom(firstArgPred.Functor.TheString);
                    newArguments = new Term[firstArgPred.Arguments.Count()];
                    for (int i = 0; i < firstArgPred.Arguments.Count(); i++)
                    {
                        var argPred = firstArgPred.Arguments[i] as Predicate;
                        if (argPred != null)
                        {
                            newArguments[i] = argPred.RemoveFunctor(functorToBeRemoved);
                        }
                        else
                        {
                            newArguments[i] = firstArgPred.Arguments[i].DeepCopy();
                        }
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            else
            {
                newFunctor   = Functor.DeepCopy() as Atom;
                newArguments = new Term[Arguments.Count()];
                for (int i = 0; i < Arguments.Count(); i++)
                {
                    var pred = Arguments[i] as Predicate;
                    if (pred != null)
                    {
                        newArguments[i] = pred.RemoveFunctor(functorToBeRemoved);
                    }
                    else
                    {
                        newArguments[i] = Arguments[i].DeepCopy();
                    }
                }
            }

            return(new Predicate(newFunctor, newArguments));
        }