예제 #1
0
파일: TestAdapter.cs 프로젝트: Ghasan/NxBRE
        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");
        }
예제 #2
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
			IEImpl 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");
		}
예제 #3
0
파일: TestBinder.cs 프로젝트: Ghasan/NxBRE
        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!");
        }
예제 #4
0
파일: TestBinder.cs 프로젝트: Ghasan/NxBRE
        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);

            QueryResultSet 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");
        }
예제 #5
0
		public RatingEngine(int verbosityLevel, int nbDodecaCalls, string ruleBaseFile) {
			this.nbDodecaCalls = nbDodecaCalls;

			ie = new IEImpl(CSharpBinderFactory.LoadFromFile("org.nxbre.examples.TelcoRatingBinder",
			                       																	ruleBaseFile + ".ccb"));

			if (verbosityLevel >= 2) ie.LogHandlers += new DispatchLog(HandleLogEvent);
			if (verbosityLevel >= 1) ie.NewFactHandler += new NewFactEvent(HandleNewFactEvent);
			
			ie.LoadRuleBase(new RuleML086DatalogAdapter(ruleBaseFile, System.IO.FileAccess.Read));

		}
        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;
        }
예제 #7
0
파일: TestAdapter.cs 프로젝트: Ghasan/NxBRE
        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");
        }
        public void IsolatedThreadSafeMemoryCloning()
        {
            //Regression test for bug #1340799
            IInferenceEngine ie1 = new IEImpl(ThreadingModelTypes.Multi);
            ie1.LoadRuleBase(NewTestAdapter());
            int ie1facts = ie1.FactsCount;

            IInferenceEngine ie2 = new IEImpl(ThreadingModelTypes.Multi);
            ie2.LoadRuleBase(NewGedcomAdapter());
            ie2.Assert(new Fact("sex", new Individual("dad"), new Individual("m")));
            ie2.NewWorkingMemory(WorkingMemoryTypes.Isolated);

            Assert.AreEqual(ie1facts, ie1.FactsCount, "FactsCount has wrongly changed");
        }
예제 #9
0
파일: TestBinder.cs 프로젝트: Ghasan/NxBRE
        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");
        }
예제 #10
0
파일: TestBinder.cs 프로젝트: Ghasan/NxBRE
 public void ErrorProcessBO()
 {
     IInferenceEngine ie = new IEImpl();
     ie.LoadRuleBase(new RuleML09NafDatalogAdapter(ruleFilesFolder + "test-0_9.ruleml", FileAccess.Read));
     ie.Process(new Hashtable());
 }
예제 #11
0
파일: TestBinder.cs 프로젝트: Ghasan/NxBRE
        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");
        }
예제 #12
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!");
 }
예제 #13
0
        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.AreXmlOfSameLength(inFile, outFile), "Same XML file lengths");
        }
예제 #14
0
파일: TestAdapter.cs 프로젝트: Ghasan/NxBRE
        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");
        }
예제 #15
0
        public void RuleBaseLabel()
        {
            IInferenceEngine ie = new IEImpl();
            ie.LoadRuleBase(NewTestAdapter());

            Assert.IsTrue(ie.Label.StartsWith("NxBRE"));
        }
예제 #16
0
파일: TestAdapter.cs 프로젝트: Ghasan/NxBRE
        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));
        }
예제 #17
0
파일: TestAdapter.cs 프로젝트: Ghasan/NxBRE
        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");
        }
예제 #18
0
파일: TestAdapter.cs 프로젝트: Ghasan/NxBRE
        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");
        }
예제 #19
0
파일: TestAdapter.cs 프로젝트: Ghasan/NxBRE
        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");
        }