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; }
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 }
protected bool Equals(TermObjectSubstitution other) { return other.NumMappings() == NumMappings() && Substitutions.All(kv => kv.Value.Equals(other.GetMapping(kv.Key))); }
public void Add(TermObjectSubstitution add) { foreach (var kv in add.Substitutions) AddMapping(kv.Key, kv.Value); }
public void ChangeOneInNext(ICollection<TermVariable> varsToChange, TermObjectSubstitution assignment) { if (_nextAssignment == null) return; //First, we stop and see if any of these have already been //changed (in nextAssignment) foreach (TermVariable varToChange in varsToChange) { //int index = _plan.VarsToAssign.IndexOf(varToChange); int index = _plan.IndexOfVariableToAssign(varToChange); if (index != -1) { var assignedValue = (TermObject)assignment.GetMapping(varToChange); if (assignedValue == null) throw new Exception("assignedValue is null; varToChange is " + varToChange + " and assignment is " + assignment); if (_nextAssignment == null) throw new Exception("nextAssignment is null"); if (!assignedValue.Equals(_nextAssignment[index])) //We've already changed one of these return; } } //Okay, we actually need to change one of these ChangeOneInNext(varsToChange); }