I just finished reading it last week.Nxbre, WritePPTTo the project team for reviewGSPThe implementation requirements of the Rule Engine in.
I don't know why I can't upload files, so I havePPTTo share with you. If you are interested in this open-source project, you can leave a message.PPTAnd only the flow engine is written due to the time relationship.
NxbreOverview
NxbreIncludingInterface EngineAndFlow Engine
Differences between the two engines
The flow engine, which uses XML as a way to control process flow for an application in an external entity. it is basically a wrapper on C #, as it offers all its flow control commands (if/then/else, while, foreach), plus a context of business objects and results.
The inference engine, which is a forward-chaining (data driven) deduction engine and that supports concepts like facts, queries and Implications (as defined in ruleml 0.86 datalog) and like rule priority, mutual Exclusion and precondition (as found in each other cial engines ). it is designed in a way that encourages the separation of roles between the expert who designs the business rules and the programmer who binds them to the Business Objects.
Use Cases of the two engines
1.The inference engine supports priority, mutual exclusions and pre-conditions,
2.The inference engine uses a "standard" rule format (ruleml ),
3.The inference engine has an elaborated Memory Model with support for isolated deduction space.
4.Interface EngineIt is more suitable for knowledge bases or expert systems, because in such systems,FactsMust be maintained
5.Flow EngineIt only parses a piece of logic and performs it according to the result.Action
6.The flow engine is really an instantaneous traversal of logical Branches Using Transient data for evaluations of boolean expressions.
Reason for selection
1.In ourGSPIn the system, noFactThe requirement for persistence is not determined by rule priority, mutex, and precondition.
2.Flow EngineRelatively simple and easy to maintain
ThereforeFlow EngineIs a suitable choice
Flow EngineIntroduction
TheAPI (breimpl)
Init
Reset
Data operationAPI(Ibrerulecontext)
Setobject
GetObject
TheAPI (breimpl)
Process
Stop
The Rules Engine follows the following rules:5Typical steps
1.Create a rule engine object
2.Load a rule set to the engine or replace the Rule Set
3.Submit the data object set to be processed by the rule set to the engine.
4.Command engine execution
5.Export the execution results of the engine and extract processed data from the engine.
Flow EngineRule file in
Rule languages are generally divided into two types:
"OrientedProgramTechnology"The rule language. The user is a technician. InFlow EngineModerate. BreFile (structure isBusinessrule. XSDRequired). The engine actually parses this file.
"Business-oriented"The rule language. The user is the business personnel. The rule customizer should generate this document. InFlow EngineModerate. XbreFile (structure isBusinessrule. XSD).
Two TypesSchemaThe conversion fromTransformxrules. XSLFile.
Flow EngineProvides the following classes for loading rule files:Irulesdriver, abstractruelsdriver, businessrulesfiledriver, javastrulesfiledriver, xbusinessrulesfiledriver, xbusinessrulesstreamdriver, xbusinessrulesstringdriver
Flow EngineRule context in
The rule context contains the following four parts:
1.RulefactorySet(Hashtable ),IncludeRuleCan be the default or custom solution.
2.OperatorSet(Hashtable ),Include available comparison operators, such:==,<,>And so on
3.ResultSet(Hashtable ),IncludeResultAnd initial user data, LookupobjectInResultSearch for data objects in a centralized manner. Each entry<Rule>Will generateResult, Each entryResultWill containMetadataAnd result data.MetadataContainsResultOfRuleOfFactoryAndParam
4.Callstack (stack ),Currently, no application is available.ResultAdd in a centralized mannerResultTo add
Main supported context types:Ibrerulecontext, abstractbrerulecontext, brerulecontextimpl
Flow EngineCreate a rule engine object
BuildBrefactoryconsoleObject, which is responsible for buildingBreimplObject, andLogAndException
BuildBreimpBefore creating an object, you must first buildBrefactory,He is responsibleLogAndExceptionAgentBreimpObjectEventGo up
UseIruledriverInitializationBreimpObject
Related types:Brefactoryconsole,Brefactory,Breimp
Flow EngineLoad rule set
InFlow EngineMediumRule(In. BreUsed in files<Rule>Part of the tag ID.IDUnique object. Load theseRuleThere are two methods:
1.In the initial stage of the engine, search<Factory>Tag, findRulefactory. Use reflection to create instances of this type (the defaultRule)
2.When the engine is running, the Rules file must be defined externallyRuleSpecial processing, which must be constructed in an external environmentBrerulefactoryAnd uses a proxy as its parameter.RuleProcessing
Discussion: whether the third method is required, because when the second method is used to expand the system, developers in the external environment have to understand which extensions are used in the currently used Rule files.RuleAndRuleSome processing methods. When we modify the rule file and add some extensionsRuleDevelopers in the external environment have to modify their programs to adapt to the new rule file.
What we want now is like using the defaultRuleUse extensions in the same wayRuleIn this case, we need to use a registration method to loadRulePreviouslyRuleRegister with the system.
AllRuleBoth must pass the engine context (Ibrerulecontext)SetfactoryMethod registration in engine Context
IbrerulefactoryInExecuteruleMethod.RuleMethod
Supported types of rule sets:Ibrerulefactory, brerulefactory (Mainly for customRuleDesigned, hisExecuteruleOnly the proxy is called.)
When writing proxy methods, note that the engine can provide context and related parameters when calling the proxy, which is urgently needed.
Flow EngineLoad Operator
Very simpleBreimplOfInit ()Method, use the reflection method from the currentAssemblySearch for All implementationsIbreoperatorInterface Type. Create an instance and add it to the context.
The operator here is onlyIfStatement used to determine the size, and+,-,*,/, Or other mathematical functions, which I think can be used as the defaultRuleTo treat
Supported types:Ibreruleoperator,Its Class is actually to implementCompareOfStrategy
Discussion: can this part meet the requirements?
Flow EngineSubmitting data objects
As mentioned above, data objects are treatedResultTo process, encapsulate hisBreruleobjectClass inherited fromAbstractbreruleresult, Will be inserted into the contextResultCentralized. Data Objects are encapsulatedBreruleobjectOfResultAttribute.
Specifically, in the external environmentSetobject (ID, object)To add the data object to the context.
Similarly, when retrieving data objectsGetObject (ID).
Flow EngineCommand engine execution
Before starting the engine, be sure to executeBreimplOfReset ()Method to clear the previousResultSet andCallstackEmpty. Otherwise, this operation may be affected. This indicates thatFlow EngineIt is a transient traversal of a logical branch. It cannot save the results or be used in a system where previous knowledge has an impact on the execution instance.
To execute the engine, you only need to callBreimplOfProcess ()Method, the engine will execute according to the logic specified in the Rule file.
More specifically,Processxml ()Method judgmentXpathnavigatorThe type of the current node to jump to a specific handler.
If the current node has subnodes, callDorecursion ()To perform iteration.
The execution method is in-depth traversal.
Flow EngineExport results
It is very simple.Getresult (ID)To export the running results.IDAndRuleOfIDSame.
Real results are encapsulated inAbstractbreruleresultOfResultAttribute in
Flow EngineInLogAndExceptionProcessing
Provides a wide range of interfaces for exposing internal running conditions to external entities.
You have also specifiedLogAndExceptionTo expose information to different terminals.
Internal useDispatchlog (message, level), dispatchexception (message, level)