public void RuleMLStreamSource() { string ruleBase = "<rulebase><fact><_head><atom><_opr><rel>regular</rel></_opr><ind>Honda</ind></atom></_head></fact></rulebase>"; RuleML08DatalogAdapter adapter = new RuleML08DatalogAdapter(new MemoryStream(new UTF8Encoding().GetBytes(ruleBase)), FileAccess.Read); ArrayList facts = adapter.Facts; Assert.IsNotNull(facts, "Facts not null"); Assert.AreEqual(1, facts.Count, "One fact expected"); Assert.AreEqual("regular", ((Fact)facts[0]).Type, "Fact of type 'regular' expected"); }
public void LoadRules() { // prepare the rule base adapter for reading the rule file var 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; default: throw new ArgumentOutOfRangeException(); } // estimate if a binder is present if (engineConfiguration.Binder != null) { var binder = engineConfiguration.Binder as CSharpBinderConfiguration; if (binder != null) { var cSharpBinderConfiguration = 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 (var sr = File.OpenText(configurationFolder + Path.DirectorySeparatorChar + binderFile)) { engine.LoadRuleBase(ruleBaseAdapter, CSharpBinderFactory.LoadFromString(cSharpBinderConfiguration.Class, sr.ReadToEnd())); } } else if (engineConfiguration.Binder is VisualBasicBinderConfiguration) { var 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 FlowEngineBinderConfiguration) { FlowEngineBinderConfiguration flowEngineBinderConfiguration = (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); } }