Drools and BRMS 6.0 (Dublin Aug 2013)

1,868 views

Published on

Talk presenting what's new in Drools 6.0, which forms part of the up coming Red Hat BRMS product platform. All kindly sponsored by Sabeo.

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

  • Be the first to like this

No Downloads
Views
Total views
1,868
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
82
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Drools and BRMS 6.0 (Dublin Aug 2013)

  1. 1. Not Quite There Yet •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 Monday, 2 September 13
  2. 2. Who am I? • Drools co-founder • JBoss (2005) • Red Hat (2006) • Polymita Acquisition 2012 • Red Hat Platform Architect Monday, 2 September 13
  3. 3. KIE - Knowledge Is Everything KIE Drools jBPMOptaPlanner UberFire Guvnor Drools-WB jBPM-WB KIE-WB Monday, 2 September 13
  4. 4. KIE - Knowledge Is Everything Monday, 2 September 13
  5. 5. KIE - Knowledge Is Everything Monday, 2 September 13
  6. 6. GitHub • URL: • https://github.com/droolsjbpm/ • Bootstrap project: • https://github.com/droolsjbpm/droolsjbpm- build-bootstrap Monday, 2 September 13
  7. 7. Serious Bits :) http://www.youtube.com/watch?v=Omj4PR3v-nI http://www.youtube.com/watch?v=4CvjKqUOEzM Monday, 2 September 13
  8. 8. What’s a Rule Monday, 2 September 13
  9. 9. This is a Rule Monday, 2 September 13
  10. 10. This is another Rule function checkemail(email){ var filter= /^([w-]+(?:.[w-]+)*)@((?:[w-]+ .)*w[w-]{0,66}).([a-z]{2,6}(?:. [a-z]{2})?)$/i if ( filter.test(email) ) { return true } else{ return false } } Monday, 2 September 13
  11. 11. This is a Rule Engine var validator = new FormValidator('example_form', [{ name: 'req', display: 'required', rules: 'required' }, { name: 'alphanumeric', rules: 'alpha_numeric' }, { name: 'password', rules: 'required' }, { name: 'password_confirm', display: 'password confirmation', rules: 'required|matches[password]' }, Monday, 2 September 13
  12. 12. These are Rules too Monday, 2 September 13
  13. 13. What is a Rule rule <rule_name> <attribute><value> when <conditions> then <actions> end Monday, 2 September 13
  14. 14. Pattern Matching Person(age >= 18) field name restriction constraintobject type pattern Monday, 2 September 13
  15. 15. Pattern Matching ? case class Grade( letter : String, passed : Boolean ) def check( grade : Grade ) = { grade match { case Grade(letter,true) => printf( "You have passed with grade: %s", letter ) case Grade(letter,false) => printf( "You have failed with grade: %s", letter ) } } Monday, 2 September 13
  16. 16. Hybrid Reasoning Monday, 2 September 13
  17. 17. Types of 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] 17 Monday, 2 September 13
  18. 18. Quick Intro What are Rule Based Systems Monday, 2 September 13
  19. 19. 19 Vision Robotics Speech Neural Nets Rule Base Systems/ Expert System Tools Understanding Natural LanguageSome Areas of Artificial Intelligence Some Areas of Artificial Intelligence Monday, 2 September 13
  20. 20. 20 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, 2 September 13
  21. 21. 21 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, 2 September 13
  22. 22. 22 Because Not Everyone Is As Smart As He Is Monday, 2 September 13
  23. 23. 1979 Rete Algorithm by Charles Forgy 23 Monday, 2 September 13
  24. 24. Clips and Jess Clips 1986 24 Clips 1995 Monday, 2 September 13
  25. 25. Technical Language Monday, 2 September 13
  26. 26. 26 Classes AccountAccount long accountNo int balance CashFlowCashFlow Date date int amount AccountPeriodAccountPeriod Date start Date end CashFlow Example Monday, 2 September 13
  27. 27. 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 rule “increase balance for AccountPeriod Credits” when ap : AccountPeriod() acc : Account() cf : CashFlow( type == CREDIT, accountNo == acc.accountNo, date >= ap.start && <= ap.end ) then acc.balance += cf.amount; end 27 acc.balance += cf.amount CashFlow Rule Monday, 2 September 13
  28. 28. 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 rule “increase balance for AccountPeriod Credits” when ap : AccountPeriod() acc : Account() cf : CashFlow( type == CREDIT, accountNo == acc.accountNo, date >= ap.start && <= ap.end ) then acc.balance += cf.amount; end 28 acc.balance += cf.amount CashFlow Rule Monday, 2 September 13
  29. 29. 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 rule “increase balance for AccountPeriod Credits” when ap : AccountPeriod() acc : Account() cf : CashFlow( type == CREDIT, accountNo == acc.accountNo, date >= ap.start && <= ap.end ) then acc.balance += cf.amount; end 29 acc.balance += cf.amount CashFlow Rule Monday, 2 September 13
  30. 30. 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 rule “increase balance for AccountPeriod Credits” when ap : AccountPeriod() acc : Account() cf : CashFlow( type == CREDIT, accountNo == acc.accountNo, date >= ap.start && <= ap.end ) then acc.balance += cf.amount; end 30 acc.balance += cf.amount CashFlow Rule Monday, 2 September 13
  31. 31. 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 rule “increase balance for AccountPeriod Credits” when ap : AccountPeriod() acc : Account() cf : CashFlow( type == CREDIT, accountNo == acc.accountNo, date >= ap.start && <= ap.end ) then acc.balance += cf.amount; end 31 acc.balance += cf.amount CashFlow Rule Monday, 2 September 13
  32. 32. 32 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-Mar-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-Mar-12 75 CREDIT 1 CashFlowCashFlowCashFlowCashFlow date amount type accountNo 2-Feb-12 200 DEBIT 1 AccountAccount accountNo balance 1 -25 CashFlow Example Monday, 2 September 13
  33. 33. 33 rule "Print blance for AccountPeriod" salience -50 when ap : AccountPeriod() acc : Account( ) then System.out.println( "Account Number " + acc.accountNo + " balance " + acc.balance ); end AgendaAgendaAgenda 1 increase balance arbitrary2 decrease balance arbitrary 3 increase balance arbitrary 4 print balance CashFlow Example Monday, 2 September 13
  34. 34. Timers Monday, 2 September 13
  35. 35. Timers Monday, 2 September 13
  36. 36. CEP Monday, 2 September 13
  37. 37. Graphical Metaphores Monday, 2 September 13
  38. 38. Graphical Metaphores • Decision Tables • Guided Editors • Rule Templates • Guided Editor + Decision Table • Score Cards • Decision Trees • We don’t do these yet Monday, 2 September 13
  39. 39. Decision Table Monday, 2 September 13
  40. 40. Decision Table Monday, 2 September 13
  41. 41. Guided Editors Monday, 2 September 13
  42. 42. Rule Templates Monday, 2 September 13
  43. 43. Rule Templates Monday, 2 September 13
  44. 44. Decision Table Wizards Monday, 2 September 13
  45. 45. Score Cards • a) Setup Parameters • b) Characteristic Section Monday, 2 September 13
  46. 46. Score Cards • 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, 2 September 13
  47. 47. Scenarios Monday, 2 September 13
  48. 48. Decision Trees Monday, 2 September 13
  49. 49. Decision Tables Monday, 2 September 13
  50. 50. Decision Table Monday, 2 September 13
  51. 51. Decision Table Monday, 2 September 13
  52. 52. Decision Table Monday, 2 September 13
  53. 53. Decision Table Monday, 2 September 13
  54. 54. Decision Table Monday, 2 September 13
  55. 55. Decision Table Monday, 2 September 13
  56. 56. Decision Table Monday, 2 September 13
  57. 57. Decision Table Monday, 2 September 13
  58. 58. Decision Table Monday, 2 September 13
  59. 59. Decision Table Monday, 2 September 13
  60. 60. Workbench OpenShift Ready Monday, 2 September 13
  61. 61. 5.x Critique Monday, 2 September 13
  62. 62. 5.x Critique UI • GWT • but not easily extended • fixed layouts • no perspectives Monday, 2 September 13
  63. 63. 5.x Critique UI • GWT • but not easily extended • fixed layouts • no perspectives JCR • Performance Issues • Everything stored as blob • No tagging, branching etc. • Webdav • Limited team providers Monday, 2 September 13
  64. 64. 5.x Critique UI • GWT • but not easily extended • fixed layouts • no perspectives JCR • Performance Issues • Everything stored as blob • No tagging, branching etc. • Webdav • Limited team providers Deployment • Binary blobs, on url Monday, 2 September 13
  65. 65. 5.x Critique Content • 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 Monday, 2 September 13
  66. 66. 5.x CritiqueDeployment •Simple Snapshot system •No real methodology •Doesn’t align with any industry standards Monday, 2 September 13
  67. 67. UF UberFire Monday, 2 September 13
  68. 68. Requirements • Modular design • Plugins • Common Life cycles • Compile time composition of plugins, via maven • Menus • contextual to perspective and focus panel • Visibility Security • Toolbars • contextual to perspective and focus panel • Visibility Security • Twitter Bootstrap UI • Flexible layouts • Perspectives Monday, 2 September 13
  69. 69. Requirements • Security • Authorization, Authentication • Seamless API for client and server • MetaData • Everything is a file, DB just for fast searching • GIT Backend • High Availability • GIT Cluster • Apache Helix • Maven integration for “projects” Monday, 2 September 13
  70. 70. UberFire Architecture Overview Monday, 2 September 13
  71. 71. KIE - Knowledge Is Everything Monday, 2 September 13
  72. 72. KIE - Knowledge Is Everything Monday, 2 September 13
  73. 73. KIE - Knowledge Is Everything Monday, 2 September 13
  74. 74. Workbench Screens Monday, 2 September 13
  75. 75. Workbench Screens • Workbench Screen • DIV • Lifecycle events • OnStartUp, OnShutDown • OnOpen, OnMayClose, OnClose • OnFocus, OnLostFocus Monday, 2 September 13
  76. 76. Workbench Screens @WorkbenchScreen(identifier = "MyFirstPanel") public class MyFirstPanel extends SimplePanel { public MyFirstPanel() { setWidget( new Label("Hello World 1") ); } @WorkbenchPartTitle public String myTitle() { return "My First Panel!"; } } Monday, 2 September 13
  77. 77. Workbench Editor Monday, 2 September 13
  78. 78. Workbench Editor • Workbench Screen • DIV • Lifecycle events • OnStartUp, OnShutDown • OnOpen, OnMayClose, OnClose • OnFocus, OnLostFocus • IsDirty, OnSave Monday, 2 September 13
  79. 79. Life Cycle Annotation @WorkbenchEditor(identifier = "TextEditor", supportedTypes = { TextResourceType.class, DotResourceType.class }) public class TextEditorPresenter { (...) @OnStart public void onStart( final Path path ) { this.path = path; } @OnSave public void onSave() { } @IsDirty public boolean isDirty() { return view.isDirty(); } } Monday, 2 September 13
  80. 80. Life Cycle Annotation @WorkbenchEditor(identifier = "TextEditor", supportedTypes = { TextResourceType.class, DotResourceType.class }) public class TextEditorPresenter { (...) @OnStart public void onStart( final Path path ) { this.path = path; } @OnSave public void onSave() { } @IsDirty public boolean isDirty() { return view.isDirty(); } } Monday, 2 September 13
  81. 81. Workbench Perspective Monday, 2 September 13
  82. 82. Workbench Perspective $registerPerspective({ "id": "Markdown Editor", "view": { "parts": [ { "place": "MarkdownLiveViewer", "parameters": {} } ], "panels": [ { "width": 600, "min_width": 300, "position": "west", "parts": [ { "place": "MarkdownLiveEditor", "parameters": {} } ] } ] }, on_close: function () { } }); Monday, 2 September 13
  83. 83. Simple POM Editor Monday, 2 September 13
  84. 84. Build and Deploy Monday, 2 September 13
  85. 85. Local Maven Repository and Manager Monday, 2 September 13
  86. 86. Create or Clone Git Repos Monday, 2 September 13
  87. 87. 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 Monday, 2 September 13
  88. 88. BPM Integration Monday, 2 September 13
  89. 89. Work - Task Lists Monday, 2 September 13
  90. 90. Work - Task Lists Monday, 2 September 13
  91. 91. Work - Task Lists Monday, 2 September 13
  92. 92. Work - Task Lists Monday, 2 September 13
  93. 93. Work - Task Lists Monday, 2 September 13
  94. 94. Work - Task Lists Monday, 2 September 13
  95. 95. BPMN Designer (JS) Monday, 2 September 13
  96. 96. BRMS 6.0 Simplified Utilization Monday, 2 September 13
  97. 97. BRMS 5.0 Programmatic API 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, 2 September 13
  98. 98. 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 Monday, 2 September 13
  99. 99. 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 Monday, 2 September 13
  100. 100. Git Hub Examples• https://github.com/droolsjbpm/drools/tree/master/drools- examples-api Monday, 2 September 13
  101. 101. KieModules <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, 2 September 13
  102. 102. 102 Monday, 2 September 13
  103. 103. KieModules • Named Entities and JAR on Classpath • Creates one KieBase • Includes resources from package matching kbase name <kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule"> <kbase name="kbase1"> <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, 2 September 13
  104. 104. 104 Monday, 2 September 13
  105. 105. KieModules • Named Entities, with inheritence and JAR on Classpath • Two projects, one “includes” from the other <dependency> <groupId>org.drools</groupId> <artifactId>named-kiesession</artifactId> <version>6.0.0-SNAPSHOT</version> </dependency> <kbase name="kbase2" includes="kbase1"> <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, 2 September 13
  106. 106. KieModules • Package location can over-ride kbase name defaults <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, 2 September 13
  107. 107. Dynamic KieModules • JARs can be loaded from URLs into KieRepository • Once loaded they can be resolved via ReleaseId 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, 2 September 13
  108. 108. Dynamic KieModules • kie-ci use embedded maven for remote discovery <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, 2 September 13
  109. 109. Dynamic KieModules // 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, 2 September 13
  110. 110. kmodule.xml Editor Monday, 2 September 13
  111. 111. Programmatic API • Builder API, for tooling integration • Incremental compilation, and problem reporting 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, 2 September 13
  112. 112. BRMS 6.0 CDI Monday, 2 September 13
  113. 113. CDI Context and Dependency • CDI injects named entities from the kmodule.xml • Injectable types • KieServices • KieContainer • KieBase • KieSession • StatelessKieSession Monday, 2 September 13
  114. 114. KBase @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, 2 September 13
  115. 115. KSession @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, 2 September 13
  116. 116. BRMS 6.0 Spring and Camel Monday, 2 September 13
  117. 117. Spring and Camel <kie:kmodule id="CxfRsSpring"> <kie:kbase name="test1" packages="test1"> <kie:ksession name="ksession1"> <kie:batch> <kie:set-global identifier="list" > <bean class="java.util.ArrayList" /> </kie:set-global> </kie:batch> </kie:ksession> <kie:ksession name="ksession2"/> </kie:kbase> </kie:kmodule> Monday, 2 September 13
  118. 118. Spring and Camel <bean id="kiePolicy" class="org.kie.camel.component.KiePolicy" /> <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="cxfrs://bean://rsServer"/> <policy ref="kiePolicy"> <unmarshal ref="xstream" /> <to uri="kie:ksession1" /> <marshal ref="xstream" /> </policy> </route> <route id="x1"> <from uri="direct://http"/> <policy ref="kiePolicy"> <to uri="cxfrs://http://localhost:58001/rest"/> </policy> </route> </camelContext> Monday, 2 September 13
  119. 119. BRMS 6.0 R.I.P Rete Monday, 2 September 13
  120. 120. 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 Monday, 2 September 13
  121. 121. Backward Chaining Reactive Transitive Closures Monday, 2 September 13
  122. 122. 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, 2 September 13
  123. 123. 123 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, 2 September 13
  124. 124. Backward Chaining 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, 2 September 13
  125. 125. Backward Chainingrule "go" salience 10 when $s : String( ) then System.out.println( $s ); 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, 2 September 13
  126. 126. Backward Chainingrule "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 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, 2 September 13
  127. 127. Backward Chainingrule "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 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, 2 September 13
  128. 128. Backward Chainingrule "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 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, 2 September 13
  129. 129. Backward Chainingrule "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 isContainedIn(x==Office, y==House) 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, 2 September 13
  130. 130. Backward Chainingrule "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 Location(x==Office, y==House) 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") isContainedIn(x==Office, y==House) Monday, 2 September 13
  131. 131. Backward Chaining rule "go2" when String( this == "go2" ) isContainedIn("Draw", "House"; ) then System.out.println( "Draw in the House" ); 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, 2 September 13
  132. 132. Backward Chaining rule "go2" when String( this == "go2" ) isContainedIn("Draw", "House"; ) then System.out.println( "Draw in the House" ); end 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, 2 September 13
  133. 133. Backward Chaining rule "go2" when String( this == "go2" ) isContainedIn("Draw", "House"; ) then System.out.println( "Draw in the House" ); end query isContainedIn( String x, String y ) Location( x, y; ) or ( Location( z, y; ) and isContainedIn( x, z; ) ) end ksession.insert( "go2" ); ksession.fireAllRules(); --- go2 Draw in the House 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, 2 September 13
  134. 134. Backward Chaining rule "go2" when String( this == "go2" ) isContainedIn("Draw", "House"; ) then System.out.println( "Draw in the House" ); end query isContainedIn( String x, String y ) Location( x, y; ) or ( Location( z, y; ) and isContainedIn( x, z; ) ) end isContainedIn(x==Draw, y==House) ksession.insert( "go2" ); ksession.fireAllRules(); --- go2 Draw in the House 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, 2 September 13
  135. 135. Backward Chaining rule "go2" when String( this == "go2" ) isContainedIn("Draw", "House"; ) then System.out.println( "Draw in the House" ); end query isContainedIn( String x, String y ) Location( x, y; ) or ( Location( z, y; ) and isContainedIn( x, z; ) ) end Location(z==Office, y==House) isContainedIn(x==Draw, y==House) ksession.insert( "go2" ); ksession.fireAllRules(); --- go2 Draw in the House 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, 2 September 13
  136. 136. Backward Chaining rule "go2" when String( this == "go2" ) isContainedIn("Draw", "House"; ) then System.out.println( "Draw in the House" ); end query isContainedIn( String x, String y ) Location( x, y; ) or ( Location( z, y; ) and isContainedIn( x, z; ) ) end Location(z==Office, y==House) isContainedIn(x==Draw, z==Office) isContainedIn(x==Draw, y==House) ksession.insert( "go2" ); ksession.fireAllRules(); --- go2 Draw in the House 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, 2 September 13
  137. 137. Backward Chaining rule "go2" when String( this == "go2" ) isContainedIn("Draw", "House"; ) then System.out.println( "Draw in the House" ); end query isContainedIn( String x, String y ) Location( x, y; ) or ( Location( z, y; ) and isContainedIn( x, z; ) ) end Location(z==Office, y==House) isContainedIn(x==Draw, z==Office) Location(z==Kitchen, y==House) isContainedIn(x==Draw, z==Kitchen) isContainedIn(x==Draw, y==House) ksession.insert( "go2" ); ksession.fireAllRules(); --- go2 Draw in the House 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, 2 September 13
  138. 138. Backward Chaining rule "go2" when String( this == "go2" ) isContainedIn("Draw", "House"; ) then System.out.println( "Draw in the House" ); end query isContainedIn( String x, String y ) Location( x, y; ) or ( Location( z, y; ) and isContainedIn( x, z; ) ) end isContainedIn(x==Draw, y==Office) ksession.insert( "go2" ); ksession.fireAllRules(); --- go2 Draw in the House 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, 2 September 13
  139. 139. Backward Chaining rule "go2" when String( this == "go2" ) isContainedIn("Draw", "House"; ) then System.out.println( "Draw in the House" ); end query isContainedIn( String x, String y ) Location( x, y; ) or ( Location( z, y; ) and isContainedIn( x, z; ) ) end Location(z==Desk, y==Office) isContainedIn(x==Draw, y==Office) ksession.insert( "go2" ); ksession.fireAllRules(); --- go2 Draw in the House 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, 2 September 13
  140. 140. Backward Chaining rule "go2" when String( this == "go2" ) isContainedIn("Draw", "House"; ) then System.out.println( "Draw in the House" ); end query isContainedIn( String x, String y ) Location( x, y; ) or ( Location( z, y; ) and isContainedIn( x, z; ) ) end Location(z==Desk, y==Office) isContainedIn(x==Draw, z==Desk) isContainedIn(x==Draw, y==Office) ksession.insert( "go2" ); ksession.fireAllRules(); --- go2 Draw in the House 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, 2 September 13
  141. 141. Backward Chaining rule "go2" when String( this == "go2" ) isContainedIn("Draw", "House"; ) then System.out.println( "Draw in the House" ); end query isContainedIn( String x, String y ) Location( x, y; ) or ( Location( z, y; ) and isContainedIn( x, z; ) ) end isContainedIn(x==Draw, y==Desk) ksession.insert( "go2" ); ksession.fireAllRules(); --- go2 Draw in the House 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, 2 September 13
  142. 142. Backward Chaining rule "go2" when String( this == "go2" ) isContainedIn("Draw", "House"; ) then System.out.println( "Draw in the House" ); end query isContainedIn( String x, String y ) Location( x, y; ) or ( Location( z, y; ) and isContainedIn( x, z; ) ) end Location(x==Draw, y==Desk) isContainedIn(x==Draw, y==Desk) ksession.insert( "go2" ); ksession.fireAllRules(); --- go2 Draw in the House 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, 2 September 13
  143. 143. Backward Chaining rule "go3" when String( this == "go3" ) isContainedIn("Key", "Office"; ) then System.out.println( "Key in the Office" ); 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, 2 September 13
  144. 144. Backward Chaining rule "go3" when String( this == "go3" ) isContainedIn("Key", "Office"; ) then System.out.println( "Key in the Office" ); end ksession.insert( "go3" ); ksession.fireAllRules(); --- go3 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, 2 September 13
  145. 145. Backward Chaining 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 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, 2 September 13
  146. 146. 6.0 JTMS (exp) Monday, 2 September 13
  147. 147. Justification-based Truth • 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 (exp) • Defeasible Logic (exp) • See drools-compiler • JTMSTest for lots of example tests Monday, 2 September 13
  148. 148. 148 JTMS Couples the logic What happens when the Child stops being 16? 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 Monday, 2 September 13
  149. 149. JTMS • Bad • Monolithic • Leaky • Brittle integrity - manual maintenance Monday, 2 September 13
  150. 150. 150 JTMS de-couples the logic Maintains the truth by automatically retracting •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 Monday, 2 September 13
  151. 151. 151 JTMS The truth maintenance cascades 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 Monday, 2 September 13
  152. 152. 152 JTMS rule "Issue Child Bus Pass" when $p : Person( ) not( ChildBusPass( person == $p ) ) then requestChildBusPass( $p ); end The truth maintenance cascades Monday, 2 September 13
  153. 153. 153 JTMS • Good • De-couple knowledge responsibilities • Encapsulate knowledge • Provide semantic abstractions for those encapsulation • Integrity robustness – truth maintenance Monday, 2 September 13
  154. 154. JTMS IsChild ChildBusPas Rule : isChildRule Rule : IssueBusPas + + Monday, 2 September 13
  155. 155. JTMS rule "Do not issue to banned people" when $p : Person( ) Banned( person =$p ) then logicalInsert(new ChildBusPass( $p ) , “neg” ); end Monday, 2 September 13
  156. 156. JTMS IsChild ChildBusPas Rule : isChildRule Rule : IssueBusPas + + Rule : Do Not Issue to Banned People - Monday, 2 September 13
  157. 157. 6.0 Defeasible (exp) Monday, 2 September 13
  158. 158. Defeasible rule "All Birds Fly" when $b : Bird( ) then logicalInsert(new Fly( $b ) ); end rule "Brocken wing" when $b : Bird( ) BrockenWing($b;) then logicalInsert(new Fly( $b ), “neg” ); end Monday, 2 September 13
  159. 159. Defeasible rule "All Birds Fly" @Defeasible when $b : Bird( ) then logicalInsert(new Fly( $b ) ); end rule "Brocken wing" @Defeasible @Defeater when $b : Bird( ) BrockenWing($b;) then logicalInsert(new Fly( $b ), “neg” ); end rule "Birds With Rockets Fly"@Defeasible @Defeats(“Brocken Wing”) when $b : Bird( ) Rocket($b;) then logicalInsert(new Fly( $b ) ); end Monday, 2 September 13
  160. 160. 160 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, 2 September 13

×