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
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.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
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
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
This is a Rule Enginevar 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
These are Rules too
Monday, 2 September 13
What is a Rule
rule <rule_name> <attribute><value> when <conditions> then <actions>end
Monday, 2 September 13
Pattern Matching
Person(age >= 18)field name restriction
constraintobject type
pattern
Monday, 2 September 13
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
Hybrid Reasoning
Monday, 2 September 13
Types of Reasoning
•Production Rule Systems PRD (forward chaining)•Reactive
•when Alarm( status == “alert” ) •then send( “warning” )
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
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
Because Not Everyone Is As Smart As He Is
Monday, 2 September 13
1979 Rete Algorithm by Charles Forgy 23
Monday, 2 September 13
Clips and Jess
Clips 1986
24
Clips 1995
Monday, 2 September 13
Technical Language
Monday, 2 September 13
26
Classes
AccountAccount
long accountNo
int balance
CashFlowCashFlow
Date date
int amount
AccountPeriodAccountPeriod
Date start
Date end
CashFlow Example
Monday, 2 September 13
select * from Account acc, Cashflow cf, AccountPeriod apwhere 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
select * from Account acc, Cashflow cf, AccountPeriod apwhere 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
select * from Account acc, Cashflow cf, AccountPeriod apwhere 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
select * from Account acc, Cashflow cf, AccountPeriod apwhere 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
select * from Account acc, Cashflow cf, AccountPeriod apwhere 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
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
rule "Print blance for AccountPeriod" salience -50when ap : AccountPeriod() acc : Account( )then System.out.println( "Account Number " + acc.accountNo + " balance " + acc.balance );end
• 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
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
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>
// Install example1 in the local maven repo before to do thisKieContainer kContainer = ks.newKieContainer( ks.newReleaseId("org.drools", "named-kiesession", "6.0.0-SNAPSHOT"));
Object msg1 = createMessage(kContainer, "Dave", "Hello, HAL. Do you read me, HAL?");kSession.insert(msg1);kSession.fireAllRules();
Monday, 2 September 13
Dynamic KieModules
// 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");
Monday, 2 September 13
kmodule.xml Editor
Monday, 2 September 13
Programmatic API• Builder API, for tooling integration• Incremental compilation, and problem
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());}
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
Backward ChainingReactive Transitive
Closures
Monday, 2 September 13
Reasoning with GraphsHouse
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
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")
Monday, 2 September 13
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") );
•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
Monday, 2 September 13
151
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
Monday, 2 September 13
152
JTMSrule "Issue Child Bus Pass"when $p : Person( ) not( ChildBusPass( person == $p ) )then requestChildBusPass( $p );end The truth maintenance cascades
Monday, 2 September 13
153
JTMS• Good• De-couple knowledge responsibilities• Encapsulate knowledge• Provide semantic abstractions for those encapsulation• Integrity robustness – truth maintenance
Monday, 2 September 13
JTMS
IsChild
ChildBusPas
Rule : isChildRule
Rule : IssueBusPas
+
+
Monday, 2 September 13
JTMSrule "Do not issue to banned people"when $p : Person( ) Banned( person =$p )then logicalInsert(new ChildBusPass( $p ) , “neg” );end
• 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?