This document discusses using rules engines for business logic and provides examples of real-world use cases. It begins with an overview of what rules engines are and how they work, explaining concepts like facts, conditions, actions, and rules. It then discusses different types of rules engines and rule processing algorithms like the basic and Rete algorithms. The document provides code snippets and XML examples from real client-side rules engines developed for applications in domains like forms building, order management, and government benefits applications. It demonstrates how rules engines can externalize and manage complex business rules and workflows.
9. Typical workflow from business to technology The organization defines the business processes.
10. Typical workflow from business to technology A business analyst translates business practices into business rule statements, constraints and actions.
11. Typical workflow from business to technology The software developer implements the rules engine component in the application. The actions and triggers are implemented by the developer. The application is deployed by a developer with the rules externalized
12. Typical workflow from business to technology The organization changes some business processes.
13. Typical workflow from business to technology If the business process doesn’t require new actions, anyone, including this silly intern with a small desk, can update the rules engine. Win.
25. Regular Expressions public static var andOrTrueFalsePattern:RegExp = /AND|OR|true|false/ gi; public static var ruleTokenPattern:RegExp = /([a-zA-Z0-9_]+)/ g; public static var propertyTokenPattern:RegExp = /([a-zA-Z0-9_.]+)/ g; public static var nonSpaceGroups:RegExp = /([a-zA-Z0-9_.'"]+)([^ ])/ gi; public static var quotesPattern:RegExp = /'|"/ gi;
28. Hamcrest API - Matchers: public static const EQUAL_TO:String = "equalTo" ; public static const NOT_EQUAL_TO:String = "notEqualTo" ; public static const LESS_THAN:String = "lessThan" ; public static const LESS_THAN_OR_EQUAL_TO:String = "lessThanOrEqualTo" ; public static const GREATER_THAN:String = "greaterThan" ; public static const GREATER_THAN_OR_EQUAL_TO:String = "greaterThanOrEqualTo" ; public static const CONTAINS:String = "contains" ;
29. Hamcrest API: Get your facts straight! public static function evaluateCondition(target:*, operator:String, source:*):Boolean { try { switch (operator) { case Matchers.EQUAL_TO: assertThat(target, equalTo(source)); break ; case Matchers.NOT_EQUAL_TO: assertThat(target, not(equalTo(source))); break ; case Matchers.LESS_THAN: assertThat(Number(target), lessThan(Number(source))); break ; default : throw new RuleError( "No matcher found for this operator!” ); } } catch (e:Error) { if (e.errorID != RuleError.ILLEGAL_OPERATOR_ERROR) { value= false ; } else { _logger.error(e.message, e.errorID); } }
30.
31.
32.
33.
34.
35. Basic Algorithm Fact condition A Action Fact cB cC cD AND OR Fact Optimizations can give priority to certain conditions, wait to process until all facts are run through conditions, etc.