public void TestAllActionsWithContext() { ie.exposeEventContext = true; ie.NewFactHandler += new NewFactEvent(AssertFactHandlerWithContext); ie.DeleteFactHandler += new NewFactEvent(RetractFactHandlerWithContext); ie.ModifyFactHandler += new NewFactEvent(ModifyFactHandlerWithContext); ie.Process(); Assert.AreEqual(2, newFactEventCount); Assert.AreEqual(1, deleteFactEventCount); Assert.AreEqual(1, modifyFactEventCount); }
public void RuleML08LoadFacts() { IInferenceEngine ie = new IEImpl(); ie.LoadRuleBase(new RuleML08DatalogAdapter(ruleFilesFolder + "discount.ruleml", FileAccess.Read)); ie.Process(); Assert.AreEqual(6, ie.FactsCount, "Initial process"); ie.LoadFacts(new RuleML08DatalogAdapter(ruleFilesFolder + "facts.ruleml", FileAccess.Read)); Assert.AreEqual(8, ie.FactsCount, "Loaded facts"); ie.Process(); Assert.AreEqual(10, ie.FactsCount, "Subsequent process"); }
public void BeforeAfterFlowEngineBinder() { IInferenceEngine ie = new IEImpl(new FlowEngineBinder(ruleFilesFolder + "testbinder1.ruleml.xbre", BindingTypes.BeforeAfter)); ie.LoadRuleBase(new RuleML09NafDatalogAdapter(ruleFilesFolder + "testbinder.ruleml", FileAccess.Read)); ie.NewFactHandler += new NewFactEvent(ShowAllNewFacts); Hashtable bo = new Hashtable(); bo.Add("THEDUKE", new Character("The Duke", "hello world")); bo.Add("BOBBYBOB", new Character("Bobby Bob", "what the?")); bo.Add("JOHNQDOE", new Character("John Q. Doe", "hello, who am i?")); bo.Add("DANNYDAN", new Character("Danny Dan", "get out of my world")); ie.Process(bo); IList <IList <Fact> > qrs = ie.RunQuery("all polite"); Assert.AreEqual(2, qrs.Count, "polite Count"); // here, we should have got one result (Danny Dan), but the politness of The Duke has // mutexed the "mundane" implication. qrs = ie.RunQuery("all mundane"); Assert.AreEqual(0, qrs.Count, "mundane Count"); }
public void ErrorProcessBO() { IInferenceEngine ie = new IEImpl(); ie.LoadRuleBase(new RuleML09NafDatalogAdapter(ruleFilesFolder + "test-0_9.ruleml", FileAccess.Read)); ie.Process(new Hashtable()); }
public void ControlFlowEngineBinder() { IInferenceEngine ie = new IEImpl(new FlowEngineBinder(ruleFilesFolder + "testbinder2.ruleml.xbre", BindingTypes.Control)); ie.LoadRuleBase(new RuleML09NafDatalogAdapter(ruleFilesFolder + "testbinder.ruleml", FileAccess.Read)); ie.NewFactHandler += new NewFactEvent(ShowAllNewFacts); Character theDuke = new Character("The Duke", "hello world"); Character bobbyBob = new Character("Bobby Bob", "what the?"); Character johnQDoe = new Character("John Q. Doe", "hello, who am i?"); Character dannyDan = new Character("Danny Dan", "get out of my world"); Hashtable bo = new Hashtable(); ArrayList al = new ArrayList(); al.Add(theDuke); al.Add(bobbyBob); al.Add(johnQDoe); al.Add(dannyDan); bo.Add("CHARACTERS", al); ie.Process(bo); // the binder uses isolated memory for each character, // so we will not run the queries but check the objects directly Assert.AreEqual("polite", theDuke.Education, "theDuke"); Assert.AreEqual(String.Empty, bobbyBob.Education, "bobbyBob"); Assert.AreEqual("polite", johnQDoe.Education, "johnQDoe"); Assert.AreEqual("mundane", dannyDan.Education, "dannyDan"); }
public void AfterBinderRetraction() { Character theDuke = new Character("The Duke", "hello world"); Hashtable bo = new Hashtable(); bo.Add("THEDUKE", theDuke); // first test to confirm that a pre-existing fact is not rededucted IInferenceEngine ie = new IEImpl(new FlowEngineBinder(ruleFilesFolder + "testbinder3.ruleml.xbre", BindingTypes.BeforeAfter)); ie.LoadRuleBase(new RuleML09NafDatalogAdapter(ruleFilesFolder + "testbinder.ruleml", FileAccess.Read)); ie.Assert(new Fact("retract_target", "education", new Individual(theDuke), new Individual("polite"))); ie.NewFactHandler += new NewFactEvent(ShowAllNewFacts); deducted = 0; ie.Process(bo); Assert.AreEqual(0, deducted, "The Duke was already polite!"); // second test to confirm that retracting the fact in the after binder restarts inference ie = new IEImpl(new FlowEngineBinder(ruleFilesFolder + "testbinder4.ruleml.xbre", BindingTypes.BeforeAfter)); ie.LoadRuleBase(new RuleML09NafDatalogAdapter(ruleFilesFolder + "testbinder.ruleml", FileAccess.Read)); ie.Assert(new Fact("retract_target", "education", new Individual(theDuke), new Individual("polite"))); ie.NewFactHandler += new NewFactEvent(ShowAllNewFacts); deducted = 0; ie.Process(bo); Assert.AreEqual(1, deducted, "The Duke was re-deducted polite!"); }
public void EndlessLoopException() { ie = new IEImpl(); ie.LoadRuleBase(new RuleML086DatalogAdapter(ruleFilesFolder + "endlessloop.ruleml", FileAccess.Read)); // Processing should reach iteration limit and throw a BREexception ie.Process(); Assert.Fail("Should never reach me!"); }
public void RunEngine() { IInferenceEngine ie = new IEImpl(); ie.LoadRuleBase(m_CompositeAdapter); Trace.WriteLine("Facts Before RunEngine:" + ie.FactsCount); ie.Process(); Trace.WriteLine("Facts After RunEngine:" + ie.FactsCount); }
public void PerfomativeLoadProcessing() { string inFile = ruleFilesFolder + "discount-0_9.ruleml"; IInferenceEngine ie = new IEImpl(); ie.LoadRuleBase(new RuleML09NafDatalogAdapter(inFile, FileAccess.Read), false); Assert.AreEqual(0, ie.FactsCount, "No fact should have been loaded"); ie.Process(RuleTypes.ConnectivesOnly); Assert.AreEqual(0, ie.FactsCount, "No fact should have been deducted"); ie.Process(RuleTypes.PerformativesOnly); Assert.AreEqual(3, ie.FactsCount, "Only fact assertion should have happened"); ie.LoadRuleBase(new RuleML09NafDatalogAdapter(inFile, FileAccess.Read), false); Assert.AreEqual(0, ie.FactsCount, "Memory should be empty at this point"); ie.Process(RuleTypes.All); Assert.AreEqual(6, ie.FactsCount, "Fact assertion and deduction should have happened"); }
private static void ProcessRuleBase(DslAdapter adapter) { IEImpl ie = new IEImpl(); ie.LoadRuleBase(adapter); ie.Process(); for (IEnumerator <Fact> e = ie.Facts; e.MoveNext();) { Console.WriteLine(e.Current); } }
private void RunTestBoundFormulas(IBinder binder, IRuleBaseAdapter rba) { // regression test for RFE 1504353 IInferenceEngine ie = new IEImpl(binder); ie.LoadRuleBase(rba); Assert.IsTrue(ie.Assert(new Fact("operandA", new Individual(23)))); Assert.IsTrue(ie.Assert(new Fact("operandB", new Individual(7)))); ie.Process(); Assert.AreEqual(4, ie.FactsCount); Assert.IsTrue(ie.FactExists(new Fact("resultA-B", new Individual(16))), "resultA-B is wrong"); Assert.IsTrue(ie.FactExists(new Fact("resultB-A", new Individual(-16))), "resultB-A is wrong"); }
public void PerformProcess(IBinder binder) { // generate dummy business objects Hashtable businessObjects = DummyData.GetInstance().GetBusinessObjects(nbDecaCustomers); // instantiate an inference engine, bind my data and process the rules IInferenceEngine ie = new IEImpl(binder); ie.LogHandlers += new DispatchLog(HandleLogEvent); ie.LoadRuleBase(new RuleML08DatalogAdapter(ruleBaseFile, System.IO.FileAccess.Read)); ie.Process(businessObjects); // processing is done, let's analyze the results QueryResultSet qrs = ie.RunQuery("Fraudulent Customers"); Console.WriteLine("\nDetected {0} fraudulent customers.", qrs.Count); if (qrs.Count != 2 * nbDecaCustomers) { Console.WriteLine("\nError! " + 2 * nbDecaCustomers + " was expected."); } // check if the customer objects have been flagged correctly int flaggedCount = 0; foreach (Customer customer in (ArrayList)businessObjects["CUSTOMERS"]) { if (customer.Fraudulent) { flaggedCount++; } } if (flaggedCount != 2 * nbDecaCustomers) { throw new Exception("\nError! " + 2 * nbDecaCustomers + " flagged Customer objects were expected.\n"); } else { Console.WriteLine("\nCustomer objects were correctly flagged\n"); } }
public void PerformProcess(IBinder binder) { // generate dummy business objects IDictionary businessObjects = DummyData.GetInstance().GetBusinessObjects(nbDecaItems); // instantiate an inference engine, bind my data and process the rules IEImpl ie = new IEImpl(binder); //ie.LogHandlers += new DispatchLog(HandleLogEvent); ie.LoadRuleBase(new RuleML09NafDatalogAdapter(ruleBaseFile, System.IO.FileAccess.Read)); ie.Process(businessObjects); // processing is done, let's analyze the results IList <IList <Fact> > qrs = ie.RunQuery("Item with weight errors"); if (qrs.Count != (3 * nbDecaItems)) { throw new Exception("Collision!"); } Console.WriteLine("No collision!"); }