public void emptyRuleMakesNoChangesToSourceOrDestinationTripleStores() { TripleStore store = new MemoryTripleStore(); SimpleRuleProcessor ruleProcessor = new SimpleRuleProcessor(); Rule rule = new Rule(); ruleProcessor.Process(rule, store); Assert.IsTrue(store.IsEmpty()); }
public void nonMatchingAntecedentsAddsNoConsequents() { TripleStore store = new MemoryTripleStore(); SimpleRuleProcessor ruleProcessor = new SimpleRuleProcessor(); Rule rule = new Rule(); rule.AddAntecedent(new Pattern(new UriRef("http://example.com/subj"), new UriRef("http://example.com/pred"), new UriRef("http://example.com/obj"))); rule.AddConsequent(new Pattern(new UriRef("http://example.com/subj"), new UriRef("http://example.com/pred"), new UriRef("http://example.com/other"))); ruleProcessor.Process(rule, store); Assert.IsTrue(store.IsEmpty(), "Store is still empty"); }
public void noAntecedentsAutomaticallyAddsConsequents() { TripleStore store = new MemoryTripleStore(); SimpleRuleProcessor ruleProcessor = new SimpleRuleProcessor(); Rule rule = new Rule(); rule.AddConsequent(new Pattern(new UriRef("http://example.com/subj"), new UriRef("http://example.com/pred"), new UriRef("http://example.com/obj"))); ruleProcessor.Process(rule, store); Assert.IsFalse(store.IsEmpty(), "Store is non-empty"); Assert.IsTrue(store.Contains(new Statement(new UriRef("http://example.com/subj"), new UriRef("http://example.com/pred"), new UriRef("http://example.com/obj"))), "Destination contains consequent"); }
public void consequentsAreAddedUsingAntecedentSolutionBindings() { TripleStore store = new MemoryTripleStore(); SimpleRuleProcessor ruleProcessor = new SimpleRuleProcessor(); store.Add(new Statement(new UriRef("http://example.com/subj"), new UriRef("http://example.com/pred"), new UriRef("http://example.com/obj"))); Rule rule = new Rule(); rule.AddAntecedent(new Pattern(new Variable("var1"), new UriRef("http://example.com/pred"), new Variable("var2"))); rule.AddConsequent(new Pattern(new Variable("var1"), new UriRef("http://example.com/newPred"), new Variable("var2"))); ruleProcessor.Process(rule, store); Assert.IsFalse(store.IsEmpty(), "Destination is non-empty"); Assert.IsTrue(store.Contains(new Statement(new UriRef("http://example.com/subj"), new UriRef("http://example.com/newPred"), new UriRef("http://example.com/obj"))), "Destination contains consequent"); }
public void allAntecedentMatchesAreProcessed() { TripleStore store = new MemoryTripleStore(); SimpleRuleProcessor ruleProcessor = new SimpleRuleProcessor(); store.Add(new Statement(new UriRef("http://example.com/subj1"), new UriRef("http://example.com/pred"), new UriRef("http://example.com/obj1"))); store.Add(new Statement(new UriRef("http://example.com/subj2"), new UriRef("http://example.com/pred"), new UriRef("http://example.com/obj2"))); Rule rule = new Rule(); rule.AddAntecedent(new Pattern(new Variable("var1"), new UriRef("http://example.com/pred"), new Variable("var2"))); rule.AddConsequent(new Pattern(new Variable("var1"), new UriRef("http://example.com/newPred"), new Variable("var2"))); ruleProcessor.Process(rule, store); Assert.IsFalse(store.IsEmpty(), "Destination is non-empty"); Assert.IsTrue(store.Contains(new Statement(new UriRef("http://example.com/subj1"), new UriRef("http://example.com/newPred"), new UriRef("http://example.com/obj1"))), "Destination contains first match onsequent"); Assert.IsTrue(store.Contains(new Statement(new UriRef("http://example.com/subj2"), new UriRef("http://example.com/newPred"), new UriRef("http://example.com/obj2"))), "Destination contains second match consequent"); }
// TODO: replace implementation with database specific rule processor public void Evaluate(SemPlan.Spiral.Core.Rule rule) { SimpleRuleProcessor ruleProcessor = new SimpleRuleProcessor(); ruleProcessor.Process(rule, this); }