SlideShare a Scribd company logo
1 of 39
Download to read offline
 
                               
Drools5 Community Training
      Sponsored by Plugtree
Module 3: Drools Expert 
     DRL Syntax
   Drools5 Community Training
      version: 1.0-SNAPSHOT
     Release Date: 03/16/2011
Under The Creative Common License
Module 3: Drools Expert 
      DRL Syntax
 Drools5 Community Training Course
  by Mauricio "Salaboy" Salatino and
  Esteban Aliverti is licensed under a
  Creative Commons Attribution 3.0
            Unported License.
Based on a work at salaboy.wordpress.
                  com.
 Permissions beyond the scope of this
   license may be available at http:
       //salaboy.wordpress.com/.
Agenda

● Introduction to Drools Expert
● Drools DRL syntax introduction
    ○ LHS Conditional Elements
    ○ RHS
    ○ Rules attributes
    ○ Queries
● Drools 5.x APIs introduction
Drools Expert Introduction

● Drools Expert is the rule engine core
● Lets us express Business Rules
● It will be in charge of making inferences to get new
  conclusions
Components interaction
Rules Execution Cycle 
Business Rule Structure
package ...
import ...
global ...

rule "My Rule"
    <Attributes>
    when <LHS>
        Song(genre == "Jazz") <CEs>
    then <RHS>
        System.out.println("Hi John!");
end
LHS - Conditional Elements

● Pattern



● e.g.
Song(genre == "Jazz")
$song: Song(genre == "Jazz" || == "Avantgarde")
$song: Song(duration > 360, $genre: genre == "Jazz")
LHS - Conditional Elements

● Field Operators



● e.g.

Song( lyrics matches "AZ-az[drink]" )
Song( authors contains "John Zorn" )
Song( author memberof $greatMusicians )
LHS - Conditional Elements

● AND



  e.g. Person( name == "John" ) AND Pet(type == "cat")
● OR


 e.g. Policewoman (age > 30) OR Fireman(age > 31)
LHS - Conditional Elements

● eval



  e.g. eval( song.isJazz() )
● not


 e.g. not( Song( genre == "Pop") )
LHS - Conditional Elements

● exists



  e.g. exists ( Song(genre == "Jazz"))
● forall


 e.g. forall ( Song()
       Song(genre == "Jazz") )
LHS - Conditional Elements

from CE


 ● e.g.
  $playlist: Playlist()
  Song() from $playlist.songs

  $playlist: Playlist()
  Song(genre == "Jazz") from $playlist.songs
LHS - Conditional Elements

● from


● e.g.
  global HibernateSession hbn;

 $playlist: Playlist()
 Song() from hbn.namedQuery("SongByArtist")
                 .setParameter("artist","John Zorn")
                 .getResultList();
LHS - Conditional Elements

● Collect




● e.g.
  $songs: ArrayList() from collect
       (Song(genre == "Jazz", year > 2000))
LHS - Conditional Elements

● Accumulate
LHS - Conditional Elements
 ● Accumulate CE:
<result pattern> from accumulate( <source pattern>,
                           init( <init code> ),
                           action( <action code> ),
                           reverse( <reverse code> ),
                           result( <result expression>))
 ● e.g.
 $playlist: Playlist()
 $jazzSongs: Number( doubleValue > 100 ) from
       accumulate( Song(playlist == $playlist, genre == "Jazz"),
                   init( double total = 0; ),
                   action( total += 1; ),
                   reverse( total -= 1; ),
                   result( total ))
LHS - Conditional Elements

 ● Accumulate Function Examples
  $playlist: Playlist()
  $total: Number( doubleValue > 100 )
from                         accumulate(
                  $song: Song(
                    playlist == $playlist,
                    genre == "Jazz"),
                 count($song))
LHS - Conditional Elements


● Accumulate out-of-the-box Functions
   ○ average
   ○ min
   ○ max
   ○ count
   ○ sum
LHS - Conditional Elements

● Accumulate custom function
$playlist: Playlist()
 $total: Number( doubleValue > 100 ) from
             accumulate( $song: Song(
                         playlist == $playlist),
                         myCustomFc($song.duration))


● We can plug our custom function here. We just need to
  implement the AccumulateFunction interface.
Nesting CEs
● Drools support nested CEs

  $petshop: PetShop()
  $total: Number( doubleValue > 10 ) from accumulate(
          $pet: Pet(petshop == $petshop,
                type == PetType.Cat)
       from $hbm.getNamedQuery("getPetsFromPetshopId")
          .setParamenter("petshopid",$petshop.getId())
          .list(), count ($pet) )
Right Hand Side
● Set of actions
● MVEL or Java (http://mvel.codehaus.org/)
● We will have a set of methods to modify the working
  memory status
   ○ insert()
   ○ modify() / update ()
   ○ retract()
           rule "Fire ! ! !"
               when
                    Fire()
               then
                    insert(new Alarm());
           end
Rule Attributes
Rule Attributes - no loop

● no-loop

i.e.
  rule "infinite activation loop"
      no-loop true
      when
           $person: Person(age > 21)
      then
           update($person){
               setName("John");
           }
  end
Rule Attributes - salience
 ● salience (higher priority first)
rule "rule with priority"
    salience 10
    when
         $song: Song()
    then
         System.out.println("Rule with higher priority Fired!");
end
rule "rule with less priority"
    salience 5

   when
          $song: Song()
   then
          System.out.println("Rule with lower priority Fired!");
end
Rule Attributes - agenda-group 
rule "Playlist ready"
          agenda-group "Create Playlist"
          when
               Playlist(size == 3)
          then
               //Set the focus to "Play playlist" agenda-group
               kcontext.getKnowledgeRuntime().getAgenda()
               .getAgendaGroup("Play playlist").setFocus();
      end

      rule "Play playlist"
          agenda-group "Play playlist"
          when
               $pl : Playlist()
          then
               $pl.play();
      end
Rule Attributes - lock-on-active

rule "Fill playlist"                rule "Number Songs"
   salience 1                          salience 2
   lock-on-active                      lock-on-active
   agenda-group "Create Playlist"      agenda-group "Create Playlist"
   when                                when
      $pl : Playlist()                    $song : Song()
      $song : Song()                   then
   then                                   modify($song){
      modify($pl){                          setName(
        addSong($song);                        index.getAndIncrement()+
      }                                        "_"+ $song.getName());
end                                       }
                                    end
Queries

Example

 query "Get Persons by Name" (String name)
  Person(name = :name)
end
Drools Expert APIs
KnowledgeBuilder
  KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
// Add our rules
kbuilder.add(new ClassPathResource("rules.drl"), ResourceType.DRL);
//Check for errors during the compilation of the rules
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
   for (KnowledgeBuilderError error : errors) {
         System.err.println(error);
   }
   throw new IllegalArgumentException("Could not parse knowledge.");
 }
KnowledgeBase
  // Create the Knowledge Base
     KnowledgeBase kbase = KnowledgeBaseFactory.
newKnowledgeBase();
  // Add the binary packages (compiled rules) to the Knowledge
Base
     kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
KnowledgeSession
 // Create a StatefulSession using the KnowledgeBase that
 // contains the compiled knowledge
StatefulKnowledgeSession ksession =
                         kbase.newStatefulKnowledgeSession();

// We can add a runtime logger to understand what is going on
// inside the Engine
KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
// Insert a new Fact inside my world
FactHandle myFactHandle = ksession.insert(new Person("Myself"));
// Update a Fact using the FactHandle
ksession.update(myFactHandle, new Person("Salaboy!"));
// Retract/Remove from my world the Fact
ksession.retract(myFactHandle);
Full Picture
Hands on Labs

Projects:
 ● 01 :: Drools Expert Introduction
 ● 02 :: Drools Expert Conditional Elements
 ● 03 :: Drools Expert Rule Attributes
Briefing Up

● Covered Topics:
   ○ Rules Execution Lifecycle
   ○ DRL Syntax
      ■ Conditional Elements in the LHS
      ■ Actions in the RHS
 
              
Questions?
Enjoy! 
Questions and Feedback are always
appreciated!
Stay Tuned!
 
                     
    Contact us at
www.plugtree.com

More Related Content

What's hot

[131]해커의 관점에서 바라보기
[131]해커의 관점에서 바라보기[131]해커의 관점에서 바라보기
[131]해커의 관점에서 바라보기NAVER D2
 
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...PROIDEA
 
Future of HTTP in CakePHP
Future of HTTP in CakePHPFuture of HTTP in CakePHP
Future of HTTP in CakePHPmarkstory
 
New in cakephp3
New in cakephp3New in cakephp3
New in cakephp3markstory
 
Php 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodPhp 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodJeremy Kendall
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8bryanbibat
 
Event Sourcing and Functional Programming
Event Sourcing and Functional ProgrammingEvent Sourcing and Functional Programming
Event Sourcing and Functional ProgrammingGlobalLogic Ukraine
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPJeremy Kendall
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPJeremy Kendall
 
JavaScript Classes and Inheritance
JavaScript Classes and InheritanceJavaScript Classes and Inheritance
JavaScript Classes and Inheritancemarcheiligers
 
Algorithm, Review, Sorting
Algorithm, Review, SortingAlgorithm, Review, Sorting
Algorithm, Review, SortingRowan Merewood
 
Intro to Advanced JavaScript
Intro to Advanced JavaScriptIntro to Advanced JavaScript
Intro to Advanced JavaScriptryanstout
 
Clojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVMClojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVMsunng87
 
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークGroovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークTsuyoshi Yamamoto
 

What's hot (20)

Meetup slides
Meetup slidesMeetup slides
Meetup slides
 
[131]해커의 관점에서 바라보기
[131]해커의 관점에서 바라보기[131]해커의 관점에서 바라보기
[131]해커의 관점에서 바라보기
 
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
 
Future of HTTP in CakePHP
Future of HTTP in CakePHPFuture of HTTP in CakePHP
Future of HTTP in CakePHP
 
はじめてのGroovy
はじめてのGroovyはじめてのGroovy
はじめてのGroovy
 
JS OO and Closures
JS OO and ClosuresJS OO and Closures
JS OO and Closures
 
New in cakephp3
New in cakephp3New in cakephp3
New in cakephp3
 
Presentatie - Introductie in Groovy
Presentatie - Introductie in GroovyPresentatie - Introductie in Groovy
Presentatie - Introductie in Groovy
 
Php 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodPhp 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the Good
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
 
Event Sourcing and Functional Programming
Event Sourcing and Functional ProgrammingEvent Sourcing and Functional Programming
Event Sourcing and Functional Programming
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
 
JavaScript Classes and Inheritance
JavaScript Classes and InheritanceJavaScript Classes and Inheritance
JavaScript Classes and Inheritance
 
ScalaMeter 2014
ScalaMeter 2014ScalaMeter 2014
ScalaMeter 2014
 
Nantes Jug - Java 7
Nantes Jug - Java 7Nantes Jug - Java 7
Nantes Jug - Java 7
 
Algorithm, Review, Sorting
Algorithm, Review, SortingAlgorithm, Review, Sorting
Algorithm, Review, Sorting
 
Intro to Advanced JavaScript
Intro to Advanced JavaScriptIntro to Advanced JavaScript
Intro to Advanced JavaScript
 
Clojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVMClojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVM
 
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークGroovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトーク
 

Similar to Drools5 Community Training Module 3 Drools Expert DRL Syntax

Metaprogramming in Haskell
Metaprogramming in HaskellMetaprogramming in Haskell
Metaprogramming in HaskellHiromi Ishii
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackVic Metcalfe
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
Python Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit TestingPython Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit TestingPython Ireland
 
Criando app Android utilizando Kotlin
Criando app Android utilizando KotlinCriando app Android utilizando Kotlin
Criando app Android utilizando KotlinLuiz Henrique Santana
 
jQuery - Introdução
jQuery - IntroduçãojQuery - Introdução
jQuery - IntroduçãoGustavo Dutra
 
JQuery do dia-a-dia Gustavo Dutra
JQuery do dia-a-dia Gustavo DutraJQuery do dia-a-dia Gustavo Dutra
JQuery do dia-a-dia Gustavo DutraTchelinux
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Jeff Carouth
 
The Ring programming language version 1.10 book - Part 94 of 212
The Ring programming language version 1.10 book - Part 94 of 212The Ring programming language version 1.10 book - Part 94 of 212
The Ring programming language version 1.10 book - Part 94 of 212Mahmoud Samir Fayed
 
WordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPressWordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPressAlena Holligan
 
The Ring programming language version 1.10 book - Part 92 of 212
The Ring programming language version 1.10 book - Part 92 of 212The Ring programming language version 1.10 book - Part 92 of 212
The Ring programming language version 1.10 book - Part 92 of 212Mahmoud Samir Fayed
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistenceHugo Hamon
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Baruch Sadogursky
 
Feel of Kotlin (Berlin JUG 16 Apr 2015)
Feel of Kotlin (Berlin JUG 16 Apr 2015)Feel of Kotlin (Berlin JUG 16 Apr 2015)
Feel of Kotlin (Berlin JUG 16 Apr 2015)intelliyole
 

Similar to Drools5 Community Training Module 3 Drools Expert DRL Syntax (20)

Clojure入門
Clojure入門Clojure入門
Clojure入門
 
Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09
 
Metaprogramming in Haskell
Metaprogramming in HaskellMetaprogramming in Haskell
Metaprogramming in Haskell
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Python Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit TestingPython Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit Testing
 
Criando app Android utilizando Kotlin
Criando app Android utilizando KotlinCriando app Android utilizando Kotlin
Criando app Android utilizando Kotlin
 
jQuery - Introdução
jQuery - IntroduçãojQuery - Introdução
jQuery - Introdução
 
JQuery do dia-a-dia Gustavo Dutra
JQuery do dia-a-dia Gustavo DutraJQuery do dia-a-dia Gustavo Dutra
JQuery do dia-a-dia Gustavo Dutra
 
The ABCs of OTP
The ABCs of OTPThe ABCs of OTP
The ABCs of OTP
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
 
The Ring programming language version 1.10 book - Part 94 of 212
The Ring programming language version 1.10 book - Part 94 of 212The Ring programming language version 1.10 book - Part 94 of 212
The Ring programming language version 1.10 book - Part 94 of 212
 
WordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPressWordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPress
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
The Ring programming language version 1.10 book - Part 92 of 212
The Ring programming language version 1.10 book - Part 92 of 212The Ring programming language version 1.10 book - Part 92 of 212
The Ring programming language version 1.10 book - Part 92 of 212
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Corona sdk
Corona sdkCorona sdk
Corona sdk
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014
 
Feel of Kotlin (Berlin JUG 16 Apr 2015)
Feel of Kotlin (Berlin JUG 16 Apr 2015)Feel of Kotlin (Berlin JUG 16 Apr 2015)
Feel of Kotlin (Berlin JUG 16 Apr 2015)
 

More from Mauricio (Salaboy) Salatino

Lessons Learnt from creating platforms on Kubernetes @ Rejekts
Lessons Learnt from creating platforms on Kubernetes @ RejektsLessons Learnt from creating platforms on Kubernetes @ Rejekts
Lessons Learnt from creating platforms on Kubernetes @ RejektsMauricio (Salaboy) Salatino
 
Building Developer Experiences for the Cloud .pdf
Building Developer Experiences for the Cloud .pdfBuilding Developer Experiences for the Cloud .pdf
Building Developer Experiences for the Cloud .pdfMauricio (Salaboy) Salatino
 
KUBEDAY - JAPAN 2022 - Building FaaS Platforms.pdf
KUBEDAY - JAPAN  2022 - Building FaaS Platforms.pdfKUBEDAY - JAPAN  2022 - Building FaaS Platforms.pdf
KUBEDAY - JAPAN 2022 - Building FaaS Platforms.pdfMauricio (Salaboy) Salatino
 
The Challenges of building Cloud Native Platforms
The Challenges of building Cloud Native PlatformsThe Challenges of building Cloud Native Platforms
The Challenges of building Cloud Native PlatformsMauricio (Salaboy) Salatino
 
Functions Working Group Update - August 2022.pdf
Functions Working Group Update - August 2022.pdfFunctions Working Group Update - August 2022.pdf
Functions Working Group Update - August 2022.pdfMauricio (Salaboy) Salatino
 
Expanding Interoperability in the CD ecosystem - CDCon - Austin, TX - 2022
Expanding Interoperability in the CD ecosystem - CDCon - Austin, TX -  2022 Expanding Interoperability in the CD ecosystem - CDCon - Austin, TX -  2022
Expanding Interoperability in the CD ecosystem - CDCon - Austin, TX - 2022 Mauricio (Salaboy) Salatino
 
Spring I/O 2022: Knative and Spring - Bringing back the `func`
Spring I/O 2022: Knative and Spring - Bringing back the `func`Spring I/O 2022: Knative and Spring - Bringing back the `func`
Spring I/O 2022: Knative and Spring - Bringing back the `func`Mauricio (Salaboy) Salatino
 
Knative Maintainers KubeConEU 22 Knative Overview and Update
Knative Maintainers KubeConEU 22 Knative Overview and UpdateKnative Maintainers KubeConEU 22 Knative Overview and Update
Knative Maintainers KubeConEU 22 Knative Overview and UpdateMauricio (Salaboy) Salatino
 
CDEventsCon Expanding Interoperability in the CD ecosystem
CDEventsCon Expanding Interoperability in the CD ecosystemCDEventsCon Expanding Interoperability in the CD ecosystem
CDEventsCon Expanding Interoperability in the CD ecosystemMauricio (Salaboy) Salatino
 
A Polyglot Developer Experience on Kubernetes - KubeCon EU Valencia
A Polyglot Developer Experience on Kubernetes - KubeCon EU ValenciaA Polyglot Developer Experience on Kubernetes - KubeCon EU Valencia
A Polyglot Developer Experience on Kubernetes - KubeCon EU ValenciaMauricio (Salaboy) Salatino
 
KCD Guatemala - Abstracciones sobre Abstracciones
KCD Guatemala - Abstracciones sobre AbstraccionesKCD Guatemala - Abstracciones sobre Abstracciones
KCD Guatemala - Abstracciones sobre AbstraccionesMauricio (Salaboy) Salatino
 
KubeCon NA - 2021 Tools That I Wish Existed 3 Years Ago To Build a SaaS Offering
KubeCon NA - 2021 Tools That I Wish Existed 3 Years Ago To Build a SaaS OfferingKubeCon NA - 2021 Tools That I Wish Existed 3 Years Ago To Build a SaaS Offering
KubeCon NA - 2021 Tools That I Wish Existed 3 Years Ago To Build a SaaS OfferingMauricio (Salaboy) Salatino
 
Cloud Native Islamabad - Getting Closer to Continuous Delivery with Knative
Cloud Native Islamabad - Getting Closer to Continuous Delivery with KnativeCloud Native Islamabad - Getting Closer to Continuous Delivery with Knative
Cloud Native Islamabad - Getting Closer to Continuous Delivery with KnativeMauricio (Salaboy) Salatino
 

More from Mauricio (Salaboy) Salatino (20)

Devoxx UK - Platforms on top of K8s
Devoxx UK - Platforms on top of K8sDevoxx UK - Platforms on top of K8s
Devoxx UK - Platforms on top of K8s
 
WTF_is_SRE_DeveloperEnabledPlatforms.pdf
WTF_is_SRE_DeveloperEnabledPlatforms.pdfWTF_is_SRE_DeveloperEnabledPlatforms.pdf
WTF_is_SRE_DeveloperEnabledPlatforms.pdf
 
Lessons Learnt from creating platforms on Kubernetes @ Rejekts
Lessons Learnt from creating platforms on Kubernetes @ RejektsLessons Learnt from creating platforms on Kubernetes @ Rejekts
Lessons Learnt from creating platforms on Kubernetes @ Rejekts
 
Building Developer Experiences for the Cloud .pdf
Building Developer Experiences for the Cloud .pdfBuilding Developer Experiences for the Cloud .pdf
Building Developer Experiences for the Cloud .pdf
 
KUBEDAY - JAPAN 2022 - Building FaaS Platforms.pdf
KUBEDAY - JAPAN  2022 - Building FaaS Platforms.pdfKUBEDAY - JAPAN  2022 - Building FaaS Platforms.pdf
KUBEDAY - JAPAN 2022 - Building FaaS Platforms.pdf
 
The Challenges of building Cloud Native Platforms
The Challenges of building Cloud Native PlatformsThe Challenges of building Cloud Native Platforms
The Challenges of building Cloud Native Platforms
 
Functions Working Group Update - August 2022.pdf
Functions Working Group Update - August 2022.pdfFunctions Working Group Update - August 2022.pdf
Functions Working Group Update - August 2022.pdf
 
JBCNConf 2022: Go vs Java (Kubernetes)
JBCNConf 2022: Go vs Java (Kubernetes)JBCNConf 2022: Go vs Java (Kubernetes)
JBCNConf 2022: Go vs Java (Kubernetes)
 
Expanding Interoperability in the CD ecosystem - CDCon - Austin, TX - 2022
Expanding Interoperability in the CD ecosystem - CDCon - Austin, TX -  2022 Expanding Interoperability in the CD ecosystem - CDCon - Austin, TX -  2022
Expanding Interoperability in the CD ecosystem - CDCon - Austin, TX - 2022
 
Spring I/O 2022: Knative and Spring - Bringing back the `func`
Spring I/O 2022: Knative and Spring - Bringing back the `func`Spring I/O 2022: Knative and Spring - Bringing back the `func`
Spring I/O 2022: Knative and Spring - Bringing back the `func`
 
KnativeCon 2022 - Knative Functions
KnativeCon 2022 - Knative FunctionsKnativeCon 2022 - Knative Functions
KnativeCon 2022 - Knative Functions
 
Knative Maintainers KubeConEU 22 Knative Overview and Update
Knative Maintainers KubeConEU 22 Knative Overview and UpdateKnative Maintainers KubeConEU 22 Knative Overview and Update
Knative Maintainers KubeConEU 22 Knative Overview and Update
 
CDEventsCon Expanding Interoperability in the CD ecosystem
CDEventsCon Expanding Interoperability in the CD ecosystemCDEventsCon Expanding Interoperability in the CD ecosystem
CDEventsCon Expanding Interoperability in the CD ecosystem
 
A Polyglot Developer Experience on Kubernetes - KubeCon EU Valencia
A Polyglot Developer Experience on Kubernetes - KubeCon EU ValenciaA Polyglot Developer Experience on Kubernetes - KubeCon EU Valencia
A Polyglot Developer Experience on Kubernetes - KubeCon EU Valencia
 
Pave the Golden Path On Your Internal Platform
Pave the Golden Path On Your Internal PlatformPave the Golden Path On Your Internal Platform
Pave the Golden Path On Your Internal Platform
 
Knative and Spring - Bringing back the func.pdf
Knative and Spring - Bringing back the func.pdfKnative and Spring - Bringing back the func.pdf
Knative and Spring - Bringing back the func.pdf
 
KCD Guatemala - Abstracciones sobre Abstracciones
KCD Guatemala - Abstracciones sobre AbstraccionesKCD Guatemala - Abstracciones sobre Abstracciones
KCD Guatemala - Abstracciones sobre Abstracciones
 
KubeCon NA - 2021 Tools That I Wish Existed 3 Years Ago To Build a SaaS Offering
KubeCon NA - 2021 Tools That I Wish Existed 3 Years Ago To Build a SaaS OfferingKubeCon NA - 2021 Tools That I Wish Existed 3 Years Ago To Build a SaaS Offering
KubeCon NA - 2021 Tools That I Wish Existed 3 Years Ago To Build a SaaS Offering
 
Cloud Native Islamabad - Getting Closer to Continuous Delivery with Knative
Cloud Native Islamabad - Getting Closer to Continuous Delivery with KnativeCloud Native Islamabad - Getting Closer to Continuous Delivery with Knative
Cloud Native Islamabad - Getting Closer to Continuous Delivery with Knative
 
Intro to the Cloud with Knative (Spanish)
Intro to the Cloud with Knative (Spanish) Intro to the Cloud with Knative (Spanish)
Intro to the Cloud with Knative (Spanish)
 

Recently uploaded

Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 

Recently uploaded (20)

Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 

Drools5 Community Training Module 3 Drools Expert DRL Syntax

  • 1.     Drools5 Community Training Sponsored by Plugtree
  • 2. Module 3: Drools Expert  DRL Syntax Drools5 Community Training version: 1.0-SNAPSHOT Release Date: 03/16/2011 Under The Creative Common License
  • 3. Module 3: Drools Expert  DRL Syntax Drools5 Community Training Course by Mauricio "Salaboy" Salatino and Esteban Aliverti is licensed under a Creative Commons Attribution 3.0 Unported License. Based on a work at salaboy.wordpress. com. Permissions beyond the scope of this license may be available at http: //salaboy.wordpress.com/.
  • 4. Agenda ● Introduction to Drools Expert ● Drools DRL syntax introduction ○ LHS Conditional Elements ○ RHS ○ Rules attributes ○ Queries ● Drools 5.x APIs introduction
  • 5. Drools Expert Introduction ● Drools Expert is the rule engine core ● Lets us express Business Rules ● It will be in charge of making inferences to get new conclusions
  • 8. Business Rule Structure package ... import ... global ... rule "My Rule" <Attributes> when <LHS> Song(genre == "Jazz") <CEs> then <RHS> System.out.println("Hi John!"); end
  • 9. LHS - Conditional Elements ● Pattern ● e.g. Song(genre == "Jazz") $song: Song(genre == "Jazz" || == "Avantgarde") $song: Song(duration > 360, $genre: genre == "Jazz")
  • 10. LHS - Conditional Elements ● Field Operators ● e.g. Song( lyrics matches "AZ-az[drink]" ) Song( authors contains "John Zorn" ) Song( author memberof $greatMusicians )
  • 11. LHS - Conditional Elements ● AND e.g. Person( name == "John" ) AND Pet(type == "cat") ● OR e.g. Policewoman (age > 30) OR Fireman(age > 31)
  • 12. LHS - Conditional Elements ● eval e.g. eval( song.isJazz() ) ● not e.g. not( Song( genre == "Pop") )
  • 13. LHS - Conditional Elements ● exists e.g. exists ( Song(genre == "Jazz")) ● forall e.g. forall ( Song() Song(genre == "Jazz") )
  • 14. LHS - Conditional Elements from CE ● e.g. $playlist: Playlist() Song() from $playlist.songs $playlist: Playlist() Song(genre == "Jazz") from $playlist.songs
  • 15. LHS - Conditional Elements ● from ● e.g. global HibernateSession hbn; $playlist: Playlist() Song() from hbn.namedQuery("SongByArtist") .setParameter("artist","John Zorn") .getResultList();
  • 16. LHS - Conditional Elements ● Collect ● e.g. $songs: ArrayList() from collect (Song(genre == "Jazz", year > 2000))
  • 17. LHS - Conditional Elements ● Accumulate
  • 18. LHS - Conditional Elements ● Accumulate CE: <result pattern> from accumulate( <source pattern>, init( <init code> ), action( <action code> ), reverse( <reverse code> ), result( <result expression>)) ● e.g. $playlist: Playlist() $jazzSongs: Number( doubleValue > 100 ) from accumulate( Song(playlist == $playlist, genre == "Jazz"), init( double total = 0; ), action( total += 1; ), reverse( total -= 1; ), result( total ))
  • 19. LHS - Conditional Elements ● Accumulate Function Examples $playlist: Playlist() $total: Number( doubleValue > 100 ) from accumulate( $song: Song( playlist == $playlist, genre == "Jazz"), count($song))
  • 20. LHS - Conditional Elements ● Accumulate out-of-the-box Functions ○ average ○ min ○ max ○ count ○ sum
  • 21. LHS - Conditional Elements ● Accumulate custom function $playlist: Playlist() $total: Number( doubleValue > 100 ) from accumulate( $song: Song( playlist == $playlist), myCustomFc($song.duration)) ● We can plug our custom function here. We just need to implement the AccumulateFunction interface.
  • 22. Nesting CEs ● Drools support nested CEs $petshop: PetShop() $total: Number( doubleValue > 10 ) from accumulate( $pet: Pet(petshop == $petshop, type == PetType.Cat) from $hbm.getNamedQuery("getPetsFromPetshopId") .setParamenter("petshopid",$petshop.getId()) .list(), count ($pet) )
  • 23. Right Hand Side ● Set of actions ● MVEL or Java (http://mvel.codehaus.org/) ● We will have a set of methods to modify the working memory status ○ insert() ○ modify() / update () ○ retract() rule "Fire ! ! !" when Fire() then insert(new Alarm()); end
  • 25. Rule Attributes - no loop ● no-loop i.e. rule "infinite activation loop" no-loop true when $person: Person(age > 21) then update($person){ setName("John"); } end
  • 26. Rule Attributes - salience ● salience (higher priority first) rule "rule with priority" salience 10 when $song: Song() then System.out.println("Rule with higher priority Fired!"); end rule "rule with less priority" salience 5 when $song: Song() then System.out.println("Rule with lower priority Fired!"); end
  • 27. Rule Attributes - agenda-group  rule "Playlist ready" agenda-group "Create Playlist" when Playlist(size == 3) then //Set the focus to "Play playlist" agenda-group kcontext.getKnowledgeRuntime().getAgenda() .getAgendaGroup("Play playlist").setFocus(); end rule "Play playlist" agenda-group "Play playlist" when $pl : Playlist() then $pl.play(); end
  • 28. Rule Attributes - lock-on-active rule "Fill playlist" rule "Number Songs" salience 1 salience 2 lock-on-active lock-on-active agenda-group "Create Playlist" agenda-group "Create Playlist" when when $pl : Playlist() $song : Song() $song : Song() then then modify($song){ modify($pl){ setName( addSong($song); index.getAndIncrement()+ } "_"+ $song.getName()); end } end
  • 29. Queries Example query "Get Persons by Name" (String name) Person(name = :name) end
  • 31. KnowledgeBuilder KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); // Add our rules kbuilder.add(new ClassPathResource("rules.drl"), ResourceType.DRL); //Check for errors during the compilation of the rules KnowledgeBuilderErrors errors = kbuilder.getErrors(); if (errors.size() > 0) { for (KnowledgeBuilderError error : errors) { System.err.println(error); } throw new IllegalArgumentException("Could not parse knowledge."); }
  • 32. KnowledgeBase // Create the Knowledge Base KnowledgeBase kbase = KnowledgeBaseFactory. newKnowledgeBase(); // Add the binary packages (compiled rules) to the Knowledge Base kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
  • 33. KnowledgeSession // Create a StatefulSession using the KnowledgeBase that // contains the compiled knowledge StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); // We can add a runtime logger to understand what is going on // inside the Engine KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession); // Insert a new Fact inside my world FactHandle myFactHandle = ksession.insert(new Person("Myself")); // Update a Fact using the FactHandle ksession.update(myFactHandle, new Person("Salaboy!")); // Retract/Remove from my world the Fact ksession.retract(myFactHandle);
  • 35. Hands on Labs Projects: ● 01 :: Drools Expert Introduction ● 02 :: Drools Expert Conditional Elements ● 03 :: Drools Expert Rule Attributes
  • 36. Briefing Up ● Covered Topics: ○ Rules Execution Lifecycle ○ DRL Syntax ■ Conditional Elements in the LHS ■ Actions in the RHS
  • 37.     Questions?
  • 38. Enjoy!  Questions and Feedback are always appreciated! Stay Tuned!
  • 39.     Contact us at www.plugtree.com