Example #1
0
        /// <summary>
        /// Transforms the term.
        /// </summary>
        /// <param name="term">Term.</param>
        /// <returns>Transformed term.</returns>
        public ITerm Visit(VariableTerm term)
        {
            ConstantID substitutedValue;

            if (Substitution.TryGetValue(term.NameId, out substitutedValue))
            {
                return(new ConstantTerm(substitutedValue, IdManager));
            }
            return(term.Clone());
        }
Example #2
0
        /// <summary>
        /// Extracts the parameters from the given term.
        /// </summary>
        /// <param name="term">Term.</param>
        private void ExtractParameters(ITerm term)
        {
            VariableTerm variableTerm = term as VariableTerm;

            if (variableTerm != null)
            {
                CollectedParameters.Add(variableTerm.NameId);
                return;
            }

            ObjectFunctionTerm objectFunctionTerm = term as ObjectFunctionTerm;

            if (objectFunctionTerm != null)
            {
                ExtractParameters(objectFunctionTerm.FunctionAtom);
            }
        }
        /// <summary>
        /// Checks whether the term needs a rename and performs the rename.
        /// </summary>
        /// <param name="term">Predicate or function term.</param>
        private void CheckAndRenameTerm(ITerm term)
        {
            VariableTerm variableTerm = term as VariableTerm;

            if (variableTerm != null)
            {
                int newParameterId;
                if (ParametersRemapping.TryGetValue(variableTerm.NameId, out newParameterId))
                {
                    variableTerm.NameId = newParameterId;
                }
                return;
            }

            ObjectFunctionTerm objectFunctionTerm = term as ObjectFunctionTerm;

            if (objectFunctionTerm != null)
            {
                CheckAndRenameAtom(objectFunctionTerm.FunctionAtom);
            }
        }
Example #4
0
        /// <summary>
        /// Gets the unification with the specified atom, i.e. calculates the variable substitution required to ground variable terms of the
        /// current atom with the grounded terms (i.e. constants) of the other atom.
        /// </summary>
        /// <param name="referenceAtom">Reference atom.</param>
        /// <returns>Unification in the form of variable substitution.</returns>
        public ISubstitution GetUnificationWith(IAtom referenceAtom)
        {
            Debug.Assert(GetNameId() == referenceAtom.GetNameId() && GetTerms().Count == referenceAtom.GetTerms().Count, "Unification of incompatible atoms!");

            ISubstitution unification = new Substitution();

            int termIndex = 0;

            foreach (var term in GetTerms())
            {
                VariableTerm variableTerm = term as VariableTerm;
                if (variableTerm != null)
                {
                    ConstantTerm valueTerm = referenceAtom.GetTerms()[termIndex] as ConstantTerm;
                    if (valueTerm != null)
                    {
                        unification.Add(variableTerm.NameId, valueTerm.NameId);
                    }
                }
                ++termIndex;
            }

            return(unification);
        }
Example #5
0
 /// <summary>
 /// Visits expression term.
 /// </summary>
 /// <param name="term">Expression term.</param>
 public void Visit(VariableTerm term)
 {
     TermStack.Push(Substitution.GetValue(term.NameID));
 }