예제 #1
0
        private Fact RenameDistinct(Fact distinct, Dictionary<TermVariable, TermVariable> renamings)
        {
            if (distinct is GroundFact)
                return distinct;

            Term arg1 = RenameTerm(distinct.GetTerm(0), renamings);
            Term arg2 = RenameTerm(distinct.GetTerm(1), renamings);

            return new VariableFact(false, distinct.RelationName, arg1, arg2);
        }
예제 #2
0
        private static Fact SubstituteDistinct(Fact distinct, Substitution theta)
        {
            if (distinct is GroundFact)
                return distinct;

            Term arg1 = SubstituteTerm(distinct.GetTerm(0), theta);
            Term arg2 = SubstituteTerm(distinct.GetTerm(1), theta);

            return arg1.HasVariables || arg2.HasVariables
                ? new VariableFact(false, distinct.RelationName, arg1, arg2)
                : (Fact) new GroundFact(distinct.RelationName, arg1, arg2);
        }
예제 #3
0
 private static void VisitDistinct(Fact distinct, GdlVisitor visitor)
 {
     visitor.VisitDistinct(distinct);
     VisitTerm(distinct.GetTerm(0), visitor);
     VisitTerm(distinct.GetTerm(1), visitor);
 }
예제 #4
0
파일: Unifier.cs 프로젝트: druzil/nggp-base
        private static bool Mgu(Fact f1, Fact f2, Substitution subsSoFar)
        {
            // Make sure this is even worth our time to check
            if (f1.RelationName != f2.RelationName)
                return false;
            if (f1.Arity != f2.Arity)
                return false;

            // Find the mgu for each column of the facts
            for (int i = 0; i < f1.Arity; i++)
            {
                // If there is no mgu, just die
                if (Mgu(f1.GetTerm(i), f2.GetTerm(i), subsSoFar) == false)
                    return false;
            }

            return true;
        }
예제 #5
0
        /// <summary>
        /// Returns true iff the given sentence is of this sentence form.
        /// </summary>
        public override bool Matches(Fact sentence)
        {
            if (sentence.RelationName != Name || sentence.Arity != _arity)
                return false;

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

                if (term != null)
                {
                    if (!_functions.ContainsKey(i) || !_functions[i].Matches(term))
                        return false;
                }
            }
            return true;
        }
예제 #6
0
        private static Fact SubstituteSentence(Fact sentence, Substitution theta)
        {
            if (sentence is GroundFact)
                return sentence;

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

            var variableFact = new VariableFact(false, sentence.RelationName, body.ToArray());
            return variableFact.VariablesOrEmpty.Any()
                ? variableFact
                : (Fact) new GroundFact(sentence.RelationName, body.ToArray());
        }
예제 #7
0
        private Fact RenameSentence(Fact sentence, Dictionary<TermVariable, TermVariable> renamings)
        {
            if (sentence is GroundFact)
                return sentence;

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

            return new VariableFact(false, sentence.RelationName, body.ToArray());
        }
예제 #8
0
 private void AskDistinct(Fact distinct, LinkedList<Expression> goals, KnowledgeBase context, Substitution theta, 
     ProverCache cache, VariableRenamer renamer, bool askOne, HashSet<Substitution> results, HashSet<Fact> alreadyAsking)
 {
     if (!distinct.GetTerm(0).Equals(distinct.GetTerm(1)))
         Ask(goals, context, theta, cache, renamer, askOne, results, alreadyAsking);
 }