Пример #1
0
        private static TermFunction SubstituteFunction(TermFunction function, Substitution theta)
        {
            if (!function.HasVariables)
                return function;

            var body = new List<Term>();
            for (int i = 0; i < function.Arity; i++)
                body.Add(SubstituteTerm(function.GetTerm(i), theta));

            return new TermFunction(function.FunctionName, body.ToArray());
        }
Пример #2
0
        private TermFunction RenameFunction(TermFunction function, Dictionary<TermVariable, TermVariable> renamings)
        {
            if (!function.HasVariables)
                return function;

            var body = new List<Term>();
            for (int i = 0; i < function.Arity; i++)
                body.Add(RenameTerm(function.GetTerm(i), renamings));

            return new TermFunction(function.FunctionName, body.ToArray());
        }
Пример #3
0
 private static void VisitFunction(TermFunction function, GdlVisitor visitor)
 {
     visitor.VisitFunction(function);
     VisitTerms(function.Arguments, visitor);
 }
Пример #4
0
        protected override int CompareTo(TermFunction t)
        {
            int comp = FunctionName - t.FunctionName;

            if (comp != 0)
                return Math.Sign(comp);

            // At this point, function names are equal

            comp = Arguments.Length - t.Arguments.Length;

            if (comp != 0)
                return Math.Sign(comp);

            // At this point, both term-functions have same number of arguments

            for (int i = 0; i < Arguments.Length; i++)
            {
                comp = Arguments[i].CompareTo(t.Arguments[i]);

                if (comp != 0)
                    return comp;
            }

            return 0;
        }
Пример #5
0
 protected override int CompareTo(TermFunction t)
 {
     // Obj < Func < Var
     return -1;
 }
Пример #6
0
 private SimpleSentenceForm(TermFunction function)
     : this(function.FunctionName, function.Arity, function.Arguments)
 {
 }
Пример #7
0
        private bool Matches(TermFunction function)
        {
            if (function.FunctionName != Name || function.Arity != _arity)
                return false;

            for (int i = 0; i < function.Arity; i++)
            {
                var term = function.GetTerm(i) as TermFunction;
                if (_functions.ContainsKey(i) && term == null)
                    return false;

                if (term != null)
                    if (!_functions.ContainsKey(i) || !_functions[i].Matches(term))
                        return false;
            }
            return true;
        }
Пример #8
0
 /**
  * Gets the mapping for a function.
  * Iterates over all the Term of the functions and recursively tries to map them.
  *
  * @param func The function whose mappings to compute.
  * @return The function after all substitutions have been made.
  */
 public virtual TermFunction GetMapping(TermFunction func)
 {
     var result = new TermFunction(true, func.FunctionName, func.Arguments);
     for (int i = 0; i < result.Arity; i++)
     {
         if (result.Arguments[i] is TermVariable)
         {
             Term replacement = GetMapping((TermVariable)result.Arguments[i]);
             if (replacement != null)
                 result.Arguments[i] = replacement;
         }
         else if (result.Arguments[i] is TermFunction)
         {
             Term replacement = GetMapping((TermFunction)result.Arguments[i]);
             if (replacement != null)
                 result.Arguments[i] = replacement;
         }
     }
     return result;
 }