private IEnumerable <Stream> Query(Parser.Binding binding) { Relation relation = this.relations[binding.key]; Pair[] vars = TokenToPairs(binding.tokens); Stream stream = new Stream(); foreach (Stream walkStream in relation.Query(vars).Walk(stream)) { yield return(walkStream); } }
private void RemoveExclusions(Exclusion exclusion, Parser.Binding binding) { // Remove any claims that would conflict with the input claim (given by binding) // via the given exclusion. Relation relation = this.GetRelation(exclusion.relationKey); Pair[] vars = new Pair[binding.tokens.Length]; for (int i = 0; i < vars.Length; i++) { if (exclusion.boundVars[i]) { vars[i] = Pair.Value(binding.tokens[i].value); } else { vars[i] = Pair.Fresh(); } } if (!exclusion.rule.IsTrue(vars)) { return; } List <string[]> varsToRemove = new List <string[]>(); foreach (Stream stream in relation.Query(vars, false).Walk(new Stream())) { string[] v = new string[vars.Length]; for (int i = 0; i < v.Length; i++) { v[i] = stream.Walk(vars[i]).key; } varsToRemove.Add(v); } foreach (string[] factToRemove in varsToRemove) { relation.RemoveFact(factToRemove); } }
public void AddCondition(Relation condition, Pair[] vars) { this.conditions.Add(condition.Query(this.SaltVars(vars))); this.relations.Add(condition); }