drools
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
Mark ProctorCo-CreatorProject Lead
Topics
Books
Community
History
Unified Concept
Declarative Domain OverviewDeclarative Programming
Domain Overview
The Future
ExpertQuick Example
Conditional Elements
Truth Maintenance and Inference
Fusion
Decision Tables
Guvnor
What's new in 5.1
Books
Introduction to Expert SystemsPeter Jackson
Expert Systems, Principles and ProgrammingJoseph C. Giarratano and Gary D. Riley
Oh And There are Drools Books Too
Community
Drools Research Network
http://www.jboss.org/drools/research-network.html30+ Research related pages
Many more as haven't updated
Community Collaboration
40% of Drools work now done in the communityUS Navy Healthcare
OSDE (Argentina's largest healthcare organisation)
Standards
Part of the W3C RIF working group
Director in RuleML group
Sample Industries and Users
InvestmentMillennium Investment Group (MIG)
LogisticsFedex
AirlineSabre
MortgageFranklin American
HealthcareOSDE
Boot 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 ....
Communication
User and Dev mailing lists
IRC, Internet Relay Chat
History
It All Started Here
Birth of CDSS
DendralBaobabMycinGuidonNeomycinTeiresiasPuffEmycinWMSaconCentaurWheezeGravidaClot
Oncocin
1970s
1980s
Because Not Everyone
Is As Smart As He Is
Business Rules Engines
OPS5ARTClipsJessDrools 2JRules
1980s
2010s
Drools 3
1990s
2000s
Drools 4Drools 5
Drools History
Drools 2Rete like XML Scripting language
Drools 3 Based on Clips functionality
Iterative improves to JRules syntax with Clips functionality
Drools 4More declarative
Basic functional programming feature with from
Basic Rule Flow
Basic BRMS
Drools 5Improved functional programming with 'accumulate'
More Advanced Rule Flow integration
Complex Event Process (Fusion)Temporal Comparators, Sliding Time Windows
Production ready BRMS
Unified Concept
Drools Modules
Business Logic integration System
Drools
Guvnor
Drools
Fusion
Drools
Flow
Drools
Expert(Also Now Drools Planner)
Business Logic Lifecycle
Rules and processes
loosely coupledtightly coupledspecificgenericDecisionServicesProcessRulesSCOPECOUPLING?
Achieving More
By Doing Less
jBPMFile file = new File (.....); // file to XML process definition
ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( IoUtils.FileToString( file ) );
ProcessInstance processInstance = new ProcessInstance(processDefinition);
JessRete 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
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
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
Drools Integration Deployment Descriptors
KnowledegBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBulider();kbuilder.addResource( ResourceFactory.newFileResource( changeset.xml, ResourceType.ChangeSet );
Knowledge XML
Declarative Services
Spring XML and Camel
Stateful Knowledge
Session
Knowledge Runtime
Integrated debug and audit
Self monitoring and adaptive
declare ProcessStartedEvent @role( event )end rule "Number of
process instances above threshold" when Number( nbProcesses :
intValue > 1000 ) from accumulate( e: ProcessStartedEvent(
processInstance.processId == "com.sample.order.OrderProcess" ) over
window:size(1h), count(e) )then System.err.println( "WARNING: Nb of
order processes in the last hour > 1000: " + nbProcesses
);end
Rules and Process Together
Domain Specific Processes
Declarative DomainOverview
Declarative Programming
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 FPMap,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 LogicPerson hasName String and
livesAt Address
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)
Drools Trunk has a prototype Prolog like query backward chaining capabilities. Stronger Polog like capabilities planned.
Opportunistic BC planned.
Functional Programming FPLisp, Haskell
Drools 5.0 has some functional capabilities
Drools 5.1, 5.2 will be looking to have strong functional capabilities
Declarative Programming
Description Logic DLKIF, OWL-DL
Planned, See The Future
ProcessesDrools 5.1 implements BPMN2 with advanced rule integration.
Drools Flow will be incorporated into jBPM5
Domain Overview
Domain Overview
Domain Overview
The Future
Full Hybrid Enginehttp://community.jboss.org/wiki/DroolsLanguageEnhancements
Nested Objects
Casting Nested Objects
Positional Constraints
POSL - Positional-Slotted Language
Method Calls
Maps and Arrays (Collections)
Collections and XPath like filtering
Free form Expressions
Managed Object Graphs (MOGS)
Nested Patterns and Queries
Queries and Unification
Ontologies and Relations via
Query Based Backward Chaining with POSL
Triples with Hybrid POJO Graph Notation.
Escapes for Dialects
Accumulate Improvements to Support Haskell map/fold/filter and MVEL projection/fold
Otherwise
Branch (Labelled Else)
Rule Execution Groups
Rule Dependency Meta-Rule Language
Parallel Meta-Rule Language
Field Versioning
Logical Closures/OnFalse
Opportunistic Backward Chaining, Lazy Field/Object Values
...
Drools Expert
Quick Example Stateless
Definitions
public 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
Building
KnowledgeBuilder 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() );
Executing
StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();Applicant applicant = new Applicant( "Mr John Smith", 16 );assertTrue( applicant.isValid() );
ksession.execute( applicant );
assertFalse( applicant.isValid() );
rule "Is of valid age" when $a : Applicant( age < 18 )then modify( $a ) { valid = false };ends
Drools Expert
Quick Example Stateful
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 {}
Definitions
rule "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 );end
rule "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
Definitions
rule "Raise the alarm when we have one or more fires" when exists Fire()then insert( new Alarm() ); println( "Raise the alarm" );end
rule "Cancel the alarm when all the fires have gone" when not Fire() $alarm : Alarm()then retract( $alarm ); println( "Cancel the alarm" );end
Definitions
rule "Status output when things are ok" when not Alarm() not Sprinkler( on == true ) then println( "Everything is ok" );end
Executing
String[] names = new String[]{"kitchen", "bedroom", "office", "livingroom"};Map name2room = new HashMap();
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
Executing
Fire 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
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 "Status output when things are ok" when not Alarm() not Sprinkler( on == true ) then println( "Everything is ok" );end
Conditional Elements
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 ) )
Accumulate CE
rule "accumulate"when $sum : Number( intValue > 100 ) from accumulate( Bus( color == "red", $t : takings ) sum( $t ) )then print "sum is + $sum;end
Accumulate CE
Patterns and CE's can be chained with 'from'
rule "collect"when $zipCode : ZipCode() $sum : Number( intValue > 100 ) from accumulate( Bus( color == "red", $t : takings ) from $hbn.getNamedQuery(Find Buses) .setParameters( [ zipCode : $zipCode ] ) .list(), sum( $t ) )then print "sum is + $sum;end
TimersCalendars
Timers
rule name timer 1m30swhen $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 beenon for 1m30s then turn it
offSame as above. Interval timer with
JDK semantics for initial duration,
then repeat duration.
Timers
rule name timer ( cron: 0 0/15 * * * * )when Alarm( )then sendEmail( Alert Alert Alert!!! )
Field Name Mandatory? Allowed Values Allowed Special CharactersSeconds YES 0-59 , - * /Minutes YES 0-59 , - * /Hours YES 0-23 , - * /Day of month YES 1-31 , - * ? / L WMonth 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
Calendars
rule "weekdays are high priority" calendars "weekday" timer (int:0 1h)when Alarm()then send( "priority high - we have an alarm );end
rule "weekend are low priority" calendars "weekend" timer (int:0 4h)when Alarm()then send( "priority low - we have an alarm );end
Execute now and after
1 hour durationExecute now and after
4 hour duration
Drools Expert
A Little Deeper
Classes
increase balance for AccountPeriod Credits
select * from Account acc, Cashflow cf, AccountPeriod apwhere acc.accountNo == cf.accountNo and cf.type == CREDIT cf.date >= ap.start and cf.date = ap.start and cf.date = ap.start && = ap.start and cf.date = ap.start && = ap.start && = 16 )then insert(new AdultBusPass( $p ) );end
Couples the logicWhat happens when the Child stops being 16?
TMS and Inference
BadMonolithic
Leaky
Brittle integrity - manual maintenance
TMS and Inference
A rule logically inserts an object
When the rule is no longer true, the object is retracted.
when $p : Person( age < 16 )then logicalInsert( new IsChild( $p ) )endwhen $p : Person( age >= 16 )then logicalInsert( new IsAdult( $p ) )end
de-couples the logicMaintains the truth by
automatically retracting
TMS and Inference
rule "Issue Child Bus Pass"when $p : Person( ) IsChild( person =$p )then logicalInsert(new ChildBusPass( $p ) );endrule "Issue Adult Bus Pass"when $p : Person( age >= 16 ) IsAdult( person =$p )then logicalInsert(new AdultBusPass( $p ) );end
The truth maintenance cascades
TMS and Inference
rule "Issue Child Bus Pass"when $p : Person( ) not( ChildBusPass( person == $p ) )then requestChildBusPass( $p );end
The truth maintenance cascades
TMS and Inference
GoodDe-couple knowledge responsibilities
Encapsulate knowledge
Provide semantic abstractions for those encapsulation
Integrity robustness truth maintenance
Drools Expert
Authoring Metaphores
Guided Editor
Decision Table
Decision Table
rule "Pricing bracket_10"
when Driver(age >= 18, age 100 ) from accumulate( $s : StockTicker( symbol == RHAT ) over window:time( 5s ), average( $s.price ) )
Over 5 secondsAggregate ticker price for RHAT over last 5 secondsThe pattern 'Number' reasons 'from' the accumulate result
Drools Guvnor
Guvnor
TechnologyJCR (JSR-170) backend
Seam + GWT frontend
WebDav
Eclipse synchronisation plugin
Role based security
AuthoringDecision Tables
Guided Editor
Rule Templates
Sentence Templates (DSLs)
Declared Types
QAScenario Testing
Rule Verification
Business asset storage
Category based browsing
Category based browsing
Guided Editor
Decision Tables
Scenario Testing
Scenario Testing
What's new In 5.1
What's new to 5.1
IntegrationOSGi ready
Spring
Camel
JMX/JOPR integration
ExpertNew Rete Algorithm differential update
Timers and Calendars
Live Open Querries
FlowBPMN2
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
What's new to 5.1
GuvnorGuided editorNested Expression builderperson.dogs[0].name
Move constrains up and down
Insert constraints
Support for more DRL elements
RSS Subcription, change notifications, inbox
Working Sets
Object constraint definitions
Rule Templates (based on Guided Editor)
Oryx BPM editor integration
Better rule documentation support
Drools flow in Oryx
Drools flow in Eclipse
Questions?
Questions?
Dave Bowman: All right, HAL; I'll go in through the emergency airlock.
HAL: Without your space helmet, Dave, you're going to find that rather difficult.
Dave Bowman: HAL, I won't 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 only winning move is not to play. How about a nice game of chess?
CashFlow
dateamounttypeaccountNo
12-Jan-07100CREDIT1
2-Feb-07200DEBIT1
18-May-0750CREDIT1
9-Mar-0775CREDIT1
???Page ??? (???)15/09/2010, 12:54:11Page / CashFlow
dateamounttype
12-Jan-07100CREDIT
9-Mar-0775CREDIT
???Page ??? (???)15/09/2010, 12:55:59Page / CashFlow
dateamounttype
2-Feb-07200DEBIT
???Page ??? (???)15/09/2010, 12:55:59Page /
Click to edit the title text format
Click to edit the outline text formatSecond Outline LevelThird Outline LevelFourth Outline LevelFifth Outline LevelSixth Outline LevelSeventh Outline LevelEighth Outline LevelNinth Outline Level
Click to edit the title text format
Click to edit the text format
Click to edit the title text format
Click to edit the text format
Click to edit the outline text formatSecond Outline LevelThird Outline LevelFourth Outline LevelFifth Outline LevelSixth Outline LevelSeventh Outline LevelEighth Outline Level
Red Hat Proprietary and Confidential
Account
accountNobalance
10
???Page ??? (???)15/09/2010, 12:55:59Page / AccountingPeriod
startend
01-Jan-0731-Mar-07
???Page ??? (???)15/09/2010, 12:55:59Page / Account
accountNobalance
1-25
???Page ??? (???)15/09/2010, 12:55:59Page / CashFlow
dateamounttypeaccountNo
12-Jan-07100CREDIT1
2-Feb-07200DEBIT1
18-May-0750CREDIT1
9-Mar-0775CREDIT1
???Page ??? (???)15/09/2010, 12:55:59Page / CashFlow
dateamounttype
12-Jan-07100CREDIT
9-Mar-0775CREDIT
???Page ??? (???)15/09/2010, 12:35:13Page / CashFlow
dateamounttype
2-Feb-07200DEBIT
???Page ??? (???)15/09/2010, 12:35:13Page / Account
accountNobalance
10
???Page ??? (???)15/09/2010, 12:35:13Page / AccountingPeriod
startend
01-Jan-0731-Mar-07
???Page ??? (???)15/09/2010, 12:35:13Page / Account
accountNobalance
1-25
???Page ??? (???)15/09/2010, 12:35:13Page /