Esempio n. 1
0
        public void HRFDirectionless()
        {
            // test added after detecting a bug in the adapter when the direction is empty string
            using(HRF086Adapter hrfa = new HRF086Adapter(new MemoryStream(Encoding.ASCII.GetBytes("+Luxury{Rolex};")),
                                                           FileAccess.Read)) {

                Assert.AreEqual(1, hrfa.Facts.Count);
            }
        }
Esempio n. 2
0
        public string PromptQueryOperation(MainForm mf)
        {
            up.lastHRFQuery = mf.PromptForString("Custom Query",
                                            "Enter a query in Human Readable Format (ASCII):",
                                         	  up.lastHRFQuery);

                if (up.lastHRFQuery != string.Empty)
                {
                    if (!up.lastHRFQuery.EndsWith(";")) up.lastHRFQuery += ";";

                    using (HRF086Adapter hrfa =
                        new HRF086Adapter(new MemoryStream(
                                                Encoding.ASCII.GetBytes("#DIRECTION_FORWARD\n\r[custom query]\n\r" + up.lastHRFQuery)),
                                                FileAccess.Read))
                    {
                        if (hrfa.Queries.Count == 1)
                        {
                            return getResultsAsString(ie.RunQuery(hrfa.Queries[0]));
                        }
                        else
                        {
                            throw new ApplicationException("custom query text must contain exactly one query");
                        }
                    }
                }

            return string.Empty;
        }
Esempio n. 3
0
            public void LoadRules()
            {
                // prepare the rule base adapter for reading the rule file
                string ruleFileFullPath = configurationFolder + Path.DirectorySeparatorChar + RuleFile;

                if (Logger.IsInferenceEngineVerbose)
                    Logger.InferenceEngineSource.TraceEvent(TraceEventType.Verbose,
                                                   0,
                                                   "Loading rule file: "
                                                   + ruleFileFullPath
                                                   + " of format: "
                                                   + engineConfiguration.Rules.Format);

                IRuleBaseAdapter ruleBaseAdapter = null;

                switch(engineConfiguration.Rules.Format) {
                    case RulesFormat.HRF086:
                        ruleBaseAdapter = new HRF086Adapter(ruleFileFullPath, FileAccess.Read);
                        break;

                    case RulesFormat.RuleML08Datalog:
                        ruleBaseAdapter = new RuleML08DatalogAdapter(ruleFileFullPath, FileAccess.Read);
                        break;

                    case RulesFormat.RuleML086Datalog:
                        ruleBaseAdapter = new RuleML086DatalogAdapter(ruleFileFullPath, FileAccess.Read);
                        break;

                    case RulesFormat.RuleML086NafDatalog:
                        ruleBaseAdapter = new RuleML086NafDatalogAdapter(ruleFileFullPath, FileAccess.Read);
                        break;

                    case RulesFormat.RuleML09NafDatalog:
                        ruleBaseAdapter = new RuleML09NafDatalogAdapter(ruleFileFullPath, FileAccess.Read);
                        break;

                    case RulesFormat.Visio2003:
                        ruleBaseAdapter = new Visio2003Adapter(ruleFileFullPath, FileAccess.Read);
                        break;
                }

                // estimate if a binder is present
                if (engineConfiguration.Binder != null) {
                    if (engineConfiguration.Binder is CSharpBinderConfiguration) {
                        CSharpBinderConfiguration cSharpBinderConfiguration = (CSharpBinderConfiguration)engineConfiguration.Binder;
                        binderFile = cSharpBinderConfiguration.File;

                        if (Logger.IsInferenceEngineVerbose)
                            Logger.InferenceEngineSource.TraceEvent(TraceEventType.Verbose,
                                                           0,
                                                           "Using CSharp binder file: "
                                                           + binderFile);

                        // we load the binder code in a string and then compile it: this method is more reliable than
                        // providing a file path directly
                        using (StreamReader sr = File.OpenText(configurationFolder + Path.DirectorySeparatorChar + binderFile)) {
                            engine.LoadRuleBase(ruleBaseAdapter,
                                                CSharpBinderFactory.LoadFromString(cSharpBinderConfiguration.Class, sr.ReadToEnd()));
                        }
                    }
                    else if (engineConfiguration.Binder is VisualBasicBinderConfiguration) {
                        VisualBasicBinderConfiguration visualBasicBinderConfiguration = (VisualBasicBinderConfiguration)engineConfiguration.Binder;
                        binderFile = visualBasicBinderConfiguration.File;

                        if (Logger.IsInferenceEngineVerbose)
                            Logger.InferenceEngineSource.TraceEvent(TraceEventType.Verbose,
                                                           0,
                                                           "Using Visual Basic binder file: "
                                                           + binderFile);

                        // we load the binder code in a string and then compile it: this method is more reliable than
                        // providing a file path directly
                        using (StreamReader sr = File.OpenText(configurationFolder + Path.DirectorySeparatorChar + binderFile)) {
                            engine.LoadRuleBase(ruleBaseAdapter,
                                                VisualBasicBinderFactory.LoadFromString(visualBasicBinderConfiguration.Class, sr.ReadToEnd()));
                        }
                    }
                    else if (engineConfiguration.Binder is NxBRE.InferenceEngine.Registry.FlowEngineBinderConfiguration) {
                        NxBRE.InferenceEngine.Registry.FlowEngineBinderConfiguration flowEngineBinderConfiguration = (NxBRE.InferenceEngine.Registry.FlowEngineBinderConfiguration)engineConfiguration.Binder;
                        binderFile = flowEngineBinderConfiguration.File;

                        if (Logger.IsInferenceEngineVerbose)
                            Logger.InferenceEngineSource.TraceEvent(TraceEventType.Verbose,
                                                           0,
                                                           "Using FlowEngine binder file: "
                                                           + binderFile);

                        engine.LoadRuleBase(ruleBaseAdapter,
                                            new NxBRE.InferenceEngine.IO.FlowEngineBinder(configurationFolder + Path.DirectorySeparatorChar + binderFile, flowEngineBinderConfiguration.Type));
                    }
                    else {
                        throw new BREException("Unexpected type of binder object in registry configuration: " + engineConfiguration.Binder.GetType().FullName);
                    }
                }
                else {
                    // no binder specified
                    binderFile = null;
                    engine.LoadRuleBase(ruleBaseAdapter);
                }
            }
Esempio n. 4
0
        public string PromptFactOperation(MainForm mf, string operation)
        {
            up.lastHRFFact = mf.PromptForString("Manual Fact " + operation,
                                            "Enter a fact in Human Readable Format (ASCII):",
                                         	  up.lastHRFFact);

            if (up.lastHRFFact != String.Empty) {
                if (!up.lastHRFFact.EndsWith(";")) up.lastHRFFact += ";";
                int iniNbFacts = ie.FactsCount;
                using(HRF086Adapter hrfa = new HRF086Adapter(new MemoryStream(Encoding.ASCII.GetBytes("#DIRECTION_FORWARD\n\r+" + up.lastHRFFact)),
                                                           FileAccess.Read)) {

                    foreach(Fact f in hrfa.Facts)
                        if (operation == "Assertion") ie.Assert(f);
                        else ie.Retract(f);
                }

                if (iniNbFacts != ie.FactsCount) return up.lastHRFFact;
            }

            return String.Empty;
        }