1
●
The SkyNet funding bill is passed.
●The system goes online on August 4th, 1997.
●Human decisions are removed from stra...
Agenda
•Quick Intro - What are Rule Based Systems
•KIE
•5.x Critique
•6.0 Improvements
•UI
•Content
•Deployment
•Spring an...
Quick Intro
What are Rule Based Systems
3
Monday, 5 August 13
4
Vision
Robotics
Speech
Neural Nets Rule Base Systems/
Expert System Tools
Understanding
Natural
LanguageSome Areas of
Ar...
5
Knowledge Representation and Reasoning
The study of Knowledge is Epistemology
● Nature Structure and Origins of Knowledg...
6
It All Started Here Birth of CDSS
Dendral
Mycin
Baobab
Guidon
Neomycin
Teiresias Emycin WM
Puff
Sacon
Centaur
Gravida
Wh...
7
Because Not Everyone
Is As Smart As He Is
Monday, 5 August 13
1979 Rete Algorithm by Charles Forgy
8
Monday, 5 August 13
Clips and Jess
Clips 1986
9
Clips 1995
Monday, 5 August 13
10
And some day we'll build him!!!
Monday, 5 August 13
11
What is a Rule
rule <rule_name>
<attribute><value>
when
<conditions>
then
<actions>
end
Monday, 5 August 13
12
Pattern Matching
Person( age >= 18 )
field name restriction
constraintobject type
pattern
Monday, 5 August 13
13
Two Phase System
Monday, 5 August 13
14Classes
AccountAccount
long accountNo
int balance
CashFlowCashFlow
Date date
int amount
AccountPeriodAccountPeriod
Date ...
15
rule “increase balance for AccountPeriod Credits”
when
ap : AccountPeriod()
acc : Account( $accountNo : accountNo )
Cas...
16
rule “increase balance for AccountPeriod Credits”
when
ap : AccountPeriod()
acc : Account( $accountNo : accountNo )
Cas...
17
rule “increase balance for AccountPeriod Credits”
when
ap : AccountPeriod()
acc : Account( $accountNo : accountNo )
Cas...
18
rule “increase balance for AccountPeriod Credits”
when
ap : AccountPeriod()
acc : Account( $accountNo : accountNo )
Cas...
19
Rules as a “view”
rule "Increase balance for AccountPeriod Credits"
when
ap : AccountPeriod( )
acc : Account( )
cf : Ca...
20
rule "Print blance for AccountPeriod" salience -50
when
ap : AccountPeriod()
acc : Account( )
then
System.out.println( ...
21
rule “increase balance for AccountPeriod Credits”
ruleflow-group “calculation”
when
ap : AccountPeriod()
acc : Account(...
22
Monday, 5 August 13
Knowledge Is Everything
Platform Changes Overview
23
Monday, 5 August 13
KIE - Knowledge Is Everything
24
KIE
Drools jBPMOptaPlanner UberFire
Guvnor
Drools-WB jBPM-WB
KIE-WB
Monday, 5 August 13
GitHub
URL:
https://github.com/droolsjbpm/
Bootstrap project:
https://github.com/droolsjbpm/droolsjbpm-build-bootstrap
25
...
GitHub
26
Monday, 5 August 13
Changes
Conventions:
•droolsjbpm -> kie
•knowlege -> kie
Examples
•KnowledgeBase -> Kie
•StatefulKnowledgeSession -> KieSe...
5.x Critique
28
Monday, 5 August 13
5.x Critique
•UI
•Content
•Deployment
•Utilize
29
Monday, 5 August 13
5.x Critique
UI
•GWT
•but not easily extended
•fixed layouts
•no perspectives
30
Monday, 5 August 13
5.x Critique
Content
•JCR
•Performance issues
•Everything stored as a blob
•No tagging, branching etc.
•Webdav, with limit...
5.x Critique
32
Deployment
•Simple Snapshot system
•No real methodology
•Doesn’t align with any industry standards
Monday,...
5.x Critique
Utilize
•Progmatic API only
•Have to select all resources
33
KnowledgeBuilder kbuilder = KnowledgeBuilderFact...
6.0 UI
Improvements
34
Monday, 5 August 13
6.0 UI
UI
•Modular
•Extensible
35
•Dynamic and Flexible layouts
•Perspectives
UF
Monday, 5 August 13
Video
UI Overview
https://www.youtube.com/watch?v=ckAznbOOV-4
36
Monday, 5 August 13
6.0 UI
38
Monday, 5 August 13
6.0 UI Content and Authoring
Improvements
39
Monday, 5 August 13
6.0 Content
•GIT
•Industry standard tooling
•Multiple repositories and projects
•All projects are Maven multi-module proje...
6.0 Content
Simple POM Editor
41
Monday, 5 August 13
6.0 Content
Build And Deploy
42
Monday, 5 August 13
6.0 Content
Local Maven repository and manager
43
Monday, 5 August 13
Video
Maven, Builder an Deploy
https://www.youtube.com/watch?v=ckAznbOOV-4
44
Monday, 5 August 13
6.0 Content
Create or Clone Git Repositories
46
Monday, 5 August 13
6.0 Deployment Improvements
47
Monday, 5 August 13
6.0 Deployment
48
Deployment
•Maven JARS
•All projects are just maven projects
•All projects compile to JARS
•JARS are ins...
6.0 Utilization
Improvemets
49
Monday, 5 August 13
KieModules
•Discovery
•META-INF/kmodule.xml
•Convention based
•No programmatic api for building
•Multiple Named entities
•...
Git Hub Examples
https://github.com/droolsjbpm/drools/tree/master/drools-examples-api
51
Monday, 5 August 13
KieModules
Defaults and JAR on Classpath
•Creates one KieBase, adds all resources from that JAR
•See kmodule.xsd in kie-ap...
53
Monday, 5 August 13
KieModules
Named Entities and JAR on Classpath
•Creates one KieBase
•Includes resources from package matching kbase name
5...
55
Monday, 5 August 13
KieModules
Named Entities, with inheritence and JAR on Classpath
•Two projects, one “includes” from the other
56
<dependen...
KieModules
Package location can over-ride kbase name defaults
57
<kbase name="WumpusMainKB" packages="org.drools.games.wum...
Dynamic KieModules
•JARs can be loaded from URLs into KieRepository
•Once loaded they can be resolved via ReleaseId
58
Kie...
Dynamic KieModules
kie-ci use embedded maven for remote discovery
59
<dependency>
<groupId>org.kie</groupId>
<artifactId>k...
Dynamic Modules
•Kie-CI and Automatic updates with KieScanner
•Replaces KnowledgeAgent
•Mave resolves new artifacts dynami...
Dynamic Modules
61
// create a new kjar
InternalKieModule kJar2 = createKieJar(ks, releaseId, "rule2", "rule3");
// deploy...
Programmatic API
•Builder API, for tooling integration
•Incremental compilation, and problem reporting
62
KieServices ks =...
kmodule.xml Editor
63
Monday, 5 August 13
6.0 Spring Camel
64
Monday, 5 August 13
Spring and Camel
65
Monday, 5 August 13
Spring and Camel
66
Monday, 5 August 13
Spring and Camel
67
Monday, 5 August 13
Spring and Camel
68
Monday, 5 August 13
6.0 CDI
69
Monday, 5 August 13
CDI Context and Dependency Injection
CDI injects named entities from the kmodule.xml
Injectable types
•KieServices
•KieCon...
KieContainer
71
@Inject
private KieContainer kContainer;
@Inject
@KReleaseId(groupId = "jar1",
artifactId = "art1",
versio...
KBase
72
@Inject
@KBase(value="jar1.KBase1", name="kb2")
@KReleaseId( groupId = "jar1",
artifactId = "art1",
version = "1....
KSession
73
@Inject
private KieSession defaultClassPathKSession;
@Inject
@KReleaseId( groupId = "jar1",
artifactId = "art1...
KSession
74
@Inject
@KSession("jar1.KSession2")
@KReleaseId( groupId = "jar1",
artifactId = "art1",
version = "1.0" )
priv...
6.0 Score Cards
75
Monday, 5 August 13
Score Cards
a) Setup Parameters
b) Characteristic Section
76
Monday, 5 August 13
Score Cards
77
•UI Generates PMML
•DRL Generated from PMML
•DRL results in
•Calculated Score
•Ranked Reason Codes
•Can imp...
6.0 JTMS
78
Monday, 5 August 13
Justification-based Truth Maintenace JTMS
Drools 5.x
•Simple logical insertion TMS, like Clips, Jess and others.
•Drools 6...
80
JTMS
rule "Issue Child Bus Pass"
when
$p : Person( age < 16 )
then
insert(new ChildBusPass( $p ) );
end
rule "Issue Adu...
81
JTMS
•Bad
•Monolithic
•Leaky
•Brittle integrity - manual maintenance
Monday, 5 August 13
82
JTMS
•A rule “logically” inserts an object
•When the rule is no longer true, the object is retracted.
rule "IsChild"
wh...
83
JTMS
rule "Issue Child Bus Pass"
when
$p : Person( )
IsChild( person =$p )
then
logicalInsert(new ChildBusPass( $p ) );...
84
JTMS
rule "Issue Child Bus Pass"
when
$p : Person( )
not( ChildBusPass( person == $p ) )
then
requestChildBusPass( $p )...
85
JTMS
• Good
• De-couple knowledge responsibilities
• Encapsulate knowledge
• Provide semantic abstractions for those en...
JTMS
86
IsChild
ChildBusPas
Rule : isChildRule
Rule : IssueBusPas
+
+
Monday, 5 August 13
JTMS
87
rule "Do not issue to banned people"
when
$p : Person( )
Banned( person =$p )
then
logicalInsert(new ChildBusPass(...
JTMS
88
IsChild
ChildBusPas
Rule : isChildRule
Rule : IssueBusPas
+
+
Rule : Do Not Issue
to Banned People
-
Monday, 5 Aug...
R.I.P RETE
inspirations:
•Leaps, Collection Oriented Match, L/R Unlinking
New Innovations
•Full Rule, and Rule Segment Unl...
6.0 Legacy and
Backwards Compatability
90
Monday, 5 August 13
Legacy Systems and Migration
Legacy API Adapter JAR
•Most API’s should work with legacy adapter
•KnowledegAgents have not ...
Backward Chaining
Re-introducing an Advanced Feature
Detailed Tutorial here:
https://www.youtube.com/watch?v=fCjIRVSRFvA
9...
93
Backward Chaining
query isChild( Person p )
$p := Person( age <= 16 )
end
rule "Issue Child Bus Pass"
when
$p : Person(...
94
Reasoning with Graphs
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Locati...
95
Backward Chaining
query isContainedIn( String x, String y )
Location( x, y; )
or
( Location( z, y; ) and isContainedIn(...
Backward Chaining
96
ksession.insert( new Location("Office", "House") );
ksession.insert( new Location("Kitchen", "House")...
Backward Chaining
97
rule "go1"
when
String( this == "go1" )
isContainedIn("Office", "House"; )
then
System.out.println( "...
Backward Chaining
98
rule "go2"
when
String( this == "go2" )
isContainedIn("Draw", "House"; )
then
System.out.println( "Dr...
Backward Chaining
99
rule "go3"
when
String( this == "go3" )
isContainedIn("Key", "Office"; )
then
System.out.println( "Ke...
Backward Chaining
100
rule "go4"
when
String( this == "go4" )
isContainedIn(thing, "Office"; )
then
System.out.println( "t...
Backward Chaining
101
rule "go5"
when
String( this == "go5" )
isContainedIn(thing, location; )
then
System.out.println( "t...
102
UF UberFirehttps://www.youtube.com/watch?v=ckAznbOOV-4
Monday, 5 August 13
103
Features
• Compile time composition of plugins
• modular components, each separate maven module.
• Lightweight
• Decou...
UberFire
104
@Dependent
@WorkbenchScreen(identifier = "MyFirstPanel")
public class MyFirstPanel {
private final FlowPanel ...
Proof is in the Pudding
•UI Rewrite started in November
•Entire BRMS ported
•New BPMS built, all integrated
•Tasks, Calend...
106
Questions?Questions?
• Dave Bowman: All right, HAL; I'll go in
through the emergency airlock.
• HAL: Without your spac...
Upcoming SlideShare
Loading in …5
×

What's new in Drools 6 - London JBUG 2013

2,487
-1

Published on

Presentation around the time of Beta3 for "What's new in Drools 6.0". Note some aspects have already changed, especially around the spring integration.

Published in: Technology, Spiritual
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,487
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
118
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

What's new in Drools 6 - London JBUG 2013

  1. 1. 1 ● 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 Proctor Project Lead Monday, 5 August 13
  2. 2. Agenda •Quick Intro - What are Rule Based Systems •KIE •5.x Critique •6.0 Improvements •UI •Content •Deployment •Spring and Camel •API •CDI •ScoreCards and PMML •JTMS •Phreak •Legacy Migrations •Backward chaining Example •UberFire 2 Monday, 5 August 13
  3. 3. Quick Intro What are Rule Based Systems 3 Monday, 5 August 13
  4. 4. 4 Vision Robotics Speech Neural Nets Rule Base Systems/ Expert System Tools Understanding Natural LanguageSome Areas of Artificial Intelligence Some Areas of Artificial Intelligence Monday, 5 August 13
  5. 5. 5 Knowledge Representation and Reasoning The study of Knowledge is Epistemology ● Nature Structure and Origins of Knowledge ● Core or AI Rule based systems ● Expert System tools ● Knowledge Representation and Reasoning ● Facilitate the codification of knowledge into a knowledge base which can be used for reasoning Monday, 5 August 13
  6. 6. 6 It All Started Here Birth of CDSS Dendral Mycin Baobab Guidon Neomycin Teiresias Emycin WM Puff Sacon Centaur Gravida Wheeze Clot Onccocin 1970s 1980s Monday, 5 August 13
  7. 7. 7 Because Not Everyone Is As Smart As He Is Monday, 5 August 13
  8. 8. 1979 Rete Algorithm by Charles Forgy 8 Monday, 5 August 13
  9. 9. Clips and Jess Clips 1986 9 Clips 1995 Monday, 5 August 13
  10. 10. 10 And some day we'll build him!!! Monday, 5 August 13
  11. 11. 11 What is a Rule rule <rule_name> <attribute><value> when <conditions> then <actions> end Monday, 5 August 13
  12. 12. 12 Pattern Matching Person( age >= 18 ) field name restriction constraintobject type pattern Monday, 5 August 13
  13. 13. 13 Two Phase System Monday, 5 August 13
  14. 14. 14Classes AccountAccount long accountNo int balance CashFlowCashFlow Date date int amount AccountPeriodAccountPeriod Date start Date end Monday, 5 August 13
  15. 15. 15 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 Credit Cashflow Rule Monday, 5 August 13
  16. 16. 16 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 Credit Cashflow Rule Monday, 5 August 13
  17. 17. 17 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 Credit Cashflow Rule Monday, 5 August 13
  18. 18. 18 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 Credit Cashflow Rule Monday, 5 August 13
  19. 19. 19 Rules as a “view” rule "Increase balance for AccountPeriod Credits" when ap : AccountPeriod( ) acc : Account( ) cf : CashFlow( type == CashFlowType.CREDIT, accountNo == acc.accountNo, date >= ap.start && <= ap.end ) then acc.balance = acc.balance + cf.amount; end rule "Decrease balance for AccountPeriod Debits" when ap : AccountPeriod( ) acc : Account( ) cf : CashFlow( type == CashFlowType.DEBIT, accountNo == acc.accountNo, date >= ap.start && <= ap.end ) then acc.balance = acc.balance - cf.amount; end CashFlowCashFlowCashFlowCashFlow date amount type accountNo 12-Jan-12 100 CREDIT 1 2-Feb-12 200 DEBIT 1 18-May-12 50 CREDIT 1 9-May-12 75 CREDIT 1 AccountingPeriodAccountingPeriod start end 01-JAN-2012 31-MAR-2012 AccountAccount accountNo balance 1 0 CashFlowCashFlowCashFlowCashFlow date amount type accountNo 12-Jan-12 100 CREDIT 1 9-May-12 75 CREDIT 1 CashFlowCashFlowCashFlowCashFlow date amount type accountNo 2-Feb-12 200 DEBIT 1 AccountAccount accountNo balance 1 -25 Monday, 5 August 13
  20. 20. 20 rule "Print blance for AccountPeriod" salience -50 when ap : AccountPeriod() acc : Account( ) then System.out.println( "Account Number " + acc.accountNo + " balance " + acc.balance ); end Conflict Resolution with Salience AgendaAgendaAgenda 1 increase balance arbitrary 2 decrease balance arbitrary 3 increase balance arbitrary 4 print balance Monday, 5 August 13
  21. 21. 21 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 rule “Print blance for AccountPeriod” ruleflow-group “report” when ap : AccountPeriod() acc : Account( ) then System.out.println( acc.accountNo + “ : “ acc.balance ); end ruleflow-group RuleFlow Monday, 5 August 13
  22. 22. 22 Monday, 5 August 13
  23. 23. Knowledge Is Everything Platform Changes Overview 23 Monday, 5 August 13
  24. 24. KIE - Knowledge Is Everything 24 KIE Drools jBPMOptaPlanner UberFire Guvnor Drools-WB jBPM-WB KIE-WB Monday, 5 August 13
  25. 25. GitHub URL: https://github.com/droolsjbpm/ Bootstrap project: https://github.com/droolsjbpm/droolsjbpm-build-bootstrap 25 Monday, 5 August 13
  26. 26. GitHub 26 Monday, 5 August 13
  27. 27. Changes Conventions: •droolsjbpm -> kie •knowlege -> kie Examples •KnowledgeBase -> Kie •StatefulKnowledgeSession -> KieSession •StatelessKnowledgeSession - StatelesKieSession Legacy API Adapter JAR •Most API’s should work with legacy adapter •KnowledegAgents have not been ported, PKG’s are not longer the unit of deployment DRL has not changed 27 Monday, 5 August 13
  28. 28. 5.x Critique 28 Monday, 5 August 13
  29. 29. 5.x Critique •UI •Content •Deployment •Utilize 29 Monday, 5 August 13
  30. 30. 5.x Critique UI •GWT •but not easily extended •fixed layouts •no perspectives 30 Monday, 5 August 13
  31. 31. 5.x Critique Content •JCR •Performance issues •Everything stored as a blob •No tagging, branching etc. •Webdav, with limited Eclipse team provider integration. •Single tree structure (packages) •Packages created project deployment units •no real alignment with industry stadard •No easy rule use (only a single global area) •Loading “model” jars into packages •Poor hack, for dependency management 31 Monday, 5 August 13
  32. 32. 5.x Critique 32 Deployment •Simple Snapshot system •No real methodology •Doesn’t align with any industry standards Monday, 5 August 13
  33. 33. 5.x Critique Utilize •Progmatic API only •Have to select all resources 33 KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.batch().add( newClassPathResource( "Model.drl", getClass() ), DRL ) .add( newClassPathResource( "Queries.drl", getClass() ), DRL ) .add( newClassPathResource( "General.drl", getClass() ), DRL ) .add( newClassPathResource( "Response.drl", getClass() ), DRL ) .add( newClassPathResource( "Events.drl", getClass() ), DRL ) .add( newClassPathResource( "UiView.drl", getClass() ), DRL ) .add( newClassPathResource( "Commands.drl", getClass() ), DRL ).build(); if ( kbuilder.hasErrors() ) { System.out.println( kbuilder.getErrors().toString() ); System.exit( 1 ); } KieBaseConfiguration kbaseConf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kbaseConf.setOption( EqualityBehaviorOption.EQUALITY ); KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase( kbaseConf ); kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() ); Counter c = new Counter(); ksession = kbase.newStatefulKnowledgeSession(); Monday, 5 August 13
  34. 34. 6.0 UI Improvements 34 Monday, 5 August 13
  35. 35. 6.0 UI UI •Modular •Extensible 35 •Dynamic and Flexible layouts •Perspectives UF Monday, 5 August 13
  36. 36. Video UI Overview https://www.youtube.com/watch?v=ckAznbOOV-4 36 Monday, 5 August 13
  37. 37. 6.0 UI 38 Monday, 5 August 13
  38. 38. 6.0 UI Content and Authoring Improvements 39 Monday, 5 August 13
  39. 39. 6.0 Content •GIT •Industry standard tooling •Multiple repositories and projects •All projects are Maven multi-module projects •Projects can be shared, via pom dependencies •Both Kie projects, and any other maven jar •Local Maven repository management for model jars 40 Monday, 5 August 13
  40. 40. 6.0 Content Simple POM Editor 41 Monday, 5 August 13
  41. 41. 6.0 Content Build And Deploy 42 Monday, 5 August 13
  42. 42. 6.0 Content Local Maven repository and manager 43 Monday, 5 August 13
  43. 43. Video Maven, Builder an Deploy https://www.youtube.com/watch?v=ckAznbOOV-4 44 Monday, 5 August 13
  44. 44. 6.0 Content Create or Clone Git Repositories 46 Monday, 5 August 13
  45. 45. 6.0 Deployment Improvements 47 Monday, 5 August 13
  46. 46. 6.0 Deployment 48 Deployment •Maven JARS •All projects are just maven projects •All projects compile to JARS •JARS are installed to local M2_REPO, which is expose on http •Can “deploy” to external repos. •Uses Maven industry methdologies Monday, 5 August 13
  47. 47. 6.0 Utilization Improvemets 49 Monday, 5 August 13
  48. 48. KieModules •Discovery •META-INF/kmodule.xml •Convention based •No programmatic api for building •Multiple Named entities •Inheritence of Resources •Defaults for lazy people •Version built in a standard 50 Monday, 5 August 13
  49. 49. Git Hub Examples https://github.com/droolsjbpm/drools/tree/master/drools-examples-api 51 Monday, 5 August 13
  50. 50. KieModules Defaults and JAR on Classpath •Creates one KieBase, adds all resources from that JAR •See kmodule.xsd in kie-api jar 52 <kmodule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://jboss.org/kie/6.0.0/kmodule"> </kmodule> KieServices ks = KieServices.Factory.get(); KieContainer kContainer = ks.getKieClasspathContainer(); KieSession kSession = kContainer.newKieSession(); kSession.setGlobal("out", out); kSession.insert(new Message("Dave", "Hello, HAL. Do you read me, HAL?")); kSession.fireAllRules(); Monday, 5 August 13
  51. 51. 53 Monday, 5 August 13
  52. 52. KieModules Named Entities and JAR on Classpath •Creates one KieBase •Includes resources from package matching kbase name 54 <kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule"> <kbase name="namedkiesession"> <ksession name="ksession1"/> </kbase> </kmodule> KieServices ks = KieServices.Factory.get(); KieContainer kContainer = ks.getKieClasspathContainer(); KieSession kSession = kContainer.newKieSession("ksession1"); kSession.setGlobal("out", out); kSession.insert(new Message("Dave", "Hello, HAL. Do you read me, HAL?")); kSession.fireAllRules(); Monday, 5 August 13
  53. 53. 55 Monday, 5 August 13
  54. 54. KieModules Named Entities, with inheritence and JAR on Classpath •Two projects, one “includes” from the other 56 <dependency> <groupId>org.drools</groupId> <artifactId>named-kiesession</artifactId> <version>6.0.0-SNAPSHOT</version> </dependency> <kbase name="kiebaseinclusion" includes="namedkiebase"> <ksession name="ksession2"/> </kbase> KieServices ks = KieServices.Factory.get(); KieContainer kContainer = ks.getKieClasspathContainer(); KieSession kSession = kContainer.newKieSession("ksession2"); kSession.setGlobal("out", out); kSession.insert(new Message("Dave", "Hello, HAL. Do you read me, HAL?")); kSession.fireAllRules(); kSession.insert(new Message("Dave", "Open the pod bay doors, HAL.")); kSession.fireAllRules(); Monday, 5 August 13
  55. 55. KieModules Package location can over-ride kbase name defaults 57 <kbase name="WumpusMainKB" packages="org.drools.games.wumpus.server, org.drools.games.wumpus.server.view"> <ksession name="WumpusMainKS" /> </kbase> <kbase name="WumpusClientKB" packages="org.drools.games.wumpus.client"> <ksession name="WumpusClientKS"/> </kbase> KieContainer kc = KieServices.Factory.get().getKieClasspathContainer(); final KieSession serverKsession = kc.newKieSession( "WumpusMainKS"); final KieSession clientKsession = kc.newKieSession("WumpusClientKS"); Monday, 5 August 13
  56. 56. Dynamic KieModules •JARs can be loaded from URLs into KieRepository •Once loaded they can be resolved via ReleaseId 58 KieServices ks = KieServices.Factory.get(); KieRepository kr = ks.getRepository(); KieModule kModule = kr.addKieModule(ks.getResources().newFileSystemResource( getFile("default-kiesession"))); KieContainer kContainer = ks.newKieContainer(kModule.getReleaseId()); KieSession kSession = kContainer.newKieSession(); kSession.setGlobal("out", out); Object msg1 = createMessage(kContainer, "Dave", "Hello, HAL. Do you read me, HAL?"); kSession.insert(msg1); kSession.fireAllRules(); Monday, 5 August 13
  57. 57. Dynamic KieModules kie-ci use embedded maven for remote discovery 59 <dependency> <groupId>org.kie</groupId> <artifactId>kie-ci</artifactId> </dependency> KieServices ks = KieServices.Factory.get(); // Install example1 in the local maven repo before to do this KieContainer kContainer = ks.newKieContainer( ks.newReleaseId("org.drools", "named-kiesession", "6.0.0-SNAPSHOT")); KieSession kSession = kContainer.newKieSession("ksession1"); kSession.setGlobal("out", out); Object msg1 = createMessage(kContainer, "Dave", "Hello, HAL. Do you read me, HAL?"); kSession.insert(msg1); kSession.fireAllRules(); Monday, 5 August 13
  58. 58. Dynamic Modules •Kie-CI and Automatic updates with KieScanner •Replaces KnowledgeAgent •Mave resolves new artifacts dynamically at runtime •SNAPSHOT, LATEST, STABLE and version ranges supported •See KieRepositoryScannerTest 60 KieServices ks = KieServices.Factory.get(); ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test", "1.0-SNAPSHOT"); InternalKieModule kJar1 = createKieJar(ks, releaseId, "rule1", "rule2"); KieContainer kieContainer = ks.newKieContainer(releaseId); MavenRepository repository = getMavenRepository(); repository.deployArtifact(releaseId, kJar1, kPom); // create a ksesion and check it works as expected KieSession ksession = kieContainer.newKieSession("KSession1"); checkKSession(ksession, "rule1", "rule2"); Monday, 5 August 13
  59. 59. Dynamic Modules 61 // create a new kjar InternalKieModule kJar2 = createKieJar(ks, releaseId, "rule2", "rule3"); // deploy it on maven repository.deployArtifact(releaseId, kJar2, kPom); // since I am not calling start() on the scanner it means it won't have automatic scheduled scanning KieScanner scanner = ks.newKieScanner(kieContainer); // scan the maven repo to get the new kjar version and deploy it on the kcontainer scanner.scanNow(); // create a ksesion and check it works as expected KieSession ksession2 = kieContainer.newKieSession("KSession1"); checkKSession(ksession2, "rule2", "rule3"); Monday, 5 August 13
  60. 60. Programmatic API •Builder API, for tooling integration •Incremental compilation, and problem reporting 62 KieServices ks = KieServices.Factory.get(); KieRepository kr = ks.getRepository(); KieFileSystem kfs = ks.newKieFileSystem(); kfs.write("src/main/resources/org/kie/example5/HAL5.drl", getRule()); KieBuilder kb = ks.newKieBuilder(kfs); kb.buildAll(); // kieModule is automatically deployed to KieRepository if successfully built. if (kb.getResults().hasMessages(Level.ERROR)) { throw new RuntimeException("Build Errors:n" + kb.getResults().toString()); } KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId()); KieSession kSession = kContainer.newKieSession(); kSession.setGlobal("out", out); kSession.insert(new Message("Dave", "Hello, HAL. Do you read me, HAL?")); kSession.fireAllRules(); Monday, 5 August 13
  61. 61. kmodule.xml Editor 63 Monday, 5 August 13
  62. 62. 6.0 Spring Camel 64 Monday, 5 August 13
  63. 63. Spring and Camel 65 Monday, 5 August 13
  64. 64. Spring and Camel 66 Monday, 5 August 13
  65. 65. Spring and Camel 67 Monday, 5 August 13
  66. 66. Spring and Camel 68 Monday, 5 August 13
  67. 67. 6.0 CDI 69 Monday, 5 August 13
  68. 68. CDI Context and Dependency Injection CDI injects named entities from the kmodule.xml Injectable types •KieServices •KieContainer •KieBase •KieSession •StatelessKieSession 70 Monday, 5 August 13
  69. 69. KieContainer 71 @Inject private KieContainer kContainer; @Inject @KReleaseId(groupId = "jar1", artifactId = "art1", version = "1.1") private KieContainer kContainerv11; Monday, 5 August 13
  70. 70. KBase 72 @Inject @KBase(value="jar1.KBase1", name="kb2") @KReleaseId( groupId = "jar1", artifactId = "art1", version = "1.0") private KieBase jar1KBase1kb2; @Inject @KBase(value="jar1.KBase1", name="kb2") @KReleaseId( groupId = "jar1", artifactId = "art1", version = "1.0") private KieBase jar1KBase1kb22; @Inject private KieBase defaultClassPathKBase; @Inject @KReleaseId( groupId = "jar1", artifactId = "art1", version = "1.0") private KieBase defaultDynamicKBase; @Inject @KBase("jar1.KBase1") @KReleaseId( groupId = "jar1", artifactId = "art1", version = "1.0") private KieBase jar1KBase1v10; @Inject @KBase("jar1.KBase1") @KReleaseId(groupId = "jar1", artifactId = "art1", version = "1.1") private KieBase jar1KBase1v11; @Inject @KBase(value="jar1.KBase1", name="kb1") @KReleaseId( groupId = "jar1", artifactId = "art1", version = "1.0") private KieBase jar1KBase1kb1; Monday, 5 August 13
  71. 71. KSession 73 @Inject private KieSession defaultClassPathKSession; @Inject @KReleaseId( groupId = "jar1", artifactId = "art1", version = "1.0") private KieSession defaultDynamicKSession; Monday, 5 August 13
  72. 72. KSession 74 @Inject @KSession("jar1.KSession2") @KReleaseId( groupId = "jar1", artifactId = "art1", version = "1.0" ) private KieSession kbase1ksession2v10; @Inject @KSession("jar1.KSession2") @KReleaseId( groupId = "jar1", artifactId = "art1", version = "1.1" ) private KieSession kbase1ksession2v11; @Inject @KSession(value="jar1.KSession2", name="ks1") @KReleaseId( groupId = "jar1", artifactId = "art1", version = "1.0" ) private KieSession kbase1ksession2ks1; @Inject @KSession(value="jar1.KSession2", name="ks2") @KReleaseId( groupId = "jar1", artifactId = "art1", version = "1.0" ) private KieSession kbase1ksession2ks2 ; @Inject @KSession(value="jar1.KSession2", name="ks2") @KReleaseId( groupId = "jar1", artifactId = "art1", version = "1.0" ) private KieSession kbase1ksession2ks22; Monday, 5 August 13
  73. 73. 6.0 Score Cards 75 Monday, 5 August 13
  74. 74. Score Cards a) Setup Parameters b) Characteristic Section 76 Monday, 5 August 13
  75. 75. Score Cards 77 •UI Generates PMML •DRL Generated from PMML •DRL results in •Calculated Score •Ranked Reason Codes •Can import PMML 4.1 •but not exposed yet •Calculated Scores •Currently Summations •Weight coming •Not in PMML standard Monday, 5 August 13
  76. 76. 6.0 JTMS 78 Monday, 5 August 13
  77. 77. Justification-based Truth Maintenace JTMS Drools 5.x •Simple logical insertion TMS, like Clips, Jess and others. •Drools 6.0 •Contradiction handling with JTMS •Clean separation of exception logic •TMS now has pluggable Belief System •Simple TMS support •JTMS now possible. •Defeasible Logic soon •See drools-compiler •JTMSTest for lots of example tests •https://github.com/droolsjbpm/drools/blob/master/drools-compiler/ src/test/java/org/drools/compiler/beliefsystem/jtms/ JTMSTest.java 79 Monday, 5 August 13
  78. 78. 80 JTMS rule "Issue Child Bus Pass" when $p : Person( age < 16 ) then insert(new ChildBusPass( $p ) ); end rule "Issue Adult Bus Pass" when $p : Person( age >= 16 ) then insert(new AdultBusPass( $p ) ); end Couples the logic What happens when the Child stops being 16? Monday, 5 August 13
  79. 79. 81 JTMS •Bad •Monolithic •Leaky •Brittle integrity - manual maintenance Monday, 5 August 13
  80. 80. 82 JTMS •A rule “logically” inserts an object •When the rule is no longer true, the object is retracted. rule "IsChild" when $p : Person( age < 16 ) then logicalInsert( new IsChild( $p ) ) end rule "IsAdult" when $p : Person( age >= 16 ) then logicalInsert( new IsAdult( $p ) ) end de-couples the logic Maintains the truth by automatically retracting Monday, 5 August 13
  81. 81. 83 JTMS rule "Issue Child Bus Pass" when $p : Person( ) IsChild( person =$p ) then logicalInsert(new ChildBusPass( $p ) ); end rule "Issue Adult Bus Pass" when $p : Person() IsAdult( person =$p ) then logicalInsert(new AdultBusPass( $p ) ); end The truth maintenance cascades Monday, 5 August 13
  82. 82. 84 JTMS rule "Issue Child Bus Pass" when $p : Person( ) not( ChildBusPass( person == $p ) ) then requestChildBusPass( $p ); end The truth maintenance cascades Monday, 5 August 13
  83. 83. 85 JTMS • Good • De-couple knowledge responsibilities • Encapsulate knowledge • Provide semantic abstractions for those encapsulation • Integrity robustness – truth maintenance Monday, 5 August 13
  84. 84. JTMS 86 IsChild ChildBusPas Rule : isChildRule Rule : IssueBusPas + + Monday, 5 August 13
  85. 85. JTMS 87 rule "Do not issue to banned people" when $p : Person( ) Banned( person =$p ) then logicalInsert(new ChildBusPass( $p ) , “neg” ); end Monday, 5 August 13
  86. 86. JTMS 88 IsChild ChildBusPas Rule : isChildRule Rule : IssueBusPas + + Rule : Do Not Issue to Banned People - Monday, 5 August 13
  87. 87. R.I.P RETE inspirations: •Leaps, Collection Oriented Match, L/R Unlinking New Innovations •Full Rule, and Rule Segment Unlinking •Lazy Evaluation, with Rule scoping •Set propagations Previous Innovations •Modify In Place •Property Reactive •Tree Based Graphs •Subnetwork support 89 Monday, 5 August 13
  88. 88. 6.0 Legacy and Backwards Compatability 90 Monday, 5 August 13
  89. 89. Legacy Systems and Migration Legacy API Adapter JAR •Most API’s should work with legacy adapter •KnowledegAgents have not been ported, PKG’s are not longer the unit of deployment JCR Migration Tool •Command Line Java code •Each Package maps to a GIT project 91 Monday, 5 August 13
  90. 90. Backward Chaining Re-introducing an Advanced Feature Detailed Tutorial here: https://www.youtube.com/watch?v=fCjIRVSRFvA 92 Monday, 5 August 13
  91. 91. 93 Backward 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 Monday, 5 August 13
  92. 92. 94 Reasoning with Graphs House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw") Monday, 5 August 13
  93. 93. 95 Backward Chaining query 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("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw") Monday, 5 August 13
  94. 94. Backward Chaining 96 ksession.insert( new Location("Office", "House") ); ksession.insert( new Location("Kitchen", "House") ); ksession.insert( new Location("Knife", "Kitchen") ); ksession.insert( new Location("Cheese", "Kitchen") ); ksession.insert( new Location("Desk", "Office") ); ksession.insert( new Location("Chair", "Office") ); ksession.insert( new Location("Computer", "Desk") ); ksession.insert( new Location("Draw", "Desk") ); House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw") Monday, 5 August 13
  95. 95. Backward Chaining 97 rule "go1" when String( this == "go1" ) isContainedIn("Office", "House"; ) then System.out.println( "office is in the house" ); end rule "go" salience 10 when $s : String( ) then System.out.println( $s ); end ksession.insert( "go1" ); ksession.fireAllRules(); --- go1 office is in the house query isContainedIn( String x, String y ) Location( x, y; ) or ( Location( z, y; ) and isContainedIn( x, z; ) ) end Does not recurse. Finds Location(“Office, House”) on first call. House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw") Monday, 5 August 13
  96. 96. Backward Chaining 98 rule "go2" when String( this == "go2" ) isContainedIn("Draw", "House"; ) then System.out.println( "Draw in the House" ); end ksession.insert( "go2" ); ksession.fireAllRules(); --- go2 Desk in the House query isContainedIn( String x, String y ) Location( x, y; ) or ( Location( z, y; ) and isContainedIn( x, z; ) ) end Recursive 3 times, note the Z. Location( “Office”, “House”) Location( “Desk”, “Office”) Location( “Draw”, “Desk”) Out Var (unbound) In Var (bound) House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw") Monday, 5 August 13
  97. 97. Backward Chaining 99 rule "go3" when String( this == "go3" ) isContainedIn("Key", "Office"; ) then System.out.println( "Key in the Office" ); end ksession.insert( "go3" ); ksession.fireAllRules(); --- go3 ksession.insert( new Location("Key", "Draw") ); ksession.fireAllRules(); --- Key in the Office Nothing returned. There is no key at any point below Office. But the query stays open and reactive. Key Inserted 3 levels below, but system detects, reacts and bubbles up the results. House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw") Monday, 5 August 13
  98. 98. Backward Chaining 100 rule "go4" when String( this == "go4" ) isContainedIn(thing, "Office"; ) then System.out.println( "thing " + thing + " is in the Office" ); end ksession.insert( "go4" ); ksession.fireAllRules(); --- go4 thing Key is in the Office thing Computer is in the Office thing Draw is in the Office thing Desk is in the Office thing Chair is in the Office Finds all Things in the office, but directly and transitively. Out Var (unbound) House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw") Monday, 5 August 13
  99. 99. Backward Chaining 101 rule "go5" when String( this == "go5" ) isContainedIn(thing, location; ) then System.out.println( "thing " + thing + " is in " + location ); end ksession.insert( "go5" ); ksession.fireAllRules(); --- go5 thing Knife is in House thing Cheese is in House thing Key is in House thing Computer is in House thing Draw is in House thing Desk is in House thing Chair is in House thing Key is in Office thing Computer is in Office thing Draw is in Office thing Key is in Desk thing Office is in House Find all things in all things. Out Var (unbound) Out Var (unbound) thing Computer is in Desk thing Knife is in Kitchen thing Cheese is in Kitchen thing Kitchen is in House thing Key is in Draw thing Draw is in Desk thing Desk is in Office thing Chair is in Office House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw") Monday, 5 August 13
  100. 100. 102 UF UberFirehttps://www.youtube.com/watch?v=ckAznbOOV-4 Monday, 5 August 13
  101. 101. 103 Features • Compile time composition of plugins • modular components, each separate maven module. • Lightweight • Decoupled components • Layout Manager and Perspectives • Embeddable/Reusable (*) • Unified API • Security • I/O • VFS • Metadata • Menus, Toolbars, Panels, etc. • Standard Life Cycle UF UberFire Monday, 5 August 13
  102. 102. UberFire 104 @Dependent @WorkbenchScreen(identifier = "MyFirstPanel") public class MyFirstPanel { private final FlowPanel panel = new FlowPanel(); @PostConstruct private void init() { final Label label = new Label(); label.setText("Hello World!"); panel.add(label); } @WorkbenchPartTitle public String myTitle() { return "My First and Cool Panel!"; } @WorkbenchPartView public IsWidget getView() { return panel; } } Monday, 5 August 13
  103. 103. Proof is in the Pudding •UI Rewrite started in November •Entire BRMS ported •New BPMS built, all integrated •Tasks, Calendars, BPM Designer •Only one person on core UI framework •All team memebers distributed •Despite aggressive schedule •Code remains modular •Easy to maintan and extend •No one is complaining yet :) 105 UF UberFire Monday, 5 August 13
  104. 104. 106 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. Joshya: Greetings, Professor Falken. Falken: Hello, Joshua. Joshya: A strange game. The only winning move is not to play. How about a nice game of chess? Monday, 5 August 13

×