internal override MatchResult Match(Term goal, World w) { var con = MatchResult.Compatible; var l = _left.Match(goal, w); var r = _right.Match(goal, w); Console.WriteLine($"{l} v {r}"); switch (l) { case MatchResult.Satisfied: return(l); case MatchResult.Contradicted: con = l; break; } switch (r) { case MatchResult.Satisfied: return(r); case MatchResult.Contradicted: if (con == r) { return(r); } break; } return(MatchResult.Compatible); }
internal override MatchResult Match(Term goal, World w) { var match = goal.Match(_left, w); MatchResult res; switch (match) { case MatchResult.Satisfied: res = MatchResult.Contradicted; break; case MatchResult.Contradicted: res = MatchResult.Satisfied; break; case MatchResult.Incompatible: res = MatchResult.Compatible; break; case MatchResult.Compatible: res = MatchResult.Compatible; break; default: res = 0; break; } return(res); }
internal override MatchResult Match(Term goal, World w) { var sat = MatchResult.Incompatible; var l = _left.Match(goal, w); var r = _right.Match(goal, w); switch (l) { case MatchResult.Contradicted: return(l); case MatchResult.Satisfied: sat = l; break; } switch (r) { case MatchResult.Contradicted: return(r); case MatchResult.Satisfied: if (sat == r) { return(r); } break; } return(MatchResult.Incompatible); }
internal override MatchResult Match(Term goal, World w) { var l = _left.Match(goal, w); var r = _right.Match(goal, w); //Console.WriteLine(l + " => " + r); if (l == MatchResult.Contradicted) { return(MatchResult.Satisfied); } else if (r == MatchResult.Satisfied) { return(MatchResult.Satisfied); } else if (l == MatchResult.Satisfied && r == MatchResult.Contradicted) { return(MatchResult.Contradicted); } else if (l == MatchResult.Satisfied && r == MatchResult.Incompatible) { return(MatchResult.Incompatible); } return(MatchResult.Compatible); }
internal override MatchResult Match(Term goal, World w) { // let the rule handle the matching if the goal is one if (!(goal is Fact)) { return(goal.Match(this, w)); } var target = (Fact)goal; // facts that have nothing to do with eachother are // always logically compatible if (!(target.IsComparable(this))) { return(MatchResult.Compatible); } // atoms if (target._arity == 0) { // atoms with the same id are a match, the goal is // satisfied. atoms without the same id are not a // match, but are logicallty compatible with eachother return((target._id == this._id) ? MatchResult.Satisfied : MatchResult.Compatible); } // predicates for (var i = 0; i < _arity; i++) { var targetVar = target._args[i] is Variable; var factVar = _args[i] is Variable; if (targetVar && factVar) { // if both predicates have a variable in the same // place then they're compatible. _satisfied[i] = MatchResult.Compatible; } else if (targetVar && !factVar) { // if the fact's argument is not a variable, then // its value is a satisfying variable for the goal. ((Variable)target._args[i]).values.Add(_args[i]); _satisfied[i] = MatchResult.Satisfied; } else if (!targetVar && factVar) { // if the target's argument is not a variable, then // its value is added to my argument ((Variable)_args[i]).values.Add(target._args[i]); _satisfied[i] = MatchResult.Satisfied; } else { // neither argument is a variable, either satisfied // if they're equal or incompatible if not _satisfied[i] = target._args[i].Equals(_args[i]) ? MatchResult.Satisfied : MatchResult.Compatible; } } // if all the args are satisfied then the goal is satisfied // otherwise the goal is compatable return(this.VariablesSatisfied()? MatchResult.Satisfied: MatchResult.Compatible); }