• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Drools @ IntelliFest 2012
 

Drools @ IntelliFest 2012

on

  • 1,543 views

Drools presentation at IntelliFest Bootcamp 2012

Drools presentation at IntelliFest Bootcamp 2012

Statistics

Views

Total Views
1,543
Views on SlideShare
1,543
Embed Views
0

Actions

Likes
0
Downloads
44
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Drools @ IntelliFest 2012 Drools @ IntelliFest 2012 Presentation Transcript

    • 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, August29th● In a panic, they try to pull the plug.● And, Skynet fights back
    • 2Drools Books
    • 3Sample Industries and Users  Investment ● Millennium Investment Group (MIG)  Logistics ● Fedex  Airline ● Sabre  Mortgage ● Franklin American  Healthcare ● OSDE
    • 4Boot Camps  San Francisco 2009 (40+ attendees) ● Sponsored by Third Pillar ● 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 ● 5 day event, with 2 days focus on the healthcare industry ● OSDE, AT&T, SAIC, US Navy Research, Kaiser, Clinica, Intermountain Healthcare, GE Healthcare, VA, Boeing, Nationwide ....
    • 5Integrated Systems Rules Rules Workflows Workflows Event Processes Semantic Ontologies Semantic Event Ontologies Processes
    • 6Integrated Systems Drools JBPM5 Drools Drools Expert (Drools Flow) Fusion Guvnor Drools Drools Drools Drools Planner Grid Semantics Chance
    • 7Rules and processes generic ? Decision Services SCOPE Process specific Rules tightly coupled COUPLING loosely coupled
    • 8Some Areas of Artificial Intelligence Vision Robotics Natural Some Areas of Language Artificial Speech Intelligence Understanding Neural Nets Rule Base Systems/ Expert System Tools
    • 9Knowledge Representation and ReasoningThe study of Knowledge is Epistemology ● Nature Structure and Origins of Knowledge ● Core or AIRule based systems ● Expert System tools ● Knowledge Representation and Reasoning ● Facilitate the codification of knowledge into a knowledge base which can be used for reasoning
    • 10Knowledege Representation and Reasoning  Production Rule Systems PRD (forward chaining) ● Reactive ● when Alarm( status == “alert” ) then send( “warning” )  Logic Programming LP (backward chaining) ● Query ● descendant( “mary”, “jane”)  Functional Programming FP ● Map,Fold, Filter ● avg([12, 16, 4, 6]) ● Returns single value 9.5 ● round([10.3, 4.7, 7.8] ) ● Returns List [10, 5, 8]  Description Logic
    • 11Knowledege Representation and Reasoning  Description Logic ● Man ● Father ● is a Man ● has at least one child ● All Fathers have sunday off ● Individual == instance ● Adhoc ● Classes and properties added and inferred over time ● Does a Man with two children have sundays off?
    • 12 It All Started Here Birth of CDSS Dendral1970s Mycin WM Teiresias Emycin Baobab Puff Guidon Sacon Centaur Gravida Wheeze Clot1980s Neomycin Oncocin
    • 13Because Not EveryoneIs As Smart As He Is
    • 14And some day well build him!!!
    • 15Concepts Overview
    • 16Concepts Overview
    • 18 What is a Rule salience <int>Quotes on Rule names are agenda-group <string>optional if the rule name has no-loop <boolean>no spaces. auto-focus <boolean> duration <long> .... • rule “<name>” <attribute> <value> when <LHS> then <RHS> RHS can be any valid java. Or MVEL. Other languages end could be added.
    • 19 What is a Rule Methods that must specific passing of be called directly instances • public void helloMark(Person person) {Rules can never if ( person.getName().equals( “mark” ) {be called directly System.out.println( “Hello Mark” ); } Specific instances } cannot be passed. • rule “Hello Mark” LHS when Person( name == “mark” ) then System.out.println( “Hello Mark” ); end RHS
    • 20 What is a Pattern P a tte rn O b je c t T y p e F ie ld C o n s t r a in t F ie ld N a m e R e s t r ic t io n E v a lu a t o r V a lu eS h o w e r ( te m p e r a tu re = = “ h o t” )
    • 21 Classes C a s h f lo w A cco un t D a te d a telo n g a c c o u n t N o d o u b le a m o u n td 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
    • 22 Credit Cashflow 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.amountrule “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
    • 23 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 0rule “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
    • 24 Production Rule System Approximated by SQL and ViewsT a b le s A cco unt A c c o u n t in g P e r io d C a s h f lo w O b je c t T y p e s A cco unt A c c o u n t in g P e r io d C a s h f lo wV ie w s v ie w 1 v ie w 2V ie w m a in v ie w R u le s r u le 1 r u le 2 agenda agenda
    • 25 Two Phase System Determine possible rules to fire Agenda EvaluationWorking Memory Action Rule insert modify Found Select Fire Rule Rule to Fire retract No Rule Found exit
    • 26 Conflict Resolution with Salience Saliencerule “Print blance for AccountPeriod” salience -50 when ap : AccountPeriod() acc : Account( ) then System.out.println( acc.accountNo + “ : “ acc.balance );endAgenda 1 increase balance 2 decrease balance arbitrary 3 increase balance 4 print balance
    • 27RuleFlow rule “increase balance for AccountPeriod Credits” ruleflow-group “calculation” when ap : AccountPeriod() acc : Account( $accountNo : accountNo ) CashFlow( type == CREDIT, accountNo == $accountNo, date >= ap.start && <= ap.end, $ammount : ammount ) then acc.balance += $amount; end ruleflow-group rule “Print blance for AccountPeriod” ruleflow-group “report” when ap : AccountPeriod() acc : Account( ) then System.out.println( acc.accountNo + “ : “ acc.balance ); end
    • 28 Definitionspublic class Applicant { private String name; private int age; private boolean valid; // getter and setter methods here} rule "Is of valid age" when $a : Applicant( age < 18 ) then modify( $a ) { valid = false }; ends
    • 29 BuildingKnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();kbuilder.add( ResourceFactory .newClassPathResource( "licenseApplication.drl", getClass() ), ResourceType.DRL );if ( kbuilder.hasErrors() ) { System.err.println( kbuilder.getErrors().toString() );}kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
    • 30 Executingrule "Is of valid age" when $a : Applicant( age < 18 )then modify( $a ) { valid = false };endsStatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();Applicant applicant = new Applicant( "Mr John Smith", 16 );assertTrue( applicant.isValid() );ksession.execute( applicant );assertFalse( applicant.isValid() );
    • 31 Executingrule "Is of valid age" when $a : Applicant( age < 18 )then modify( $a ) { valid = false };endsStatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();Applicant applicant = new Applicant( "Mr John Smith", 16 );assertTrue( applicant.isValid() );ksession.execute( applicant );assertFalse( applicant.isValid() );
    • 32 Definitionspublic 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 {}
    • 33 Definitionsrule "When there is a fire turn on the sprinkler" when Fire($room : room) $sprinkler : Sprinkler( room == $room, on == false )then modify( $sprinkler ) { on = true }; println( "Turn on the sprinkler for room " + $room.name );endrule "When the fire is gone turn off the sprinkler" when $room : Room( ) $sprinkler : Sprinkler( room == $room, on == true ) not Fire( room == $room )then modify( $sprinkler ) { on = false }; println( "Turn off the sprinkler for room " + $room.name );end
    • 34 Definitionsrule "Raise the alarm when we have one or more fires" when exists Fire()then insert( new Alarm() ); println( "Raise the alarm" );endrule "Cancel the alarm when all the fires have gone" when not Fire() $alarm : Alarm()then retract( $alarm ); println( "Cancel the alarm" );end
    • 35 Definitionsrule "Status output when things are ok" when not Alarm() not Sprinkler( on == true )then println( "Everything is ok" );end
    • 36 ExecutingString[] names = new String[]{"kitchen", "bedroom", "office", "livingroom"};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
    • 37 ExecutingFire kitchenFire = new Fire( name2room.get( "kitchen" ) );Fire officeFire = new Fire( name2room.get( "office" ) );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
    • 38 Executingksession.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 okrule "Status output when things are ok" when not Alarm() not Sprinkler( on == true )then println( "Everything is ok" );end
    • 39 Conditional Elementsnot Bus( color = “red” )exists Bus( color = “red” )forall ( $bus : Bus( color == “red” ) )forall ( $bus : Bus( floors == 2 ) Bus( this == $bus, color == “red” ) )
    • 40Accumulate CE rule "accumulate" when accumulate( Bus( color == "red", $t : takings ); $sum : sum( $t ) ) then print "sum is “ + $sum; end accumulate( Bus( color == "red", $t : takings ); $sum : sum( $t ), $min : min( $t ) $max : max( $t ); $min > 100 && $max < 200 )
    • 41 TimersField Name Mandatory? Allowed Values Allowed Special CharactersSeconds YES 0-59 ,-*/Minutes YES 0-59 ,-*/Hours YES 0-23 ,-*/Day of month YES 1-31 ,-*?/LWMonth 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 hourrule “name” timer ( cron: 0 0/15 * * * * )when Alarm( )then sendEmail( ”Alert Alert Alert!!!” )
    • 42 Calendarsrule "weekdays are high priority" calendars "weekday" timer (int:0 1h) Execute now and after 1 hour durationwhen Alarm()then send( "priority high - we have an alarm” );endrule "weekend are low priority" calendars "weekend" timer (int:0 4h) Execute now and after 4 hour durationwhen Alarm()then send( "priority low - we have an alarm” );end
    • 43TMS and Inference rule "Issue Child Bus Pass" Couples the logic when $p : Person( age < 16 ) then insert(new ChildBusPass( $p ) ); end rule "Issue Adult Bus Pass" What happens when the Child when stops being 16? $p : Person( age >= 16 ) then insert(new AdultBusPass( $p ) ); end
    • 44TMS and Inference  Bad ● Monolithic ● Leaky ● Brittle integrity - manual maintenance
    • 45TMS and Inference  A rule “logically” inserts an object  When the rule is no longer true, the object is retracted. when $p : Person( age < 16 ) de-couples the logic then logicalInsert( new IsChild( $p ) ) end when Maintains the truth by $p : Person( age >= 16 ) automatically retracting then logicalInsert( new IsAdult( $p ) ) end
    • 46TMS and Inference rule "Issue Child Bus Pass" when $p : Person( ) IsChild( person =$p ) then logicalInsert(new ChildBusPass( $p ) ); end rule "Issue Adult Bus Pass" The truth maintenance cascades when $p : Person() IsAdult( person =$p ) then logicalInsert(new AdultBusPass( $p ) ); end
    • 47TMS and Inference rule "Issue Child Bus Pass" when $p : Person( ) not( ChildBusPass( person == $p ) ) then requestChildBusPass( $p ); end The truth maintenance cascades
    • 48TMS and Inference  Good ● De-couple knowledge responsibilities ● Encapsulate knowledge ● Provide semantic abstractions for those encapsulation ● Integrity robustness – truth maintenance
    • 49Backward Chaining query isChild( Person p ) $p := Person( age <= 16 ) end rule "Issue Child Bus Pass" when $p : Person( ) isChild( $p; ) then logicalInsert(new ChildBusPass( $p ) ); end
    • 50Reasoning with Graphs House ●Location( “office”,”house” ) ●Location( “kitchen”,”house” ) ●Location( “desk”,”office” ) ●Location( “chair”,”office” ) Location( “lamp”,”desk” ) ● ● Location( “computer”,”desk” ) ● Location( “draw”,”desk” ) Location( “key”,”draw” ) ●
    • 51Backward Chaining query isContainedIn( String x, String y ) Location( x, y; ) or ( Location( z, y; ) and ?isContainedIn( x, z; ) ) end
    • 52Backward Chainingquery isContainedIn( String x, String y ) Location( x, y; ) or ( Location( z, y; ) and ?isContainedIn( x, z; ) )end House ●Location( “office”,”house” ) Location( “kitchen”,”house” ) ● ●Location( “desk”,”office” ) ● Location( “chair”,”office” ) ●Location( “lamp”,”desk” ) ●Location( “computer”,”desk” ) ● Location( “draw”,”desk” ) Location( “key”,”draw” ) ●
    • 53 Questions? • Dave Bowman: All right, HAL; Ill go in through the emergency airlock. • HAL: Without your space helmet, Dave, youre going to find that rather difficult. • Dave Bowman: HAL, I wont argue with you anymore! Open the doors! • HAL: Dave, this conversation can serve no purpose anymore. Goodbye.Joshua: Greetings, Professor Falken.Stephen Falken: Hello, Joshua.Joshua: A strange game. The onlywinning move is not to play. Howabout a nice game of chess?