コード例 #1
0
ファイル: FraudControl.cs プロジェクト: Ghasan/NxBRE
        public void PerformProcess(IBinder binder)
        {
            // generate dummy business objects
            IDictionary businessObjects = DummyData.GetInstance().GetBusinessObjects(nbDecaCustomers);

            // instantiate an inference engine, bind my data and process the rules
            IInferenceEngine ie = new IEImpl(binder);
            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("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");
        }
コード例 #2
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);

            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");
        }