• Like

Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Developing applications with rules, workflow and event processing (it@cork 2010)

  • 3,104 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
3,104
On Slideshare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
248
Comments
0
Likes
3

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Mark Proctor Co-Creator Project Lead
    • T he SkyNet funding bill is passed.
    • 2. The system goes online on August 4th, 1997.
    • 3. Human decisions are removed from strategic defense.
    • 4. SkyNet begins to learn at a geometric rate.
    • 5. It becomes self-aware at 2:14am Eastern time, August 29th
    • 6. In a panic, they try to pull the plug.
    • 7. And, Skynet fights back
  • 8. Topics
    • Books
    • 9. Community
    • 10. History
    • 11. Unified Concept
    • 12. Declarative Domain Overview
      • Declarative Programming
      • 13. Domain Overview
      • 14. The Future
    • Expert
      • Quick Example
      • 15. Conditional Elements
      • 16. Truth Maintenance and Inference
    • Fusion
    • 17. Decision Tables
    • 18. Guvnor
    • 19. What's new in 5.1
  • 20. Books
    • Introduction to Expert Systems
      • Peter Jackson
    • Expert Systems, Principles and Programming
      • Joseph C. Giarratano and Gary D. Riley
  • 21. Oh And There are Drools Books Too
  • 22. Community
  • 23. Drools Research Network
    • http://www.jboss.org/drools/research-network.html
      • 30+ Research related pages
      • 24. Many more as haven't updated
  • 25. Community Collaboration
    • 40% of Drools work now done in the community
      • US Navy Healthcare
      • 26. OSDE (Argentina's largest healthcare organisation)
  • 27. Standards
    • Part of the W3C RIF working group
    • 28. Director in RuleML group
  • 29. Sample Industries and Users
    • Investment
      • Millennium Investment Group (MIG)
    • Logistics
      • Fedex
    • Airline
      • Sabre
    • Mortgage
      • Franklin American
    • Healthcare
      • OSDE
  • 30. Boot Camps
    • San Francisco 2009 (40+ attendees)
      • Sponsored by Third Pillar
      • 31. Sun, FAMC, OSDE, Kaseya, Fedex, TU Group, Intermountain Healthcare, Gap, Sony Pictures, Lockheed Martin, Kaiser, HP, Wells Fargo, US Navy Research, FOLIOfn, Boeing .....
    • San Diego 2010 (80+ attendess)
      • Sponsored by US Navy
      • 32. 5 day event, with 2 days focus on the healthcare industry
      • 33. OSDE, AT&T, SAIC, US Navy Research, Kaiser, Clinica, Intermountain Healthcare, GE Healthcare, VA, Boeing, Nationwide ....
  • 34. Communication
    • User and Dev mailing lists
    • 35. IRC, Internet Relay Chat
  • 36. History
  • 37. It All Started Here Birth of CDSS 1970s 1980s Dendral Baobab Mycin Guidon Neomycin Teiresias Puff Emycin WM Sacon Centaur Wheeze Gravida Clot Oncocin
  • 38. Because Not Everyone Is As Smart As He Is
  • 39. Business Rules Engines 1980s 2010s 1990s 2000s OPS5 ART Clips Jess Drools 2 JRules Drools 3 Drools 4 Drools 5
  • 40. Drools History
    • Drools 2
      • Rete “like” XML Scripting language
    • Drools 3
      • Based on Clips functionality
      • 41. Iterative improves to JRules syntax with Clips functionality
    • Drools 4
      • More declarative
      • 42. Basic functional programming feature with “from”
      • 43. Basic Rule Flow
      • 44. Basic BRMS
    • Drools 5
      • Improved functional programming with 'accumulate'
      • 45. More Advanced Rule Flow integration
      • 46. Complex Event Process (Fusion)
        • Temporal Comparators, Sliding Time Windows
      • Production ready BRMS
  • 47. Unified Concept
  • 48. Drools Modules (Also Now Drools Planner)
  • 49. Business Logic Lifecycle
  • 50. Rules and processes loosely coupled tightly coupled specific generic Decision Services Process Rules SCOPE COUPLING ?
  • 51. Achieving More By Doing Less
  • 52. jBPM File file = new File (“.....”); // file to XML process definition ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( IoUtils.FileToString( file ) ); ProcessInstance processInstance = new ProcessInstance(processDefinition); Jess Rete engine = new Rete(); FileReader file = new FileReader("myfile.clp"); Jesp parser = new Jesp(file, engine); parser.parse(false); Esper EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(); EPStatement countStmt = admin.createEPL( "...." ); countStmt.start(); Knowledge API
  • 53. Drools Flow KnowledegBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBulider(); kbuilder.addResource( ResourceFactory.newClassPathResource( “myflow.bpmn2”, ResourceType.BPMN2 ); If ( kbuilder.hasErrors() ) { log.error( kbuilder.hasErrors().toString() ); } KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addKnowledgePackages( kbase.getKnowledgePackages() ); Knowledge API
  • 54. Drools Expert KnowledegBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBulider(); kbuilder.addResource( ResourceFactory.newClassPathResource( “myrules.drl”, ResourceType.DRL ); If ( kbuilder.hasErrors() ) { log.error( kbuilder.hasErrors().toString() ); } KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addKnowledgePackages( kbase.getKnowledgePackages() ); Knowledge API
  • 55. Drools Integration Deployment Descriptors <change-set> <add> <resource source='classpath:myapp/data/myflow.bpmn2' type='BPMN2' /> <resource source='http:myapp/data/myrules.drl' type='DRL' /> <resource source='classpath:data/IntegrationExampleTest. xls ' type=&quot;DTABLE&quot;> <decisiontable- conf input-type=&quot;XLS&quot; worksheet-name=&quot;Tables_2&quot; /> </resource> <add> </change-set> KnowledegBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBulider(); kbuilder.addResource( ResourceFactory.newFileResource( “changeset.xml”, ResourceType.ChangeSet ); Knowledge XML
  • 56. <drools:kbase id=&quot;kbase1&quot;> <drools:resource type=&quot;DRL&quot; source=&quot;classpath:.../testSpring.drl&quot; /> </drools:kbase> <drools:ksession id=&quot;ksession1&quot; type=&quot; stateless &quot; kbase =&quot;kbase1&quot; /> <drools:ksession id=&quot;ksession2&quot; type=&quot; stateful &quot; kbase =&quot;kbase1&quot;/> <camelContext id=&quot;camel&quot;> <route> <from uri=&quot;cxfrs://bean://rsServer&quot;/> <marshal ref=&quot;xstream&quot;/> <to uri=”drools:ksession1” /> <unmarshal ref=&quot;xstream&quot;/> </route> </camelContext> Declarative Services Spring XML and Camel
  • 57. Stateful Knowledge Session
  • 58. Knowledge Runtime
  • 59.  
  • 60. Integrated debug and audit
  • 61. Self monitoring and adaptive declare ProcessStartedEvent @role( event ) end rule &quot;Number of process instances above threshold&quot; when Number( nbProcesses : intValue > 1000 ) from accumulate( e: ProcessStartedEvent( processInstance.processId == &quot;com.sample.order.OrderProcess&quot; ) over window:size(1h), count(e) ) then System.err.println( &quot;WARNING: Nb of order processes in the last hour > 1000: &quot; + nbProcesses ); end
  • 62. Rules and Process Together
  • 63. Domain Specific Processes
  • 64. Declarative Domain Overview
  • 65. Declarative Programming
    • Production Rule Systems PRD (forward chaining)
      • Reactive
      • 66. when Alarm( status == “alert” ) then send( “warning” )
    • Logic Programming LP (backward chaining)
      • Query
      • 67. descendant( “mary”, “jane”)
    • Functional Programming FP
      • Map,Fold, Filter
      • 68. avg([12, 16, 4, 6])
        • Returns single value 9.5
      • round([10.3, 4.7, 7.8] )
        • Returns List [10, 5, 8]
    • Description Logic
      • Person hasName String and livesAt Address
  • 69. Declarative Programming
    • Production Rule Systems PRD (forward chaining FC)
      • Drools 5.0, OPSJ ( hyrbid BC), ART( hyrbid BC)
    • Logic Programming LP (backward chaining BC)
      • target : Prolog (POSL Position Slotted Language)
      • 70. Drools Trunk has a prototype Prolog like query backward chaining capabilities. Stronger Polog like capabilities planned.
      • 71. Opportunistic BC planned.
    • Functional Programming FP
      • Lisp, Haskell
      • 72. Drools 5.0 has some functional capabilities
      • 73. Drools 5.1, 5.2 will be looking to have strong functional capabilities
  • 74. Declarative Programming
    • Description Logic DL
      • KIF, OWL-DL
      • 75. Planned, See “The Future”
    • Processes
      • Drools 5.1 implements BPMN2 with advanced rule integration.
      • 76. Drools Flow will be incorporated into jBPM5
  • 77. Domain Overview
  • 78. Domain Overview
  • 79. Domain Overview
  • 80. The Future
    • Full Hybrid Engine
      • http://community.jboss.org/wiki/DroolsLanguageEnhancements
    • Nested Objects
    • 81. Casting Nested Objects
    • 82. Positional Constraints
    • 83. POSL - Positional-Slotted Language
    • 84. Method Calls
    • 85. Maps and Arrays (Collections)
    • 86. Collections and XPath like filtering
    • 87. Free form Expressions
    • 88. Managed Object Graphs (MOGS)
    • 89. Nested Patterns and Queries
    • 90. Queries and Unification
    • 91. Ontologies and Relations via
    • 92. Query Based Backward Chaining with POSL
    • Triples with Hybrid POJO Graph Notation.
    • 93. Escapes for Dialects
    • 94. Accumulate Improvements to Support Haskell map/fold/filter and MVEL projection/fold
    • 95. Otherwise
    • 96. Branch (Labelled Else)
    • 97. Rule Execution Groups
    • 98. Rule Dependency Meta-Rule Language
    • 99. Parallel Meta-Rule Language
    • 100. Field Versioning
    • 101. Logical Closures/OnFalse
    • 102. Opportunistic Backward Chaining, Lazy Field/Object Values
    • 103. ...
  • 104. Drools Expert Quick Example Stateless
  • 105. Definitions public class Applicant { private String name; private int age; private boolean valid; // getter and setter methods here } rule &quot;Is of valid age&quot; when $a : Applicant( age < 18 ) then modify ( $a ) { valid = false }; ends
  • 106. Building KnowledgeBuilder kbuilder = KnowledgeBuilderFactory .newKnowledgeBuilder(); kbuilder .add( ResourceFactory .newClassPathResource( &quot;licenseApplication.drl&quot; , getClass() ), ResourceType.DRL ); if ( kbuilder .hasErrors() ) { System.err.println( kbuilder .getErrors().toString() ); } kbase .addKnowledgePackages( kbuilder .getKnowledgePackages() );
  • 107. Executing StatelessKnowledgeSession ksession = kbase .newStatelessKnowledgeSession(); Applicant applicant = new Applicant ( &quot;Mr John Smith&quot; , 16 ); assertTrue ( applicant .isValid() ); ksession .execute( applicant ); assertFalse ( applicant .isValid() ); rule &quot;Is of valid age&quot; when $a : Applicant( age < 18 ) then modify ( $a ) { valid = false }; ends
  • 108. Drools Expert Quick Example Stateful
  • 109. Definitions public class Room { private String name // getter and setter methods here } public class Sprinkler { private Room room ; private boolean on ; // getter and setter methods here } public class Fire { private Room room ; // getter and setter methods here } public class Alarm { }
  • 110. Definitions rule &quot;When there is a fire turn on the sprinkler&quot; when Fire ($room : room) $sprinkler : Sprinkler ( room == $room, on == false ) then modify ( $sprinkler ) { on = true }; println ( &quot;Turn on the sprinkler for room &quot; + $room.name ); end rule &quot;When the fire is gone turn off the sprinkler&quot; when $room : Room ( ) $sprinkler : Sprinkler ( room == $room, on == true ) not Fire ( room == $room ) then modify ( $sprinkler ) { on = false }; println ( &quot;Turn off the sprinkler for room &quot; + $room.name ); end
  • 111. Definitions rule &quot;Raise the alarm when we have one or more fires&quot; when exists Fire () then insert ( new Alarm () ); println ( &quot;Raise the alarm&quot; ); end rule &quot;Cancel the alarm when all the fires have gone&quot; when not Fire () $alarm : Alarm () then retract ( $alarm ); println ( &quot;Cancel the alarm&quot; ); end
  • 112. Definitions rule &quot;Status output when things are ok&quot; when not Alarm () not Sprinkler ( on == true ) then println ( &quot;Everything is ok&quot; ); end
  • 113. Executing String [] names = new String []{ &quot;kitchen&quot; , &quot;bedroom&quot; , &quot;office&quot; , &quot;livingroom&quot; }; Map < String , Room > name2room = new HashMap < String , Room >(); for ( String name : names ){ Room room = new Room ( name ); name2room .put( name , room ); ksession .insert( room ); Sprinkler sprinkler = new Sprinkler ( room ); ksession .insert( sprinkler ); } ksession .fireAllRules() > Everything is ok
  • 114. Executing Fire kitchenFire = new Fire ( name2room.get( &quot;kitchen&quot; ) ); Fire officeFire = new Fire ( name2room.get( &quot;office&quot; ) ); FactHandle kitchenFireHandle = ksession .insert( kitchenFire ); FactHandle officeFireHandle = ksession .insert( officeFire ); ksession .fireAllRules(); > Raise the alarm > Turn on the sprinkler for room kitchen > Turn on the sprinkler for room office
  • 115. Executing ksession .retract( kitchenFireHandle ); ksession .retract( officeFireHandle ); ksession .fireAllRules() > Turn off the sprinkler for room office > Turn off the sprinkler for room kitchen > Cancel the alarm > Everything is ok rule &quot;Status output when things are ok&quot; when not Alarm () not Sprinkler ( on == true ) then println ( &quot;Everything is ok&quot; ); end
  • 116. Conditional Elements
  • 117. not Bus( color = “red” ) Conditional Elements exists Bus( color = “red” ) forall ( $bus : Bus( floors == 2 ) Bus( this == $bus, color == “red” ) ) forall ( $bus : Bus( color == “red” ) )
  • 118. Accumulate CE rule &quot;accumulate&quot; when $sum : Number( intValue > 100 ) from accumulate ( Bus( color == &quot;red&quot; , $t : takings ) sum( $t ) ) then print &quot;sum is “ + $sum; end
  • 119. Accumulate CE Patterns and CE's can be chained with ' from ' rule &quot;collect&quot; when $zipCode : ZipCode() $sum : Number( intValue > 100 ) from accumulate ( Bus( color == &quot;red&quot; , $t : takings ) from $hbn.getNamedQuery( “Find Buses” ) .setParameters( [ “zipCode” : $zipCode ] ) .list(), sum( $t ) ) then print &quot;sum is “ + $sum; end
  • 120. Timers Calendars
  • 121. Timers rule “name” timer 1m30s when $l : Light( status == “on” ) then modify ( $l ) { status = “off” }; rule “name” timer (int: 1m30s 0) when $l : Light( status == “on” ) then modify ( $l ) { status = “off” }; When the light is on, and has been on for 1m30s then turn it off Same as above. Interval timer with JDK semantics for initial duration, then repeat duration.
  • 122. Timers rule “name” timer ( cron: 0 0/15 * * * * ) when Alarm( ) then sendEmail( ”Alert Alert Alert!!!” ) Field Name Mandatory? Allowed Values Allowed Special Characters Seconds YES 0-59 , - * / Minutes YES 0-59 , - * / Hours YES 0-23 , - * / Day of month YES 1-31 , - * ? / L W Month YES 1-12 or JAN-DEC , - * / Day of week YES 1-7 or SUN-SAT , - * ? / L # Year NO empty, 1970-2099 , - * / Send alert every quarter of an hour
  • 123. Calendars rule &quot;weekdays are high priority&quot; calendars &quot;weekday&quot; timer (int:0 1h) when Alarm() then send( &quot;priority high - we have an alarm” ); end rule &quot;weekend are low priority&quot; calendars &quot;weekend&quot; timer (int:0 4h) when Alarm() then send( &quot;priority low - we have an alarm” ); end Execute now and after 1 hour duration Execute now and after 4 hour duration
  • 124. Drools Expert A Little Deeper
  • 125. Classes
  • 126. increase balance for AccountPeriod Credits select * from Account acc, Cashflow cf, AccountPeriod ap where acc.accountNo == cf.accountNo and cf.type == CREDIT cf.date >= ap.start and cf.date <= ap.end decrease balance for AccountPeriod Debits select * from Account acc, Cashflow cf, AccountPeriod ap where acc.accountNo == cf.accountNo and cf.type == DEBIT cf.date >= ap.start and cf.date <= ap.end trigger : acc.balance += cf.amount trigger : acc.balance -= cf.amount Creating Views with Triggers
  • 127. rule “increase balance for AccountPeriod Credits” when ap : AccountPeriod() acc : Account( $accountNo : accountNo ) CashFlow( type == CREDIT, accountNo == $accountNo, date >= ap.start && <= ap.end, $ammount : ammount ) then acc.balance += $amount; end select * from Account acc, Cashflow cf, AccountPeriod ap where acc.accountNo == cf.accountNo and cf.type == CREDIT cf.date >= ap.start and cf.date <= ap.end trigger : acc.balance += cf.amount Bringing it Together
  • 128. rule “increase balance for AccountPeriod Credits” when ap : AccountPeriod() acc : Account( $accountNo : accountNo ) CashFlow( type == CREDIT, accountNo == $accountNo, date >= ap.start && <= ap.end, $ammount : ammount ) then acc.balance += $amount; end rule “decrease balance for AccountPeriod Debits” when ap : AccountPeriod() acc : Account( $accountNo : accountNo ) CashFlow( type == DEBIT, accountNo == $accountNo, date >= ap.start && <= ap.end, $ammount : ammount ) then acc.balance -= $amount; end Rules as a “view”
  • 129. Truth Maintenance Inference
  • 130. TMS and Inference rule &quot;Issue Child Bus Pass&quot; when $p : Person ( age < 16 ) then insert(new ChildBusPass ( $p ) ); end rule &quot;Issue Adult Bus Pass&quot; when $p : Person ( age >= 16 ) then insert(new AdultBusPass ( $p ) ); end Couples the logic What happens when the Child stops being 16?
  • 131. TMS and Inference
    • Bad
      • Monolithic
      • 132. Leaky
      • 133. Brittle integrity - manual maintenance
  • 134. TMS and Inference
    • A rule “logically” inserts an object
    • 135. When the rule is no longer true, the object is retracted.
    when $p : Person ( age < 16 ) then logicalInsert ( new IsChild ( $p ) ) end when $p : Person ( age >= 16 ) then logicalInsert ( new IsAdult ( $p ) ) end de-couples the logic Maintains the truth by automatically retracting
  • 136. TMS and Inference rule &quot;Issue Child Bus Pass&quot; when $p : Person ( ) IsChild ( person =$p ) then logicalInsert ( new ChildBusPass ( $p ) ); end rule &quot;Issue Adult Bus Pass&quot; when $p : Person ( age >= 16 ) IsAdult ( person =$p ) then logicalInsert ( new AdultBusPass ( $p ) ); end The truth maintenance cascades
  • 137. TMS and Inference rule &quot;Issue Child Bus Pass&quot; when $p : Person ( ) not ( ChildBusPass ( person == $p ) ) then requestChildBusPass( $p ); end The truth maintenance cascades
  • 138. TMS and Inference
    • Good
      • De-couple knowledge responsibilities
      • 139. Encapsulate knowledge
      • 140. Provide semantic abstractions for those encapsulation
      • 141. Integrity robustness – truth maintenance
  • 142. Drools Expert Authoring Metaphores
  • 143. Guided Editor
  • 144. Decision Table
  • 145. Decision Table rule &quot;Pricing bracket_10&quot; when Driver(age >= 18, age <= 24, locationRiskProfile == &quot;LOW&quot;, priorClaims == &quot;1&quot;) policy: Policy(type == &quot;COMPREHENSIVE&quot;) then policy.setBasePrice(450); end
  • 146. Fusion
  • 147. Drools Fusion: Enables...
    • Event Detection:
      • From an event cloud or set of streams, select all the meaningful events, and only them.
    • [Temporal] Event Correlation:
      • Ability to correlate events and facts declaring both temporal and non-temporal constraints between them.
      • 148. Ability to reason over event aggregation.
    • Event Sequencing:
      • A -> ( B OR C ) -> D
    • Event Abstraction:
      • Ability to compose complex events from atomic events AND reason over them
  • 149. Drools Fusion: Features
    • Support to Event semantics:
      • Usually immutable, but not enforced
      • 150. Strong temporal relationships
      • 151. Managed lifecycle
      • 152. Point-in-time and Interval events
    • Time semantics
      • Discrete
    • Temporal relationships
      • All 13 operators defined by James Allen (+ negations)
  • 153. Drools Fusion: Temporal Reasoning
  • 154. Drools Fusion: Temporal Reasoning
  • 155. $c : Custumer( type == “VIP ) $oe : BuyOrderEvent( customer == $c ) from entry-point “Home Broker Stream” not BuyAckEvent( relatedEvent == $oe.id, this after[1s, 10s] $oe ) from entry-point “Stock Trader Stream” Operators Existing Drools 'not' Conditional Elements can be used to detect non-occurrence of events BackAckEvent must occur between 1s and 10s ' after' BuyOrderEvent
  • 156. Aggregations Rule Engines do not deal with aggregations $n : Number( intValue > 100 ) from accumulate ( $s : StockTicker( symbol == “RHAT” ) over window:time ( 5s ), average ( $s.price ) ) Over 5 seconds Aggregate ticker price for RHAT over last 5 seconds The pattern 'Number' reasons 'from' the accumulate result
  • 157. Drools Guvnor
  • 158. Guvnor
    • Technology
      • JCR (JSR-170) backend
      • 159. Seam + GWT frontend
      • 160. WebDav
      • 161. Eclipse synchronisation plugin
      • 162. Role based security
    • Authoring
    • QA
      • Scenario Testing
      • 167. Rule Verification
  • 168. Business asset storage
  • 169. Category based browsing
  • 170. Category based browsing
  • 171. Guided Editor
  • 172. Decision Tables
  • 173. Scenario Testing
  • 174. Scenario Testing
  • 175. What's new In 5.1
  • 176. What's new to 5.1
    • Integration
    • Expert
      • New Rete Algorithm “differential update”
      • 180. Timers and Calendars
      • 181. Live Open Querries
    • Flow
      • BPMN2
  • 182. Differential Update
    • Differential Update (a.k.a. “true modify”)
      • Implements a real “modify/update” operation, instead of retract+assert.
        • Reuses tuples, reduces GC stress, improves performance
  • 183. What's new to 5.1
    • Guvnor
      • Guided editor
        • Nested Expression builder
          • person.dogs[0].name
        • Move constrains up and down
        • 184. Insert constraints
        • 185. Support for more DRL elements
      • RSS Subcription, change notifications, inbox
      • 186. Working Sets
      • 187. Object constraint definitions
      • 188. Rule Templates (based on Guided Editor)
      • 189. Oryx BPM editor integration
      • 190. Better rule documentation support
  • 191. Drools flow in Oryx
  • 192. Drools flow in Eclipse
  • 193. Questions? Questions?
    • Dave Bowman : All right, HAL; I'll go in through the emergency airlock.
    • 194. HAL : Without your space helmet, Dave, you're going to find that rather difficult.
    • 195. Dave Bowman : HAL, I won't argue with you anymore! Open the doors!
    • 196. HAL : Dave, this conversation can serve no purpose anymore. Goodbye.
    Joshua: Greetings, Professor Falken. Stephen Falken : Hello, Joshua. Joshua: A strange game. The only winning move is not to play. How about a nice game of chess?