Drools 6.0 (JudCon 2013)

106
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 Saturday, 29 June 13

description

 

Transcript of Drools 6.0 (JudCon 2013)

Page 1: Drools 6.0 (JudCon 2013)

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

Saturday, 29 June 13

Page 2: Drools 6.0 (JudCon 2013)

Who am I?

• Drools co-founder

• JBoss (2005)

• Red Hat (2006)

• Polymita Acquisition 2012

• Red Hat Platform Architect

Saturday, 29 June 13

Page 3: Drools 6.0 (JudCon 2013)

KIE - Knowledge Is EverythingKIE

Drools jBPMOptaPlanner UberFire

Guvnor

Drools-WB jBPM-WB

KIE-WB

Saturday, 29 June 13

Page 5: Drools 6.0 (JudCon 2013)

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

Saturday, 29 June 13

Page 6: Drools 6.0 (JudCon 2013)

BRMS 6.0Simplified Utilization

Saturday, 29 June 13

Page 7: Drools 6.0 (JudCon 2013)

BRMS 5.0 Programmatic APIKnowledgeBuilder 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();

Saturday, 29 June 13

Page 8: Drools 6.0 (JudCon 2013)

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

Saturday, 29 June 13

Page 10: Drools 6.0 (JudCon 2013)

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();

Saturday, 29 June 13

Page 11: Drools 6.0 (JudCon 2013)

11

Saturday, 29 June 13

Page 12: Drools 6.0 (JudCon 2013)

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();

Saturday, 29 June 13

Page 13: Drools 6.0 (JudCon 2013)

13

Saturday, 29 June 13

Page 14: Drools 6.0 (JudCon 2013)

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();

Saturday, 29 June 13

Page 15: Drools 6.0 (JudCon 2013)

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");

Saturday, 29 June 13

Page 16: Drools 6.0 (JudCon 2013)

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();

Saturday, 29 June 13

Page 17: Drools 6.0 (JudCon 2013)

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 thisKieContainer 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();

Saturday, 29 June 13

Page 18: Drools 6.0 (JudCon 2013)

Dynamic Modules

// create a new kjarInternalKieModule kJar2 = createKieJar(ks, releaseId, "rule2", "rule3");

// deploy it on mavenrepository.deployArtifact(releaseId, kJar2, kPom);

// since I am not calling start() on the scanner it means it won't have automatic scheduled scanningKieScanner scanner = ks.newKieScanner(kieContainer);

// scan the maven repo to get the new kjar version and deploy it on the kcontainerscanner.scanNow();

// create a ksesion and check it works as expectedKieSession ksession2 = kieContainer.newKieSession("KSession1");checkKSession(ksession2, "rule2", "rule3");

Saturday, 29 June 13

Page 19: Drools 6.0 (JudCon 2013)

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");

Saturday, 29 June 13

Page 20: Drools 6.0 (JudCon 2013)

kmodule.xml Editor

Saturday, 29 June 13

Page 21: Drools 6.0 (JudCon 2013)

Programmatic API• Builder API, for tooling integration• Incremental compilation, and problem

reportingKieServices 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();

Saturday, 29 June 13

Page 22: Drools 6.0 (JudCon 2013)

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 thisKieContainer 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();

Saturday, 29 June 13

Page 23: Drools 6.0 (JudCon 2013)

BRMS 6.0 CDI

Saturday, 29 June 13

Page 24: Drools 6.0 (JudCon 2013)

CDI Context and Dependency • CDI injects named entities from the

kmodule.xml

• Injectable types• KieServices• KieContainer• KieBase• KieSession• StatelessKieSession

Saturday, 29 June 13

Page 25: Drools 6.0 (JudCon 2013)

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;

@Injectprivate 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;

Saturday, 29 June 13

Page 26: Drools 6.0 (JudCon 2013)

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;

Saturday, 29 June 13

Page 27: Drools 6.0 (JudCon 2013)

BRMS 6.0 Spring and Camel

Saturday, 29 June 13

Page 28: Drools 6.0 (JudCon 2013)

Spring and Camel

Saturday, 29 June 13

Page 29: Drools 6.0 (JudCon 2013)

Spring and Camel

Saturday, 29 June 13

Page 30: Drools 6.0 (JudCon 2013)

Spring and Camel

Saturday, 29 June 13

Page 31: Drools 6.0 (JudCon 2013)

Spring and Camel

Saturday, 29 June 13

Page 32: Drools 6.0 (JudCon 2013)

Backward ChainingReactive Transitive

Closures

Saturday, 29 June 13

Page 33: Drools 6.0 (JudCon 2013)

33

Reasoning with Graphs

●Location( “kitchen”,”house” )●Location( “office”,”house” )

●Location( “desk”,”office” ) ●Location( “chair”,”office” )

●Location( “lamp”,”desk” )

●Location( “draw”,”desk” )

●Location( “computer”,”desk” )

●Location( “key”,”draw” )

House

Saturday, 29 June 13

Page 34: Drools 6.0 (JudCon 2013)

34

Backward Chainingquery isContainedIn( String x, String y ) Location( x, y; ) or ( Location( z, y; ) and isContainedIn( x, z; ) )end

House

Location("Office", "House ")

Location("Kitchen", "House")

Location("Desk", "Office")

Location("Chair", "Office")

Location("Computer", "Desk")

Location("Draw", "Desk")

Location("Knife", "Kitchen")

Location("Cheese", "Kitchen")

Location("Key", "Draw")

Saturday, 29 June 13

Page 35: Drools 6.0 (JudCon 2013)

Backward Chainingksession.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")

Saturday, 29 June 13

Page 36: Drools 6.0 (JudCon 2013)

Backward Chainingrule "go" salience 10when $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")

Saturday, 29 June 13

Page 37: Drools 6.0 (JudCon 2013)

Backward Chainingrule "go1"when String( this == "go1" ) isContainedIn("Office", "House"; )then System.out.println( "office is in the house" );end

rule "go" salience 10when $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")

Saturday, 29 June 13

Page 38: Drools 6.0 (JudCon 2013)

Backward Chainingrule "go1"when String( this == "go1" ) isContainedIn("Office", "House"; )then System.out.println( "office is in the house" );end

rule "go" salience 10when $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")

Saturday, 29 June 13

Page 39: Drools 6.0 (JudCon 2013)

Backward Chainingrule "go1"when String( this == "go1" ) isContainedIn("Office", "House"; )then System.out.println( "office is in the house" );end

rule "go" salience 10when $s : String( )then System.out.println( $s );end

ksession.insert( "go1" );ksession.fireAllRules();---go1office 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")

Saturday, 29 June 13

Page 40: Drools 6.0 (JudCon 2013)

Backward Chainingrule "go1"when String( this == "go1" ) isContainedIn("Office", "House"; )then System.out.println( "office is in the house" );end

rule "go" salience 10when $s : String( )then System.out.println( $s );end

ksession.insert( "go1" );ksession.fireAllRules();---go1office 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")

Saturday, 29 June 13

Page 41: Drools 6.0 (JudCon 2013)

Backward Chainingrule "go1"when String( this == "go1" ) isContainedIn("Office", "House"; )then System.out.println( "office is in the house" );end

rule "go" salience 10when $s : String( )then System.out.println( $s );end

ksession.insert( "go1" );ksession.fireAllRules();---go1office 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)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")

Saturday, 29 June 13

Page 42: Drools 6.0 (JudCon 2013)

Backward Chainingrule "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")

Saturday, 29 June 13

Page 43: Drools 6.0 (JudCon 2013)

Backward Chainingrule "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")

Saturday, 29 June 13

Page 44: Drools 6.0 (JudCon 2013)

Backward Chainingrule "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();---go2Draw 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")

Saturday, 29 June 13

Page 45: Drools 6.0 (JudCon 2013)

Backward Chainingrule "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();---go2Draw 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")

Saturday, 29 June 13

Page 46: Drools 6.0 (JudCon 2013)

Backward Chainingrule "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();---go2Draw 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")

Saturday, 29 June 13

Page 47: Drools 6.0 (JudCon 2013)

Backward Chainingrule "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();---go2Draw 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")

Saturday, 29 June 13

Page 48: Drools 6.0 (JudCon 2013)

Backward Chainingrule "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();---go2Draw 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")

Saturday, 29 June 13

Page 49: Drools 6.0 (JudCon 2013)

Backward Chainingrule "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();---go2Draw 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")

Saturday, 29 June 13

Page 50: Drools 6.0 (JudCon 2013)

Backward Chainingrule "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();---go2Draw 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")

Saturday, 29 June 13

Page 51: Drools 6.0 (JudCon 2013)

Backward Chainingrule "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();---go2Draw 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")

Saturday, 29 June 13

Page 52: Drools 6.0 (JudCon 2013)

Backward Chainingrule "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();---go2Draw 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")

Saturday, 29 June 13

Page 53: Drools 6.0 (JudCon 2013)

Backward Chainingrule "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();---go2Draw 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")

Saturday, 29 June 13

Page 54: Drools 6.0 (JudCon 2013)

Backward Chainingrule "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")

Saturday, 29 June 13

Page 55: Drools 6.0 (JudCon 2013)

Backward Chainingrule "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")

Saturday, 29 June 13

Page 56: Drools 6.0 (JudCon 2013)

Backward Chainingrule "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")

Saturday, 29 June 13

Page 57: Drools 6.0 (JudCon 2013)

Backward Chainingrule "go4"when String( this == "go4" ) isContainedIn(thing, "Office"; )then System.out.println( "thing " + thing + " is 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")

Saturday, 29 June 13

Page 58: Drools 6.0 (JudCon 2013)

Backward Chainingrule "go4"when String( this == "go4" ) isContainedIn(thing, "Office"; )then System.out.println( "thing " + thing + " is in the Office" );end

Out

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")

Saturday, 29 June 13

Page 59: Drools 6.0 (JudCon 2013)

Backward Chainingrule "go4"when String( this == "go4" ) isContainedIn(thing, "Office"; )then System.out.println( "thing " + thing + " is in the Office" );end

ksession.insert( "go4" );ksession.fireAllRules();---go4thing Key is in the Officething Computer is in the Officething Draw is in the Officething Desk is in the Officething Chair is in the Office

Out

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")

Saturday, 29 June 13

Page 60: Drools 6.0 (JudCon 2013)

Backward Chainingrule "go5"when String( this == "go5" ) isContainedIn(thing, location; )then System.out.println( "thing " + thing + " is in " + location );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")

Saturday, 29 June 13

Page 61: Drools 6.0 (JudCon 2013)

Backward Chainingrule "go5"when String( this == "go5" ) isContainedIn(thing, location; )then System.out.println( "thing " + thing + " is in " + location );end

Out

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")

Saturday, 29 June 13

Page 62: Drools 6.0 (JudCon 2013)

Backward Chainingrule "go5"when String( this == "go5" ) isContainedIn(thing, location; )then System.out.println( "thing " + thing + " is in " + location );end

Out Out

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")

Saturday, 29 June 13

Page 63: Drools 6.0 (JudCon 2013)

Backward Chainingrule "go5"when String( this == "go5" ) isContainedIn(thing, location; )then System.out.println( "thing " + thing + " is in " + location );end

ksession.insert( "go5" );ksession.fireAllRules();---go5thing Knife is in Housething Cheese is in Housething Key is in Housething Computer is in Housething Draw is in Housething Desk is in Housething Chair is in Housething Key is in Office

thing Computer is in Officething Draw is in Officething Key is in Desk

thing Office is in House

Out Out

thing Computer is in Deskthing Knife is in Kitchenthing Cheese is in Kitchenthing Kitchen is in House

thing Key is in Drawthing Draw is in Desk

thing Desk is in Officething 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")

Saturday, 29 June 13

Page 64: Drools 6.0 (JudCon 2013)

BRMS 6.0 Score Cards

Saturday, 29 June 13

Page 65: Drools 6.0 (JudCon 2013)

Score Cards• a) Setup Parameters• b) Characteristic Section

Saturday, 29 June 13

Page 66: Drools 6.0 (JudCon 2013)

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

Saturday, 29 June 13

Page 67: Drools 6.0 (JudCon 2013)

6.0 JTMS

Saturday, 29 June 13

Page 68: Drools 6.0 (JudCon 2013)

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.• Defeasible Logic soon

• See drools-compiler• JTMSTest for lots of example tests

Saturday, 29 June 13

Page 69: Drools 6.0 (JudCon 2013)

69

JTMSCouples 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 ) );endrule "Issue Adult Bus Pass"when $p : Person( age >= 16 )then insert(new AdultBusPass( $p ) );end

Saturday, 29 June 13

Page 70: Drools 6.0 (JudCon 2013)

JTMS• Bad• Monolithic• Leaky• Brittle integrity - manual maintenance

Saturday, 29 June 13

Page 71: Drools 6.0 (JudCon 2013)

71

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 ) )endrule "IsAdult"when $p : Person( age >= 16 )then logicalInsert( new IsAdult( $p ) )end

Saturday, 29 June 13

Page 72: Drools 6.0 (JudCon 2013)

72

JTMS

The truth maintenance cascades

rule "Issue Child Bus Pass"when $p : Person( ) IsChild( person =$p )then logicalInsert(new ChildBusPass( $p ) );endrule "Issue Adult Bus Pass"when $p : Person() IsAdult( person =$p )then logicalInsert(new AdultBusPass( $p ) );end

Saturday, 29 June 13

Page 73: Drools 6.0 (JudCon 2013)

73

JTMSrule "Issue Child Bus Pass"when $p : Person( ) not( ChildBusPass( person == $p ) )then requestChildBusPass( $p );end The truth maintenance cascades

Saturday, 29 June 13

Page 74: Drools 6.0 (JudCon 2013)

74

JTMS• Good• De-couple knowledge responsibilities• Encapsulate knowledge• Provide semantic abstractions for those encapsulation• Integrity robustness – truth maintenance

Saturday, 29 June 13

Page 75: Drools 6.0 (JudCon 2013)

JTMS

IsChild

ChildBusPas

Rule : isChildRule

Rule : IssueBusPas

+

+

Saturday, 29 June 13

Page 76: Drools 6.0 (JudCon 2013)

JTMSrule "Do not issue to banned people"when $p : Person( ) Banned( person =$p )then logicalInsert(new ChildBusPass( $p ) , “neg” );end

Saturday, 29 June 13

Page 77: Drools 6.0 (JudCon 2013)

JTMS

IsChild

ChildBusPas

Rule : isChildRule

Rule : IssueBusPas

+

+

Rule : Do Not Issue to Banned People

-

Saturday, 29 June 13

Page 78: Drools 6.0 (JudCon 2013)

BRMS 6.0R.I.P Rete

Saturday, 29 June 13

Page 79: Drools 6.0 (JudCon 2013)

R.I.P RETEinspirations:• 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

Saturday, 29 June 13

Page 80: Drools 6.0 (JudCon 2013)

BRMS 6.0UI - OpenShift Ready

Saturday, 29 June 13

Page 81: Drools 6.0 (JudCon 2013)

5.x Critique

Saturday, 29 June 13

Page 82: Drools 6.0 (JudCon 2013)

5.x CritiqueUI

• GWT• but not easily extended• fixed layouts• no perspectives

Saturday, 29 June 13

Page 83: Drools 6.0 (JudCon 2013)

5.x CritiqueUI

• GWT• but not easily extended• fixed layouts• no perspectives

JCR• Performance Issues• Everything stored as blob• No tagging, branching etc.• Webdav• Limited team providers

Saturday, 29 June 13

Page 84: Drools 6.0 (JudCon 2013)

5.x CritiqueUI

• 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

Saturday, 29 June 13

Page 85: Drools 6.0 (JudCon 2013)

5.x CritiqueContent• 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

Saturday, 29 June 13

Page 86: Drools 6.0 (JudCon 2013)

5.x CritiqueDeployment

•Simple Snapshot system

•No real methodology

•Doesn’t align with any industry standards

Saturday, 29 June 13

Page 87: Drools 6.0 (JudCon 2013)

UF UberFire

Saturday, 29 June 13

Page 88: Drools 6.0 (JudCon 2013)

Requirements• GWT + Errai• Modular design

• Plugins• Common Life cycles

• Compile time composition of plugins, via maven• Flexible layouts• Perspectives• GIT Backend• High Availability• Maven integration for “projects”

Saturday, 29 June 13

Page 89: Drools 6.0 (JudCon 2013)

UberFire Architecture Overview

Saturday, 29 June 13

Page 90: Drools 6.0 (JudCon 2013)

Saturday, 29 June 13

Page 91: Drools 6.0 (JudCon 2013)

•Modular•Extensible

•Dynamic and Flexible layouts•Perspectives

Saturday, 29 June 13

Page 92: Drools 6.0 (JudCon 2013)

Simple POM Editor

Saturday, 29 June 13

Page 93: Drools 6.0 (JudCon 2013)

Build and Deploy

Saturday, 29 June 13

Page 94: Drools 6.0 (JudCon 2013)

Local Maven Repository and Manager

Saturday, 29 June 13

Page 95: Drools 6.0 (JudCon 2013)

Create or Clone Git Repos

Saturday, 29 June 13

Page 96: Drools 6.0 (JudCon 2013)

KIE - Knowledge Is Everything

Saturday, 29 June 13

Page 97: Drools 6.0 (JudCon 2013)

KIE - Knowledge Is Everything

Saturday, 29 June 13

Page 98: Drools 6.0 (JudCon 2013)

KIE - Knowledge Is Everything

Saturday, 29 June 13

Page 99: Drools 6.0 (JudCon 2013)

Community Beta3Demo

Saturday, 29 June 13

Page 100: Drools 6.0 (JudCon 2013)

UI Improvments

Saturday, 29 June 13

Page 101: Drools 6.0 (JudCon 2013)

UberFire new Navigation System

Saturday, 29 June 13

Page 102: Drools 6.0 (JudCon 2013)

UberFire new Navigation System

Saturday, 29 June 13

Page 103: Drools 6.0 (JudCon 2013)

UberFire new Navigation System

Saturday, 29 June 13

Page 104: Drools 6.0 (JudCon 2013)

UberFire new Navigation System

Saturday, 29 June 13

Page 105: Drools 6.0 (JudCon 2013)

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

Saturday, 29 June 13

Page 106: Drools 6.0 (JudCon 2013)

107

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?

Saturday, 29 June 13