Successfully reported this slideshow.

JUDCon India 2012 Drools Expert

1

Share

Loading in …3
×
1 of 68
1 of 68

More Related Content

Related Books

Free with a 14 day trial from Scribd

See all

Related Audiobooks

Free with a 14 day trial from Scribd

See all

JUDCon India 2012 Drools Expert

  1. 1. 1 Mark Proctor Project Lead The SkyNet funding bill is passed. The system goes online on August 4th, 1997. Human decisions are removed from strategic defense. SkyNet begins to learn at a geometric rate. It becomes self-aware at 2:14am Eastern time, August 29th In a panic, they try to pull the plug. And, Skynet fights back
  2. 2. 2 Wumpus World
  3. 3. 3 Wumpus World
  4. 4. 4 Wumpus World C e ll H e ro Wu m p u s P itt G old int row int row int row int row int row Int col Int col Int col Int col Int col
  5. 5. 5 Wumpus World
  6. 6. 6 Wumpus World
  7. 7. 7 Wumpus World d e m ons tration
  8. 8. 8 Drools B ooks
  9. 9. 9 S ample Indus tries and Us ers Inve s tm e nt Mille nniu m Inve s tm e nt G rou p (M IG ) Logis tics Fed ex Airline S ab re M ortgage F ranklin Am e rican H e alth care OSDE
  10. 10. 10 B oot C amps S an F rancis co 2009 (40+ atte nd e e s ) S p ons ore d b y Th ird P illar S u n, F AM C , O S D E , Kas e ya, F e d e x, TU G rou p , Inte rm ou ntain H e alth care , G ap , S ony P ictu re s , Lockh e e d Martin, Kais e r, H P , We lls F argo, U S N avy R e s e arch , F O LIO fn, Boe ing ..... S an D ie go 201 0 (80+ atte nd e s s ) S p ons ore d b y U S N avy 5 d ay e ve nt, with 2 d ays focu s on th e h e alth care ind u s try O S D E , AT&T, S AIC , U S N avy R e s e arch , Kais e r, C linica, Inte rm ou ntain H e alth care , G E H e alth care , VA, Boe ing, N ationwid e ....
  11. 11. 11 Integrated S ys tems Rules Rules Workflows Workflows Event Processes Semantic Ontologies Semantic Event Ontologies Processes
  12. 12. 12 generic Rules and proces s es ? Decision Services SCOPE Process specific Rules tightly coupled COUPLING loosely coupled
  13. 13. 13 Integrated S ys tems Drools JBPM5 Drools Drools Expert (Drools Flow) Fusion Guvnor Drools Drools Drools Drools Planner Grid Semantics Chance Business Logic integration System
  14. 14. 14 Declarative Programming P rod u ction R u le S ys te m s P R D (forward ch aining) R e active wh e n Alarm ( s tatu s = = “ale rt” ) th e n s e nd ( “warning” ) Logic P rogram m ing LP (b ackward ch aining) Q u e ry d e s ce nd ant( “m ary”, “j ”) ane F u nctional P rogram m ing F P Map ,F old , F ilte r avg([1 2, 1 6, 4, 6]) R e tu rns s ingle valu e 9.5 rou nd ([1 0.3, 4.7, 7.8] ) R e tu rns Lis t [1 0, 5, 8] D e s crip tion Logic P e rs on H as N am e and
  15. 15. 15 C las s es C a s h f lo w A cco u n t D a te d a te lo n g a c c o u n t N o d o u b le a m o u n t d o u b le b a la n c e in t t y p e lo n g a c c o u n t N o A c c o u n t in g P e r io d D a te s ta r t D a te e n d
  16. 16. 16 C redit C as hflow Rule 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 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
  17. 17. 17 Rules as a “ view” CashFlow AccountingPeriod date amount type accountNo start end 12-Jan-07 100 CREDIT 1 01-Jan-07 31-Mar-07 2-Feb-07 200 DEBIT 1 18-May-07 50 CREDIT 1 Account 9-Mar-07 75 CREDIT 1 accountNo balance 1 0 rule “increase balance for AccountPeriod rule “decrease balance for AccountPeriod Credits” Debits” when when ap : AccountPeriod() ap : AccountPeriod() acc : Account( $accountNo : accountNo ) acc : Account( $accountNo : accountNo ) CashFlow( type == CREDIT, CashFlow( type == DEBIT, accountNo == $accountNo, accountNo == $accountNo, date >= ap.start && <= ap.end, date >= ap.start && <= ap.end, $ammount : ammount ) $ammount : ammount ) then then acc.balance += $amount; acc.balance -= $amount; end CashFlow end CashFlow date amount type date amount type 12-Jan-07 100 CREDIT 2-Feb-07 200 DEBIT 9-Mar-07 75 CREDIT Account accountNo balance 1 -25
  18. 18. 18 Definitions p u b lic clas s Ap p licant { p rivate S tring nam e ; p rivate int age ; p rivate b oole an valid ; / ge tte r and s e tte r m e th od s h e re / } rule "Is of valid age" when $a : Applicant( age < 18 ) then modify( $a ) { valid = false }; ends
  19. 19. 19 B uilding Knowle d ge Bu ild e r kb u ild e r = Knowle d ge Bu ild e rF actory.ne wK nowle d ge Bu ild e r(); kb u ild e r.ad d ( R e s ou rce F actory .ne wC las s P ath R e s ou rce ( "lice ns e Ap p lication.d rl", ge tC las s () ), R e s ou rce Typ e .D R L ); if ( kb u ild e r.h as E rrors () ) { S ys te m .e rr.p rintln( kb u ild e r.ge tE rrors ().toS tring() ); } kb as e .ad d K nowle d ge P ackage s ( kb u ild e r.ge tKnowle d ge P ackage s () );
  20. 20. 20 S pring C onfiguration
  21. 21. 21 E xecuting rule "Is of valid age" when $a : Applicant( age < 18 ) then modify( $a ) { valid = false }; ends S tate le s s K nowle d ge S e s s ion ks e s s ion = kb as e .ne wS tate le s s Knowle d ge S e s s ion(); Ap p licant ap p licant = ne w Ap p licant( "M r Joh n S m ith ", 1 6 ); as s e rtTru e ( ap p licant.is Valid () ); ks e s s ion.e xe cu te ( ap p licant ); as s e rtF als e ( ap p licant.is Valid () );
  22. 22. 22 Definitions p u b lic clas s R oom { p rivate S tring nam e / ge tte r and s e tte r m e th od s h e re / } p u b lic clas s S p rinkle r { p rivate R oom room ; p rivate b oole an on; / ge tte r and s e tte r m e th od s h e re / } p u b lic clas s F ire { p rivate R oom room ; / ge tte r and s e tte r m e th od s h e re / } p u b lic clas s Alarm {
  23. 23. 23 Definitions ru le "Wh e n th e re is a fire tu rn on th e s p rinkle r" wh e n F ire ($room : room ) $s p rinkle r : S p rinkle r( room = = $room , on = = fals e ) th e n m od ify( $s p rinkle r ) { on = tru e }; p rintln( "Tu rn on th e s p rinkle r for room " + $room .nam e ); e nd ru le "Wh e n th e fire is gone tu rn off th e s p rinkle r" wh e n $room : R oom ( ) $s p rinkle r : S p rinkle r( room = = $room , on = = tru e ) not F ire ( room = = $room ) th e n m od ify( $s p rinkle r ) { on = fals e }; p rintln( "Tu rn off th e s p rinkle r for room " + $room .nam e );
  24. 24. 24 Definitions ru le "R ais e th e alarm wh e n we h ave one or m ore fire s " wh e n e xis ts F ire () th e n ins e rt( ne w Alarm () ); p rintln( "R ais e th e alarm " ); e nd ru le "C ance l th e alarm wh e n all th e fire s h ave gone " wh e n not F ire () $alarm : Alarm () th e n re tract( $alarm ); p rintln( "C ance l th e alarm " ); e nd
  25. 25. 25 Definitions ru le "S tatu s ou tp u t wh e n th ings are ok" wh e n not Alarm () not S p rinkle r( on = = tru e ) th e n p rintln( "E ve ryth ing is ok" ); e nd
  26. 26. 26 E xecuting S tring[] nam e s = ne w S tring[]{"kitch e n", "b e d room ", "office ", "livingroom "}; M ap < S tring,R oom > nam e 2room = ne w H as h M ap < S tring,R oom > (); for( S tring nam e : nam e s ){ R oom room = ne w R oom ( nam e ); nam e 2room .p u t( nam e , room ); ks e s s ion.ins e rt( room ); S p rinkle r s p rinkle r = ne w S p rinkle r( room ); ks e s s ion.ins e rt( s p rinkle r ); } ks e s s ion.fire AllR u le s () > E ve ryth ing is ok
  27. 27. 27 E xecuting F ire kitch e nF ire = ne w F ire ( nam e 2room .ge t( "kitch e n" ) ); F ire office F ire = ne w F ire ( nam e 2room .ge t( "office " ) ); F actH and le kitch e nF ire H and le = ks e s s ion.ins e rt( kitch e nF ire ); F actH and le office F ire H and le = ks e s s ion.ins e rt( office F ire ); ks e s s ion.fire AllR u le s (); > R ais e th e alarm > Tu rn on th e s p rinkle r for room kitch e n > Tu rn on th e s p rinkle r for room office
  28. 28. 28 E xecuting ks e s s ion.re tract( kitch e nF ire H and le ); ks e s s ion.re tract( office F ire H and le ); ks e s s ion.fire AllR u le s () > Tu rn off th e s p rinkle r for room office > Tu rn off th e s p rinkle r for room kitch e n > C ance l th e alarm > E ve ryth ing is ok ru le "S tatu s ou tp u t wh e n th ings are ok" wh e n not Alarm () not S p rinkle r( on = = tru e ) th e n p rintln( "E ve ryth ing is ok" );
  29. 29. 29 C onditional E lements not Bus( color = “red” ) exists Bus( color = “red” ) forall ( $bus : Bus( color == “red” ) ) forall ( $bus : Bus( floors == 2 ) Bus( this == $bus, color == “red” ) )
  30. 30. 30 A ccumulate C E ru le "accu m u late " wh e n $s u m : N u m b e r( intValu e > 1 00 ) from accu m u late ( Bu s ( color = = "re d ", $t : takings ) s u m ( $t ) ) th e n p rint "s u m is “ + $s u m ; e nd
  31. 31. 31 Decis ion Table
  32. 32. 32 Decis ion Table rule "Pricing bracket_10" when Driver(age >= 18, age <= 24, locationRiskProfile == "LOW", priorClaims == "1") policy: Policy(type == "COMPREHENSIVE") then policy.setBasePrice(450);
  33. 33. 33 Types Types Layou t H orizontal Ve rtical Lim ite d e ntry E xte nd e d e ntry C ate goris ation E xp and e d form , contracte d form M u lti-h it, all h its M u lti-h it, firs t h it S ingle h it
  34. 34. 34 Layouts Horizontal
  35. 35. 35 Layouts Vertical
  36. 36. 36 Layouts Limited entry
  37. 37. 37 Layouts E xtended entry
  38. 38. 38 C ategoris ation E xpanded form S ingle colu m n for e ve ry cond ition com b ination Th e nu m b e r of colu m ns s h ou ld e qu al th e p rod u ct of th e nu m b e r of s tate s for e ve ry cond ition. e .g. 2 cond itions , one with 3 s tate s th e oth e r 4 (s e e ab ove ): 3 * 4 = 1 2 com b inations e .g. 2 cond itions e ach with 3 s tate s and 1 cond ition with 4 s tate s give s : 3 * 3 * 4 = 36 com b inations
  39. 39. 39 C ategoris ation E xpanded form (continued)
  40. 40. 40 C ategoris ation C ontracted form C ontraction is th e firs t op tim is ation. R e d u ce s th e nu m b e r of cond ition colu m ns . R e m ove s im p os s ib le com b inations If th e s am e actions e xis t for ru le s cove ring all cond ition s tate s for a give n cond ition th e y can b e com b ine d and th e cond ition s tate b e com e s irre le vant.
  41. 41. 41 C ategoris ation C ontracted form – s tage 1 R u le s 2 and 3 are im p os s ib le cond itions
  42. 42. 42 C ategoris ation C ontracted form – s tage 2 M e rge ad j nt colu m n grou p s with id e ntical action p arts ace
  43. 43. 43 C ategoris ation Multi-hit, all hits To ge t com p le te re s u lt all ru le s m atch ing ne e d to h ave th e ir actions e xe cu te d . C ond ition colu m ns are not m u tu ally e xclu s ive If th e C ond ition colu m ns are not e xclu s ive , s om e com b ination of cond itions are p re s e nt in m ore th an one colu m n, wh ich m ay le ad to am b igu ity or incons is te ncy.
  44. 44. 44 C ategoris ation Multi-hit, all hits G ive n a 35 ye ar old with 1 5 ye ars s e rvice 1 . R u le 1 m atch e s , giving 22 d ays 2. R u le 5 m atch e s , giving an ad d itional 3 d ays 3. A total of 25 d ays is as s igne d
  45. 45. 45 C ategoris ation Multi-hit, firs t hit To ge t com p le te re s u lt th e firs t ru le (from le ft-to-righ t) m atch ing ne e d s to h ave its action e xe cu te d . C ond ition colu m ns are not m u tu ally e xclu s ive . If th e C ond ition colu m ns are not e xclu s ive , s om e com b ination of cond itions are p re s e nt in m ore th an one colu m n, wh ich m ay le ad to am b igu ity or incons is te ncy.
  46. 46. 46 C ategoris ation Multi-hit, firs t hit G ive n a 35 ye ar old with 1 5 ye ars s e rvice 1 . R u le 4 m atch e s , giving 25 d ays 2. R u le 6 wou ld m atch b u t R u le 4 was th e firs t h it
  47. 47. 47 C ategoris ation S ingle hit E ach p os s ib le com b ination of cond itions m atch e s e xactly one , and only one , ru le . C ond ition colu m ns are m u tu ally e xclu s ive As th e C ond ition colu m ns are e xclu s ive ; com b inations of cond itions cannot b e p re s e nt in m ore th an one colu m n wh ich e lim inate s am b igu ity and incons is te ncy. C las s ic form if S ingle -h it is "e xp and e d d e cis ion tab le "; b u t th is can b e op tim is e d or “contracte d ”.
  48. 48. 48 C ategoris ation S ingle hit G ive n a 35 ye ar old with 1 5 ye ars s e rvice 1 . R u le 3 m atch e s , giving 25 d ays 2. N o oth e r ru le s m atch
  49. 49. 49 Validation & Verification Redundancy - S ubs umption
  50. 50. 50 Validation & Verification Deficiency P re m iu m is £500 if ap p licant age is le s s th an 30 P re m iu m is £300 if Ye ars With ou t C laim is gre ate r th an or e qu al to 1 0 ye ars . Ap p licant is 29, p re m iu m is £500 Ap p licant h as 1 2 ye ars with ou t claim , p re m iu m is £300 Ap p licant is 29 with 1 2 ye ars with ou t claim , p re m iu m is ?!?
  51. 51. 51 Decis ion Tables in G uvnor Vid e o d e m ons tration
  52. 52. 52 Guided Editor
  53. 53. 53 Decision Table
  54. 54. 54 Decision Table
  55. 55. 55 Decision Table
  56. 56. 56 Decision Tables – Cell merging.. etc Cell Merging Cell Grouping Typed Columns Sorting by column Negate pattern Support for Ohterwise
  57. 57. 57 Decision Tables – Wizard
  58. 58. 58 Rule Templates
  59. 59. 59 Rule Templates
  60. 60. 60 Rule Templates
  61. 61. 61 Scenario Testing
  62. 62. 62 TMS and Inference ru le "Is s u e C h ild Bu s P as s " Couples the logic wh e n $p : P e rs on( age < 1 6 ) th e n ins e rt(ne w C h ild Bu s P as s ( $p ) ); e nd ru le "Is s u e Ad u lt Bu s P as s " What happens when the Child stops being 16? wh e n $p : P e rs on( age > = 1 6 ) th e n ins e rt(ne w Ad u ltBu s P as s ( $p ) ); e nd
  63. 63. 63 TMS and Inference Bad Monolith ic Le aky Brittle inte grity - m anu al m ainte nance
  64. 64. 64 TMS and Inference A ru le “logically” ins e rts an ob j ct e Wh e n th e ru le is no longe r tru e , th e ob j ct is re tracte d . e wh e n de-couples the logic $p : P e rs on( age < 1 6 ) th e n logicalIns e rt( ne w Is C h ild ( $p ) ) e nd wh e n Maintains the truth by automatically retracting $p : P e rs on( age > = 1 6 ) th e n logicalIns e rt( ne w Is Ad u lt( $p ) ) e nd
  65. 65. 65 TMS and Inference ru le "Is s u e C h ild Bu s P as s " wh e n $p : P e rs on( ) Is C h ild ( p e rs on = $p ) th e n logicalIns e rt(ne w C h ild Bu s P as s ( $p ) ); e nd The truth maintenance ru le "Is s u e Ad u lt Bu s P as s " cascades wh e n $p : P e rs on( age > = 1 6 ) Is Ad u lt( p e rs on = $p ) th e n logicalIns e rt(ne w Ad u ltBu s P as s ( $p ) ); e nd
  66. 66. 66 TMS and Inference ru le "Is s u e C h ild Bu s P as s " wh e n $p : P e rs on( ) not( C h ild Bu s P as s ( p e rs on = = $p ) ) th e n re qu e s tC h ild Bu s P as s ( $p ); The truth maintenance cascades e nd
  67. 67. 67 TMS and Inference G ood D e -cou p le knowle d ge re s p ons ib ilitie s E ncap s u late knowle d ge P rovid e s e m antic ab s tractions for th os e e ncap s u lation Inte grity rob u s tne s s – tru th m ainte nance
  68. 68. 68 Ques tions ? D ave Bowm an: All righ t, H AL; I'll go in th rou gh th e e m e rge ncy airlock. H AL: With ou t you r s p ace h e lm e t, D ave , you 're going to find th at rath e r d ifficu lt. D ave Bowm an: H AL, I won't argu e with you anym ore ! O p e n th e d oors ! H AL: D ave , th is conve rs ation can s e rve no p u rp os e anym ore . G ood b ye . essor Falken. oshua. . The only winning move is not to play. How about a nice game of chess

Editor's Notes

  • JBoss Enteprise BRMS (new in 2009) Enables critical business rules to be managed in a more centralized manner (e.g. Insurance = policy risk assess and pricing; Heathcare = claims processing annual regulatory changes) Avoids need to otherwise re-code business rules redundantly in multiple applications Leverages JBoss Rules execution engine which has been available for years Adds new browser-based Rules Mgmt app, enabling business users to participate in the review, editing, and maintenance of business rule changes Also adds Repository to provide version management of multiple sets of business rules Supports the deployment of business rules to JBoss middleware platforms and non-JBoss runtime environments
  • JBoss Enteprise BRMS (new in 2009) Enables critical business rules to be managed in a more centralized manner (e.g. Insurance = policy risk assess and pricing; Heathcare = claims processing annual regulatory changes) Avoids need to otherwise re-code business rules redundantly in multiple applications Leverages JBoss Rules execution engine which has been available for years Adds new browser-based Rules Mgmt app, enabling business users to participate in the review, editing, and maintenance of business rule changes Also adds Repository to provide version management of multiple sets of business rules Supports the deployment of business rules to JBoss middleware platforms and non-JBoss runtime environments
  • ×