示例#1
0
文件: Main.cs 项目: vkiktev/NxBRE
 public Stresser(int stresserID, MainClass mc, IInferenceEngine ie)
 {
     this.stresserID = stresserID;
     this.mc         = mc;
     this.ie         = ie;
     this.bumps      = 0;
 }
 public void SetUp()
 {
     _initialDataProviderMock = MockRepository.GenerateMock <IDataProvider>();
     _knowledgeManagerMock    = MockRepository.GenerateMock <IKnowledgeBaseManager>();
     _inferenceEngineMock     = MockRepository.GenerateMock <IInferenceEngine>();
     _fuzzyEngineMock         = MockRepository.GenerateMock <IFuzzyEngine>();
 }
示例#3
0
            public CachedEngine(string configurationFolder, EngineConfiguration engineConfiguration)
            {
                this.configurationFolder = configurationFolder;
                this.engineConfiguration = engineConfiguration;

                // instantiate the IInferenceEngine
                engine = new IEImpl(ThreadingModelTypes.MultiHotSwap);
            }
示例#4
0
 public void DestroyIE()
 {
     ie = null;
     if (Logger.IsInferenceEngineVerbose)
     {
         Logger.InferenceEngineSource.TraceEvent(TraceEventType.Verbose, 0, "DestroyIE()");
     }
 }
示例#5
0
        public RatingEngine(int verbosityLevel, int nbDodecaCalls, string ruleBaseFile)
        {
            this.nbDodecaCalls = nbDodecaCalls;

            ie = new IEImpl(CSharpBinderFactory.LoadFromFile("NxBRE.Examples.TelcoRatingBinder",
                                   																	ruleBaseFile + ".ccb"));

            if (verbosityLevel >= 1) ie.NewFactHandler += new NewFactEvent(HandleNewFactEvent);

            ie.LoadRuleBase(new RuleML09NafDatalogAdapter(ruleBaseFile, System.IO.FileAccess.Read));
        }
示例#6
0
 protected virtual void NewIEImpl(IBinder bob)
 {
     if (bob != null)
     {
         ie = new IEImpl(bob);
     }
     else
     {
         ie = new IEImpl();
     }
 }
示例#7
0
 public FuzzyExpert(
     IDataProvider dataProvider,
     IKnowledgeBaseManager knowledgeBaseManager,
     IInferenceEngine inferenceEngine,
     IFuzzyEngine fuzzyEngine)
 {
     _initialDataProvider = dataProvider ?? throw new ArgumentNullException(nameof(dataProvider));
     _knowledgeManager    = knowledgeBaseManager ?? throw new ArgumentNullException(nameof(knowledgeBaseManager));
     _inferenceEngine     = inferenceEngine ?? throw new ArgumentNullException(nameof(inferenceEngine));
     _fuzzyEngine         = fuzzyEngine ?? throw new ArgumentNullException(nameof(fuzzyEngine));
 }
示例#8
0
        public RatingEngine(int verbosityLevel, int nbDodecaCalls, string ruleBaseFile)
        {
            this.nbDodecaCalls = nbDodecaCalls;

            ie = new IEImpl(CSharpBinderFactory.LoadFromFile("NxBRE.Examples.TelcoRatingBinder",
                                                             ruleBaseFile + ".ccb"));

            if (verbosityLevel >= 1)
            {
                ie.NewFactHandler += new NewFactEvent(HandleNewFactEvent);
            }

            ie.LoadRuleBase(new RuleML09NafDatalogAdapter(ruleBaseFile, System.IO.FileAccess.Read));
        }
示例#9
0
文件: Main.cs 项目: Ghasan/NxBRE
        public static void Main(string[] args)
        {
            HOT_SWAP = Boolean.Parse(args[0]);
            binder = Boolean.Parse(args[1]);
            if (args.Length > 2) csharpBinder = Boolean.Parse(args[2]);

            MAIN_IE = new IEImpl((HOT_SWAP)?ThreadingModelTypes.MultiHotSwap:ThreadingModelTypes.Multi);
            SECOND_IE = new IEImpl((HOT_SWAP)?ThreadingModelTypes.MultiHotSwap:ThreadingModelTypes.Single);

            MainClass mc = new MainClass();

            InitMainEngine();

            SECOND_IE.LoadRuleBase(new RuleML09NafDatalogAdapter(XMLFOLDER + "subtract.ruleml", System.IO.FileAccess.Read));

            mc.RunTests();
        }
示例#10
0
        /// <summary>
        /// Adds an Inference Engine to the Triple Store
        /// </summary>
        /// <param name="reasoner">Reasoner to add</param>
        public void AddInferenceEngine(IInferenceEngine reasoner)
        {
            this._reasoners.Add(reasoner);

            //Apply Inference to all existing Graphs
            if (this._graphs.Count > 0)
            {
                lock (this._graphs)
                {
                    //Have to do a ToList() in case someone else inserts a Graph
                    //Which ApplyInference may do if the Inference information is stored in a special Graph
                    foreach (IGraph g in this._graphs.ToList())
                    {
                        this.ApplyInference(g);
                    }
                }
            }
        }
示例#11
0
文件: Main.cs 项目: vkiktev/NxBRE
        public static void Main(string[] args)
        {
            HOT_SWAP = Boolean.Parse(args[0]);
            binder   = Boolean.Parse(args[1]);
            if (args.Length > 2)
            {
                csharpBinder = Boolean.Parse(args[2]);
            }

            MAIN_IE   = new IEImpl((HOT_SWAP)?ThreadingModelTypes.MultiHotSwap:ThreadingModelTypes.Multi);
            SECOND_IE = new IEImpl((HOT_SWAP)?ThreadingModelTypes.MultiHotSwap:ThreadingModelTypes.Single);

            MainClass mc = new MainClass();

            InitMainEngine();

            SECOND_IE.LoadRuleBase(new RuleML09NafDatalogAdapter(XMLFOLDER + "subtract.ruleml", System.IO.FileAccess.Read));

            mc.RunTests();
        }
示例#12
0
        private void RunTestBinderEvents(IInferenceEngine ie)
        {
            ie.LoadRuleBase(new RuleML09NafDatalogAdapter(ruleFilesFolder + "events-test.ruleml",
                                                          FileAccess.Read));

            Hashtable bo = new Hashtable();

            bo.Add("ASSERTED", new ArrayList());
            bo.Add("RETRACTED", new ArrayList());
            bo.Add("MODIFIED", new ArrayList());

            ie.Process(bo);

            Assert.AreEqual(2, ((ArrayList)bo["ASSERTED"]).Count, "Count Asserted");
            Assert.IsTrue(Misc.IListToString((ArrayList)bo["ASSERTED"]).Contains("toAssert{whatever}"), "Asserted Right");

            Assert.AreEqual(1, ((ArrayList)bo["RETRACTED"]).Count, "Count Retracted");
            Assert.AreEqual("toRetract{whatever}", ((ArrayList)bo["RETRACTED"])[0].ToString(), "Retracted Right");

            Assert.AreEqual(2, ((ArrayList)bo["MODIFIED"]).Count, "Count Modified");
            Assert.AreEqual("toModify{whatever}", ((ArrayList)bo["MODIFIED"])[0].ToString(), "Modified From Right");
            Assert.AreEqual("toModify{done}", ((ArrayList)bo["MODIFIED"])[1].ToString(), "Modified To Right");
        }
示例#13
0
        /// <summary>
        /// Adds an Inference Engine to the Triple Store
        /// </summary>
        /// <param name="reasoner">Reasoner to add</param>
        public void AddInferenceEngine(IInferenceEngine reasoner)
        {
            this._reasoners.Add(reasoner);

            //Apply Inference to all existing Graphs
            if (this._graphs.Count > 0)
            {
                lock (this._graphs)
                {
                    //Have to do a ToList() in case someone else inserts a Graph
                    //Which ApplyInference may do if the Inference information is stored in a special Graph
                    foreach (IGraph g in this._graphs.ToList())
                    {
                        this.ApplyInference(g);
                    }
                }
            }
        }
示例#14
0
 /// <summary>
 /// Removes an Inference Engine from the Triple Store
 /// </summary>
 /// <param name="reasoner">Reasoner to remove</param>
 public void RemoveInferenceEngine(IInferenceEngine reasoner)
 {
     this._reasoners.Remove(reasoner);
 }
示例#15
0
 /// <summary>
 /// Creates a new Reasoner Graph which is a wrapper around an existing Graph with a reasoner applied and the resulting Triples materialised
 /// </summary>
 /// <param name="g">Graph</param>
 /// <param name="reasoner">Reasoner</param>
 public ReasonerGraph(IGraph g, IInferenceEngine reasoner)
 {
     this._baseGraph = g;
     this._reasoners.Add(reasoner);
     this.Initialise();
 }
示例#16
0
 /// <summary>
 /// Creates a new Reasoner Graph which is a wrapper around an existing Graph with a reasoner applied and the resulting Triples materialised
 /// </summary>
 /// <param name="g">Graph</param>
 /// <param name="reasoner">Reasoner</param>
 public ReasonerGraph(IGraph g, IInferenceEngine reasoner)
 {
     this._baseGraph = g;
     this._reasoners.Add(reasoner);
     this.Initialise();
 }
示例#17
0
 protected virtual void NewIEImpl(IBinder bob)
 {
     if (bob != null) ie = new IEImpl(bob);
     else ie = new IEImpl();
 }
示例#18
0
 public void DestroyIE()
 {
     ie = null;
       	if (Logger.IsInferenceEngineVerbose) Logger.InferenceEngineSource.TraceEvent(TraceEventType.Verbose, 0, "DestroyIE()");
 }
示例#19
0
 /// <summary>
 /// Instantiates a new IEFacade that wraps an instance of the Inference Engine.
 /// </summary>
 /// <param name="ie">The Inference Engine the new facade must encapsulate.</param>
 public IEFacade(IInferenceEngine ie)
 {
     this.ie = ie;
 }
示例#20
0
            public CachedEngine(string configurationFolder, EngineConfiguration engineConfiguration)
            {
                this.configurationFolder = configurationFolder;
                this.engineConfiguration = engineConfiguration;

                // instantiate the IInferenceEngine
                engine = new IEImpl(ThreadingModelTypes.MultiHotSwap);
            }
示例#21
0
        private void RunTestBinderEvents(IInferenceEngine ie)
        {
            ie.LoadRuleBase(new RuleML09NafDatalogAdapter(ruleFilesFolder + "events-test.ruleml",
                                                   	 FileAccess.Read));

            //ie.LogHandlers += new DispatchLog(ShowAllLogs);
              Hashtable bo = new Hashtable();
              bo.Add("ASSERTED", new ArrayList());
              bo.Add("RETRACTED", new ArrayList());
              bo.Add("MODIFIED", new ArrayList());

              ie.Process(bo);

            Assert.AreEqual(1, ((ArrayList)bo["ASSERTED"]).Count, "Count Asserted");
            Assert.AreEqual("toAssert{whatever}", ((ArrayList)bo["ASSERTED"])[0].ToString(), "Asserted Right");

            Assert.AreEqual(1, ((ArrayList)bo["RETRACTED"]).Count, "Count Retracted");
            Assert.AreEqual("toRetract{whatever}", ((ArrayList)bo["RETRACTED"])[0].ToString(), "Retracted Right");

            Assert.AreEqual(2, ((ArrayList)bo["MODIFIED"]).Count, "Count Modified");
            Assert.AreEqual("toModify{whatever}", ((ArrayList)bo["MODIFIED"])[0].ToString(), "Modified From Right");
            Assert.AreEqual("toModify{done}", ((ArrayList)bo["MODIFIED"])[1].ToString(), "Modified To Right");
        }
示例#22
0
        public void LoadRuleBase(MainForm mf, string uri, bool onlyFacts)
        {
            IBinder binder = null;

            // give priority to custom compiled binders
            if (File.Exists(uri + ".ccb"))
            {
                up.lastBinderClassName = mf.PromptForString("C# Custom Binder - " + uri + ".ccb",
                                                            "Enter the fully qualified name of the binder class:",
                                                            up.lastBinderClassName);
                binder = CSharpBinderFactory.LoadFromFile(up.lastBinderClassName, uri + ".ccb");
            }
            else if (File.Exists(uri + ".vcb"))
            {
                up.lastBinderClassName = mf.PromptForString("VB.NET Custom Binder - " + uri + ".vcb",
                                                            "Enter the fully qualified name of the binder class:",
                                                            up.lastBinderClassName);
                binder = VisualBasicBinderFactory.LoadFromFile(up.lastBinderClassName, uri + ".vcb");
            }
            else if (File.Exists(uri + ".xbre"))
            {
                bool isBeforeAfter = mf.AskYesNoQuestion("Flow Engine Binder - " + uri + ".xbre",
                                                         uri + ".xbre\n\nIs this binder running in Before/After mode ?\n\n(No would mean that it runs in Control Process mode)");

                binder = new FlowEngineBinder(uri + ".xbre", isBeforeAfter?BindingTypes.BeforeAfter:BindingTypes.Control);
            }

            if (!onlyFacts)
            {
                ie = new IEImpl(binder);
            }

            switch (Path.GetExtension(uri).ToLower())
            {
            case ".ruleml":
                try {
                    if (onlyFacts)
                    {
                        ie.LoadFacts(new RuleML09NafDatalogAdapter(uri, FileAccess.Read));
                    }
                    else
                    {
                        ie.LoadRuleBase(new RuleML09NafDatalogAdapter(uri, FileAccess.Read));
                    }
                }
                catch (Exception firstAttemptException) {
                    try {
                        if (onlyFacts)
                        {
                            ie.LoadFacts(new RuleML086NafDatalogAdapter(uri, FileAccess.Read));
                        }
                        else
                        {
                            ie.LoadRuleBase(new RuleML086NafDatalogAdapter(uri, FileAccess.Read));
                        }
                    }
                    catch (Exception) {
                        try {
                            if (onlyFacts)
                            {
                                ie.LoadFacts(new RuleML086DatalogAdapter(uri, FileAccess.Read));
                            }
                            else
                            {
                                ie.LoadRuleBase(new RuleML086DatalogAdapter(uri, FileAccess.Read));
                            }
                        }
                        catch (Exception) {
                            try {
                                if (onlyFacts)
                                {
                                    ie.LoadFacts(new RuleML08DatalogAdapter(uri, FileAccess.Read));
                                }
                                else
                                {
                                    ie.LoadRuleBase(new RuleML08DatalogAdapter(uri, FileAccess.Read));
                                }
                            } catch (Exception) {
                                // the fall-back policy failed, hence throw the original exception
                                throw firstAttemptException;
                            }
                        }
                    }
                }
                break;

            case ".hrf":
                if (onlyFacts)
                {
                    ie.LoadFacts(new HRF086Adapter(uri, FileAccess.Read));
                }
                else
                {
                    ie.LoadRuleBase(new HRF086Adapter(uri, FileAccess.Read));
                }
                break;

            case ".vdx":
                string[] selectedPages = mf.PromptForVisioPageNameSelection(Visio2003Adapter.GetPageNames(uri));
                if (selectedPages != null)
                {
                    if (onlyFacts)
                    {
                        ie.LoadFacts(new Visio2003Adapter(uri, FileAccess.Read, selectedPages));
                    }
                    else
                    {
                        ie.LoadRuleBase(new Visio2003Adapter(uri, FileAccess.Read, (DialogResult.Yes == MessageBox.Show(mf,
                                                                                                                        "Is your Visio rule base using strict syntax?",
                                                                                                                        "Visio strictness",
                                                                                                                        MessageBoxButtons.YesNo,
                                                                                                                        MessageBoxIcon.Question,
                                                                                                                        MessageBoxDefaultButton.Button2)), selectedPages));
                    }
                }
                break;

            default:
                throw new Exception(Path.GetExtension(uri) + " is an unknown extension.");
            }
        }
示例#23
0
        public void LoadRuleBase(MainForm mf, string uri, bool onlyFacts)
        {
            IBinder binder = null;
            // give priority to custom compiled binders
            if (File.Exists(uri + ".ccb")) {
                up.lastBinderClassName = mf.PromptForString("C# Custom Binder - " + uri + ".ccb",
                                                      	 "Enter the fully qualified name of the binder class:",
                                                     		 up.lastBinderClassName);
                binder = CSharpBinderFactory.LoadFromFile(up.lastBinderClassName, uri + ".ccb");
            }
            else if (File.Exists(uri + ".vcb")) {
                up.lastBinderClassName = mf.PromptForString("VB.NET Custom Binder - " + uri + ".vcb",
                                                      	 "Enter the fully qualified name of the binder class:",
                                                     		 up.lastBinderClassName);
                binder = VisualBasicBinderFactory.LoadFromFile(up.lastBinderClassName, uri + ".vcb");
            }
            else if (File.Exists(uri + ".xbre")) {
                bool isBeforeAfter = mf.AskYesNoQuestion("Flow Engine Binder - " + uri + ".xbre",
                                                         uri + ".xbre\n\nIs this binder running in Before/After mode ?\n\n(No would mean that it runs in Control Process mode)");

                binder = new FlowEngineBinder(uri + ".xbre", isBeforeAfter?BindingTypes.BeforeAfter:BindingTypes.Control);
            }

            if (!onlyFacts) ie = new IEImpl(binder);

            switch(Path.GetExtension(uri).ToLower()) {
                case ".ruleml":
                    try {
                        if (onlyFacts) ie.LoadFacts(new RuleML09NafDatalogAdapter(uri, FileAccess.Read));
                        else ie.LoadRuleBase(new RuleML09NafDatalogAdapter(uri, FileAccess.Read));
                    }
                    catch(Exception firstAttemptException) {
                        try {
                            if (onlyFacts) ie.LoadFacts(new RuleML086NafDatalogAdapter(uri, FileAccess.Read));
                            else ie.LoadRuleBase(new RuleML086NafDatalogAdapter(uri, FileAccess.Read));
                        }
                        catch(Exception) {
                            try {
                                if (onlyFacts) ie.LoadFacts(new RuleML086DatalogAdapter(uri, FileAccess.Read));
                                else ie.LoadRuleBase(new RuleML086DatalogAdapter(uri, FileAccess.Read));
                            }
                            catch(Exception) {
                                try {
                                    if (onlyFacts) ie.LoadFacts(new RuleML08DatalogAdapter(uri, FileAccess.Read));
                                    else ie.LoadRuleBase(new RuleML08DatalogAdapter(uri, FileAccess.Read));
                                } catch(Exception) {
                                    // the fall-back policy failed, hence throw the original exception
                                    throw firstAttemptException;
                                }
                            }
                        }
                    }
                    break;

                case ".hrf":
                    if (onlyFacts) ie.LoadFacts(new HRF086Adapter(uri, FileAccess.Read));
                    else ie.LoadRuleBase(new HRF086Adapter(uri, FileAccess.Read));
                    break;

                case ".vdx":
                    string[] selectedPages = mf.PromptForVisioPageNameSelection(Visio2003Adapter.GetPageNames(uri));
                    if (selectedPages != null) {
                        if (onlyFacts) ie.LoadFacts(new Visio2003Adapter(uri, FileAccess.Read, selectedPages));
                        else ie.LoadRuleBase(new Visio2003Adapter(uri, FileAccess.Read, (DialogResult.Yes == MessageBox.Show(mf,
                                                                                    "Is your Visio rule base using strict syntax?",
                                                                                    "Visio strictness",
                                                                                    MessageBoxButtons.YesNo,
                                                                                    MessageBoxIcon.Question,
                                                            MessageBoxDefaultButton.Button2)), selectedPages));
                    }
                    break;

                default:
                    throw new Exception(Path.GetExtension(uri) + " is an unknown extension.");
            }
        }
示例#24
0
 /// <summary>
 /// Removes an Inference Engine from the Triple Store
 /// </summary>
 /// <param name="reasoner">Reasoner to remove</param>
 public void RemoveInferenceEngine(IInferenceEngine reasoner)
 {
     this._reasoners.Remove(reasoner);
 }
示例#25
0
 public void DestroyIE()
 {
     ie = null;
     Console.WriteLine("DestroyIE()");
 }
示例#26
0
 /// <summary>
 /// Creates a new Reasoner Graph which is a wrapper around an existing Graph with a reasoner applied and the resulting Triples materialised.
 /// </summary>
 /// <param name="g">Graph.</param>
 /// <param name="reasoner">Reasoner.</param>
 public ReasonerGraph(IGraph g, IInferenceEngine reasoner)
 {
     _baseGraph = g;
     _reasoners.Add(reasoner);
     Initialise();
 }
示例#27
0
文件: Main.cs 项目: Ghasan/NxBRE
 public Stresser(int stresserID, MainClass mc, IInferenceEngine ie)
 {
     this.stresserID = stresserID;
     this.mc = mc;
     this.ie = ie;
     this.bumps = 0;
 }
示例#28
0
 /// <summary>
 /// Instantiates a new IEFacade that wraps an instance of the Inference Engine.
 /// </summary>
 /// <param name="ie">The Inference Engine the new facade must encapsulate.</param>
 public IEFacade(IInferenceEngine ie)
 {
     this.ie = ie;
 }
示例#29
0
 public void DestroyIE()
 {
     ie = null;
     Console.WriteLine("DestroyIE()");
 }