Ejemplo n.º 1
0
        public override object VisitQuantifiedSentence(QuantifiedSentence sentence, object arg)
        {
            var substitution = (IDictionary <Variable, ITerm>)arg;

            var quantified          = sentence.Quantified;
            var quantifiedAfterSubs = (ISentence)quantified.Accept(this, arg);

            var variables = new List <Variable>();

            foreach (Variable v in sentence.Variables)
            {
                if (substitution.ContainsKey(v))
                {
                    ITerm st = substitution[v];
                    if (st is Variable)
                    {
                        // Only if it is a variable to I replace it, otherwise
                        // I drop it.
                        variables.Add((Variable)st.Copy());
                    }
                }
                else
                {
                    // No substitution for the quantified variable, so
                    // keep it.
                    variables.Add((Variable)v.Copy());
                }
            }

            // If not variables remaining on the quantifier, then drop it
            if (variables.Count == 0)
            {
                return(quantifiedAfterSubs);
            }

            return(new QuantifiedSentence(sentence.Quantifier, variables, quantifiedAfterSubs));
        }