예제 #1
0
        public TermObjectSubstitution Copy(TermObjectSubstitution add)
        {
            var result = new TermObjectSubstitution();

            foreach (var kv in Substitutions)
                result.Substitutions[kv.Key] = kv.Value.Clone();
            result._hashcode = _hashcode;

            result.Add(add);

            return result;
        }
예제 #2
0
        public static AssignmentsImpl GetAssignmentsWithRecursiveInput(Implication rule,
                                                                       ISentenceDomainModel model, ISentenceForm form, Fact input,
                                                                       Dictionary<ISentenceForm, FunctionInfo> functionInfoMap,
                                                                       Dictionary<ISentenceForm, ICollection<Fact>> completedSentenceFormValues)
        {
            //Look for the literal(s) in the rule with the sentence form of the
            //recursive input. This can be tricky if there are multiple matching
            //literals.
            var matchingLiterals = rule.Antecedents.Conjuncts.OfType<Fact>().Where(form.Matches).ToList();

            var assignmentsList = new List<AssignmentsImpl>();
            foreach (Fact matchingLiteral in matchingLiterals)
            {
                var preassignment = new TermObjectSubstitution();
                preassignment.Add(matchingLiteral.Unify(input));
                if (preassignment.NumMappings() > 0)
                {
                    var assignments = new AssignmentsImpl(
                        preassignment,
                        rule,
                        //TODO: This one getVarDomains call is why a lot of
                        //SentenceModel/DomainModel stuff is required. Can
                        //this be better factored somehow?
                        SentenceDomainModels.GetVarDomains(rule, model, SentenceDomainModels.VarDomainOpts.IncludeHead),
                        functionInfoMap,
                        completedSentenceFormValues);
                    assignmentsList.Add(assignments);
                }
            }

            if (assignmentsList.Count == 0)
                return new AssignmentsImpl();
            if (assignmentsList.Count == 1)
                return assignmentsList[0];
            throw new Exception("Not yet implemented: assignments for recursive functions with multiple recursive conjuncts");
            //TODO: Plan to implement by subclassing TermObjectSubstitution into something
            //that contains and iterates over multiple TermObjectSubstitution
        }