示例#1
0
        public void RuleML08SaveRuleBase()
        {
            IInferenceEngine ie = new IEImpl();

            ie.LoadRuleBase(new RuleML08DatalogAdapter(ruleFilesFolder + "discount.ruleml", FileAccess.Read));
            ie.SaveRuleBase(new RuleML08DatalogAdapter(outFile, FileAccess.Write));

            // for now, let's reload the rulebase
            ie.LoadRuleBase(new RuleML08DatalogAdapter(outFile, FileAccess.Read));
        }
示例#2
0
        public void RuleML086SaveRuleBase()
        {
            IInferenceEngine ie = new IEImpl();

            ie.LoadRuleBase(new RuleML086DatalogAdapter(ruleFilesFolder + "endlessloop.ruleml", FileAccess.Read));
            ie.SaveRuleBase(new RuleML086DatalogAdapter(outFile, FileAccess.Write));

            ie.LoadRuleBase(new RuleML086DatalogAdapter(outFile, FileAccess.Read));

            Assert.IsTrue(AreSameXml(ruleFilesFolder + "endlessloop.ruleml", outFile), "Same XML");
        }
示例#3
0
        public void RuleMLNaf091SaveRuleBase()
        {
            string inFile = ruleFilesFolder + "test-0_91.ruleml";

            IInferenceEngine ie = new IEImpl();

            ie.LoadRuleBase(new RuleML091NafDatalogAdapter(inFile, FileAccess.Read));
            ie.SaveRuleBase(new RuleML091NafDatalogAdapter(outFile, FileAccess.Write));

            ie.LoadRuleBase(new RuleML091NafDatalogAdapter(outFile, FileAccess.Read));

            Assert.IsTrue(AreSameXml(inFile, outFile), "Same XML: " + inFile + " and " + outFile);
        }
示例#4
0
        public void HRFLoadRuleBase()
        {
            IInferenceEngine ie = new IEImpl();

            ie.LoadRuleBase(new HRF086Adapter(ruleFilesFolder + "gedcom-relations.hrf", FileAccess.Read));
            Assert.AreEqual("forward", ie.Direction, "Gedcom Direction");
            Assert.AreEqual("gedcom-relations", ie.Label, "Gedcom Label");
            Assert.AreEqual(0, ie.FactsCount, "Gedcom Facts");

            ie.LoadRuleBase(new HRF086Adapter(ruleFilesFolder + "fraudcontrol.hrf", FileAccess.Read));
            Assert.AreEqual(3, ie.FactsCount, "FraudControl Facts");

            ie.LoadRuleBase(new HRF086Adapter(ruleFilesFolder + "telco-rating.hrf", FileAccess.Read));
            Assert.AreEqual(3, ie.FactsCount, "Telco-Rating Facts");
        }
示例#5
0
        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");
        }
示例#6
0
        public void ErrorProcessBO()
        {
            IInferenceEngine ie = new IEImpl();

            ie.LoadRuleBase(new RuleML09NafDatalogAdapter(ruleFilesFolder + "test-0_9.ruleml", FileAccess.Read));
            ie.Process(new Hashtable());
        }
示例#7
0
        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");
        }
示例#8
0
        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!");
        }
示例#9
0
 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!");
 }
示例#10
0
        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);
        }
示例#11
0
        public void RuleML086SaveRuleBase()
        {
            IInferenceEngine ie = new IEImpl();

            ie.LoadRuleBase(new RuleML086DatalogAdapter(ruleFilesFolder + "endlessloop.ruleml", FileAccess.Read));
            ie.SaveRuleBase(new RuleML086DatalogAdapter(outFile, FileAccess.Write));

            // for now, compare only the size
            Assert.IsTrue(AreXmlOfSameLength(ruleFilesFolder + "endlessloop.ruleml", outFile), "Same XML size");
        }
示例#12
0
        public void Setup()
        {
            ie = new IEImpl();

            ie.LoadRuleBase(new RuleML09NafDatalogAdapter(ruleFilesFolder + "events-test.ruleml",
                                                          FileAccess.Read));

            newFactEventCount    = 0;
            deleteFactEventCount = 0;
            modifyFactEventCount = 0;
            factEventCount       = 0;
        }
示例#13
0
        public void RuleMLNaf09SaveRuleBase()
        {
            string inFile = ruleFilesFolder + "test-0_9.ruleml";

            IInferenceEngine ie = new IEImpl();

            ie.LoadRuleBase(new RuleML09NafDatalogAdapter(inFile, FileAccess.Read));
            ie.SaveRuleBase(new RuleML09NafDatalogAdapter(outFile, FileAccess.Write));

            // for now, compare only the size
            Assert.IsTrue(AreXmlOfSameLength(inFile, outFile), "Same XML size");
        }
示例#14
0
        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");
        }
示例#15
0
文件: Main.cs 项目: vkiktev/NxBRE
        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);
            }
        }
示例#16
0
        public void HRFSaveRuleBase()
        {
            IInferenceEngine ie = new IEImpl();

            ie.LoadRuleBase(new HRF086Adapter(ruleFilesFolder + "gedcom-relations.hrf", FileAccess.Read));
            ie.SaveRuleBase(new HRF086Adapter(outFileHRF, FileAccess.Write));

            IInferenceEngine ie2 = new IEImpl();

            ie2.LoadRuleBase(new HRF086Adapter(outFileHRF, FileAccess.Read));

            Assert.AreEqual(ie.Direction, ie2.Direction, "Same Direction");
            Assert.AreEqual(ie.Label, ie2.Label, "Same Label");
        }
示例#17
0
        public void RuleML086SaveFacts()
        {
            IInferenceEngine ie = new IEImpl();

            ie.LoadRuleBase(new RuleML086NafDatalogAdapter(ruleFilesFolder + "test-0_86.ruleml", FileAccess.Read));

            ie.SaveFacts(new RuleML086NafDatalogAdapter(outFile, FileAccess.Write));

            IInferenceEngine ie2 = new IEImpl();

            ie2.LoadRuleBase(new RuleML086NafDatalogAdapter(outFile, FileAccess.Read));
            Assert.AreEqual(ie.Label, ie2.Label, "Label");
            Assert.AreEqual(ie.FactsCount, ie2.FactsCount, "FactsCount");
        }
示例#18
0
		protected string GenerateRuleFile(string inFile, SaveFormatAttributes sfa) {
			string outFile = outFilesFolder + sfa.ToString().ToLower() + "-" + inFile;
			
			FileInfo fi = new FileInfo(outFile);
			if (fi.Exists) fi.Delete();
			
			IInferenceEngine ie = new IEImpl();
			ie.LoadRuleBase(new RuleML09NafDatalogAdapter(ruleFilesFolder + inFile, FileAccess.Read));
			ie.SaveRuleBase(new RuleML09NafDatalogAdapter(outFile, FileAccess.Write, sfa));
			
			Console.Out.WriteLine("Generated: {0}", outFile);
			
			return outFile;
		}
示例#19
0
        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");
        }
示例#20
0
        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");
        }
        private void PerformSaveTest(string ruleFile, SaveFormatAttributes sfa)
        {
            string inFile = ruleFilesFolder + ruleFile;

            string   outFile = outFilesFolder + "outtest.ruleml";
            FileInfo fi      = new FileInfo(outFile);

            if (fi.Exists)
            {
                fi.Delete();
            }

            IInferenceEngine ie = new IEImpl();

            ie.LoadRuleBase(new RuleML09NafDatalogAdapter(inFile, FileAccess.Read));
            ie.SaveRuleBase(new RuleML09NafDatalogAdapter(outFile, FileAccess.Write, sfa));

            Assert.IsTrue(TestAdapter.AreSameXml(inFile, outFile), "Same XML file lengths");
        }
示例#22
0
        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");
            }
        }
示例#23
0
        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!");
        }