private static Implication RemoveNotDistinctLiteral(Implication rule, Negation notDistinctLiteral) { //Figure out the substitution we want... //If we have two constantsin Either Remove one or //maybe get rid of the ___? //One is a variablein Replace the variable with the other thing //throughout the rule var distinct = (Fact)notDistinctLiteral.Negated; Term arg1 = distinct.GetTerm(0); Term arg2 = distinct.GetTerm(1); if (arg1 == arg2) { //Just Remove that literal var newBody = new List<Expression>(); newBody.AddRange(rule.Antecedents.Conjuncts); newBody.Remove(notDistinctLiteral); return new Implication(rule.Consequent, newBody.ToArray()); } var p1 = arg1 as TermVariable; if (p1 != null) { //What we return will still have the not-distinct literal, //but it will get replaced in the next pass. //(Even if we have two variables, they will be equal next time through.) var sub = new Substitution(); sub.AddMapping(p1, arg2); return (Implication)rule.ApplySubstitution(sub); } var variable = arg2 as TermVariable; if (variable != null) { var sub = new Substitution(); sub.AddMapping(variable, arg1); return (Implication)rule.ApplySubstitution(sub); } if (arg1 is TermObject || arg2 is TermObject) { //We have two non-equal constants, or a constant and a function. //The rule should have no effect. return null; } //We have two functions. Complicated! (Have to replace them with unified version.) //We pass on this case for now. //TODO: Implement correctly. throw new Exception("We can't currently handle (not (distinct <function> <function>))."); }
private static void VisitNot(Negation not, GdlVisitor visitor) { visitor.VisitNot(not); VisitAll(not.Negated, visitor); }
private static Substitution Mgu(Negation neg1, Negation neg2) { return Mgu(neg1.Negated, neg2.Negated); }
private static Negation SubstituteNot(Negation not, Substitution theta) { return not.VariablesOrEmpty.Any() ? new Negation(SubstituteLiteral(not.Negated, theta)) : not; }
private Negation RenameNot(Negation not, Dictionary<TermVariable, TermVariable> renamings) { return not.VariablesOrEmpty.Any() ? new Negation(RenameLiteral(not.Negated, renamings)) : not; }
private void AskNot(Negation not, LinkedList<Expression> goals, KnowledgeBase context, Substitution theta, ProverCache cache, VariableRenamer renamer, bool askOne, HashSet<Substitution> results, HashSet<Fact> alreadyAsking) { var notGoals = new LinkedList<Expression>(); notGoals.AddLast(not.Negated); var notResults = new HashSet<Substitution>(); Ask(notGoals, context, theta, cache, renamer, true, notResults, alreadyAsking); if (notResults.Count == 0) Ask(goals, context, theta, cache, renamer, askOne, results, alreadyAsking); }