SlideShare una empresa de Scribd logo
1 de 20
Descargar para leer sin conexión
Rule Engine– Java & Ruby
Drools & Ruleby




               Ing. Martín Cabrera
               martin.cabrera@moove-it.com
               Moove-IT
Content
   Rules Engine ? What is this ?
   When to use ?
   RETE algorithm
   In Java - JBoss Drools
       features
       Syntax
   In ruby ?
Motor de Reglas ¿what a #@!$ ?

                    Application




                    Rule engine




    Rule def.
                            knowledge base
         Rule def
When to use?
   Infrastructure decoupled from the source
   System to allow the final user to define their rules
    and change them dynamically
       Developers are not the primary responsibility for changing
        rules
   Moderate or high complexity of business rules
   Performance !

   Conclusion: down the rules of your system, so that
    they can be reused, decouple the code and allow the
    user to know the rules ... to modify !
Tipical Code
01     if ((user.isMemberOf(AdministratorGroup) && user.isMemberOf(teleworkerGroup)) ||
02             user.isSuperUser() {
03         // more checks for specific cases
04         if ((expenseRequest.code().equals("B203") ||
05                 (expenseRequest.code().equals("A903") && (totalExpenses < 200) &&
06                      (bossSignOff > totalExpenses)) && (deptBudget.notExceeded)) {
07             // issue payments
08         }
09         else if {
10             // check lots of other conditions
11         }
12     }
                                                          Change this rules ! ... %&”@    !
13     else {
14         // even more business logic
15     }
16 }
Rete Algorithm – the
Solution !
   Pattern matching algorithm for implementing
    production rule systems (wikipedia)
       http://en.wikipedia.org/wiki/Rete_algorithm
   replaces if ... Then with an optimized logic network
Rete 2
   RETE – characteristics:
       It reduces or eliminates certain types of redundancy through the use of
        node sharing.
       It stores partial matches when performing joins between different fact
        types.
       It allows for efficient removal of memory elements when facts are
        retracted from working memory.
   Widely used to implement matching functionality within pattern-
    matching engines that exploit a match-resolve-act cycle to
    support forward and backward chaining and inferencing.
       Forward-chaining (facts -> goals)
       Backguard chaining (goals -> facts)
Drools –
   http://jboss.org/drools

   Introduction video -
    http://blog.athico.com/2010/03/fosdem-50-minute-introduction-into.h

   Introduction
       Rules engine framework for java
       It is used in other jboss projects like JBPM, SEAM, Jboss ESB and
        others
       The rules can be written in Java, Python, Groovy Ruby and your own
        rule language
       Jboss tools – plugin Eclipse to use this framework
Eclipse & Drools
Syntax or rules definition

rule “<name>”
   <attribute> <value>
   when
      <LHS>
   then
      <RHS>
end
Example – rule definition
 rule.drl

package com.mooveit.rule

import com.mooveit.rule.Global

global Global global;

rule "r1 - first rule"

            when
                   instance : Entity( field1 > 2010)
            then
                   ...
end
Example
                                Business Action

                                                         1
StatefulSession session = getRulesBase().newStatefulSession();
session.setGlobal("rulesImpl", this);

session.insert(instance);
session.fireAllRules();


                                            2

                            3                     knowledge base
                                                      +instance




      Execute the “then” part for the instance that match the facts
Drools Schema
Rules files
                Repository of
                instances




                   assert
                   modify
                   retract
JBoss Rules Overview
                                                                     Agenda
Rule                                                                Activation
 Rule
   Rule       1.Parse DRL        RuleBase                 Rule                       Fact
     Rule
      Rule
                                                                    Activation
                                                                                   Fact




                                   2. Create
                                                          Rule                      Fact



Fact
 Fact
   Fact      3. Assert Facts   WorkingMemory
     Fact
      Fact                                                          Fact
                                                                     Fact
                                                                       Fact




                                                     es
                                                                         Fact



                                                   ul
                                                   R
                                                                          Fact

                                               ll
                                               A
                                              re           Rule         (5) activation
                                           Fi
                                                            Rule      -> consequence
                                        4.


                                                              Rule
                                                                Rule
                                                                 Rule
Examples in our projects

   (demo)
Rule Engine in
Rules Engine In ruby
   Ruleby - https://github.com/codeaspects/ruleby
       Rule engine for Ruby
       Active project but with few people dedicated
       October 11 of 2010 last push in the master branch
       Install: gem install ruleby
   Others
       Ruby Rools - http://rools.rubyforge.org/
           Last activity (ago 2009 in rools users)
           Status: Beta
           2 members
       A few projects without activity: rein, ruby-rules
       Treetop
           language for describing languages
           It's not a pure rule engine ... but can serve
Ruleby Description
   Provide a pure Ruby Domain Specific Language (DSL)
     rule [m.status == :HELLO] do |v|
       puts v[:m].message
     end


   (LHS) Left hand side of the production (the ‘when’) is
    represented by the Array parameter
   (RHS) The right hand side (the ‘then’) is represented by the
    block.
      engine :hello_engine do |e|
        HelloWorldRulebook.new(e).rules
        assert e, Message.new(:HELLO, ‘Hello World’)
        e.match
      end

   Result:Hello World
Ruleby links

   The Ruleby DSL for more information.
       https://github.com/codeaspects/ruleby/wiki/The-Ruleby
   Download
       http://gemcutter.org/gems/ruleby
   User Group
       http://groups-beta.google.com/group/ruleby
That's it !

Más contenido relacionado

La actualidad más candente

SQL to Hive Cheat Sheet
SQL to Hive Cheat SheetSQL to Hive Cheat Sheet
SQL to Hive Cheat SheetHortonworks
 
Rule Engine: Drools .Net
Rule Engine: Drools .NetRule Engine: Drools .Net
Rule Engine: Drools .NetGuo Albert
 
Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!Jorge Vásquez
 
Spring Framework - Validation
Spring Framework - ValidationSpring Framework - Validation
Spring Framework - ValidationDzmitry Naskou
 
Apache Ambari: Managing Hadoop and YARN
Apache Ambari: Managing Hadoop and YARNApache Ambari: Managing Hadoop and YARN
Apache Ambari: Managing Hadoop and YARNHortonworks
 
Elastic Search (엘라스틱서치) 입문
Elastic Search (엘라스틱서치) 입문Elastic Search (엘라스틱서치) 입문
Elastic Search (엘라스틱서치) 입문SeungHyun Eom
 
Introduction to Apache Spark Developer Training
Introduction to Apache Spark Developer TrainingIntroduction to Apache Spark Developer Training
Introduction to Apache Spark Developer TrainingCloudera, Inc.
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressionsLogan Chien
 
Introduction to MongoDB.pptx
Introduction to MongoDB.pptxIntroduction to MongoDB.pptx
Introduction to MongoDB.pptxSurya937648
 
Apache doris (incubating) introduction
Apache doris (incubating) introductionApache doris (incubating) introduction
Apache doris (incubating) introductionleanderlee2
 
Java design patterns
Java design patternsJava design patterns
Java design patternsShawn Brito
 
Oak, the Architecture of the new Repository
Oak, the Architecture of the new RepositoryOak, the Architecture of the new Repository
Oak, the Architecture of the new RepositoryMichael Dürig
 
Tez Shuffle Handler: Shuffling at Scale with Apache Hadoop
Tez Shuffle Handler: Shuffling at Scale with Apache HadoopTez Shuffle Handler: Shuffling at Scale with Apache Hadoop
Tez Shuffle Handler: Shuffling at Scale with Apache HadoopDataWorks Summit
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBMongoDB
 
SPRING - MAVEN - REST API (ITA - Luglio 2017)
SPRING - MAVEN - REST API (ITA - Luglio 2017)SPRING - MAVEN - REST API (ITA - Luglio 2017)
SPRING - MAVEN - REST API (ITA - Luglio 2017)Valerio Radice
 

La actualidad más candente (20)

SQL to Hive Cheat Sheet
SQL to Hive Cheat SheetSQL to Hive Cheat Sheet
SQL to Hive Cheat Sheet
 
Rule Engine: Drools .Net
Rule Engine: Drools .NetRule Engine: Drools .Net
Rule Engine: Drools .Net
 
Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!
 
Drools Ecosystem
Drools EcosystemDrools Ecosystem
Drools Ecosystem
 
Spring Framework - Validation
Spring Framework - ValidationSpring Framework - Validation
Spring Framework - Validation
 
Apache Ambari: Managing Hadoop and YARN
Apache Ambari: Managing Hadoop and YARNApache Ambari: Managing Hadoop and YARN
Apache Ambari: Managing Hadoop and YARN
 
Elastic Search (엘라스틱서치) 입문
Elastic Search (엘라스틱서치) 입문Elastic Search (엘라스틱서치) 입문
Elastic Search (엘라스틱서치) 입문
 
Introduction to Apache Spark Developer Training
Introduction to Apache Spark Developer TrainingIntroduction to Apache Spark Developer Training
Introduction to Apache Spark Developer Training
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressions
 
Redis overview
Redis overviewRedis overview
Redis overview
 
MongoDB
MongoDBMongoDB
MongoDB
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Introduction to MongoDB.pptx
Introduction to MongoDB.pptxIntroduction to MongoDB.pptx
Introduction to MongoDB.pptx
 
Apache doris (incubating) introduction
Apache doris (incubating) introductionApache doris (incubating) introduction
Apache doris (incubating) introduction
 
Java design patterns
Java design patternsJava design patterns
Java design patterns
 
Oak, the Architecture of the new Repository
Oak, the Architecture of the new RepositoryOak, the Architecture of the new Repository
Oak, the Architecture of the new Repository
 
Spring Data JPA
Spring Data JPASpring Data JPA
Spring Data JPA
 
Tez Shuffle Handler: Shuffling at Scale with Apache Hadoop
Tez Shuffle Handler: Shuffling at Scale with Apache HadoopTez Shuffle Handler: Shuffling at Scale with Apache Hadoop
Tez Shuffle Handler: Shuffling at Scale with Apache Hadoop
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
SPRING - MAVEN - REST API (ITA - Luglio 2017)
SPRING - MAVEN - REST API (ITA - Luglio 2017)SPRING - MAVEN - REST API (ITA - Luglio 2017)
SPRING - MAVEN - REST API (ITA - Luglio 2017)
 

Destacado

Business Rule Engine
Business Rule EngineBusiness Rule Engine
Business Rule EngineAnkur Singhal
 
UX en proyectos de moove-it
UX en proyectos de moove-itUX en proyectos de moove-it
UX en proyectos de moove-itmartincabrera
 
Presentación Juego para el plan ceibal
Presentación Juego para el plan ceibalPresentación Juego para el plan ceibal
Presentación Juego para el plan ceibalmartincabrera
 
Drools5 Community Training module 4 RETE Algorithm Introduction
Drools5 Community Training module 4 RETE Algorithm IntroductionDrools5 Community Training module 4 RETE Algorithm Introduction
Drools5 Community Training module 4 RETE Algorithm IntroductionMauricio (Salaboy) Salatino
 
Communication with our_clients
Communication with our_clientsCommunication with our_clients
Communication with our_clientsmartincabrera
 
Obey The Rules: Implementing a Rules Engine in Flex
Obey The Rules: Implementing a Rules Engine in FlexObey The Rules: Implementing a Rules Engine in Flex
Obey The Rules: Implementing a Rules Engine in FlexRJ Owen
 
Developing a Real-time Engine with Akka, Cassandra, and Spray
Developing a Real-time Engine with Akka, Cassandra, and SprayDeveloping a Real-time Engine with Akka, Cassandra, and Spray
Developing a Real-time Engine with Akka, Cassandra, and SprayJacob Park
 
Node js presentation
Node js presentationNode js presentation
Node js presentationmartincabrera
 
Programming the Physical World with Device Shadows and Rules Engine
Programming the Physical World with Device Shadows and Rules EngineProgramming the Physical World with Device Shadows and Rules Engine
Programming the Physical World with Device Shadows and Rules EngineAmazon Web Services
 
Them's the Rules - Using a Rules Engine to Wrangle Complexity
Them's the Rules - Using a Rules Engine to Wrangle ComplexityThem's the Rules - Using a Rules Engine to Wrangle Complexity
Them's the Rules - Using a Rules Engine to Wrangle ComplexityMicah Breedlove
 

Destacado (15)

Ruleby
RulebyRuleby
Ruleby
 
Business Rule Engine
Business Rule EngineBusiness Rule Engine
Business Rule Engine
 
UX en proyectos de moove-it
UX en proyectos de moove-itUX en proyectos de moove-it
UX en proyectos de moove-it
 
Presentación Juego para el plan ceibal
Presentación Juego para el plan ceibalPresentación Juego para el plan ceibal
Presentación Juego para el plan ceibal
 
Drools5 Community Training module 4 RETE Algorithm Introduction
Drools5 Community Training module 4 RETE Algorithm IntroductionDrools5 Community Training module 4 RETE Algorithm Introduction
Drools5 Community Training module 4 RETE Algorithm Introduction
 
Communication with our_clients
Communication with our_clientsCommunication with our_clients
Communication with our_clients
 
Rules engine
Rules engineRules engine
Rules engine
 
Obey The Rules: Implementing a Rules Engine in Flex
Obey The Rules: Implementing a Rules Engine in FlexObey The Rules: Implementing a Rules Engine in Flex
Obey The Rules: Implementing a Rules Engine in Flex
 
Drools expert-docs
Drools expert-docsDrools expert-docs
Drools expert-docs
 
Best practices webinar
Best practices webinarBest practices webinar
Best practices webinar
 
Developing a Real-time Engine with Akka, Cassandra, and Spray
Developing a Real-time Engine with Akka, Cassandra, and SprayDeveloping a Real-time Engine with Akka, Cassandra, and Spray
Developing a Real-time Engine with Akka, Cassandra, and Spray
 
Node js presentation
Node js presentationNode js presentation
Node js presentation
 
Programming the Physical World with Device Shadows and Rules Engine
Programming the Physical World with Device Shadows and Rules EngineProgramming the Physical World with Device Shadows and Rules Engine
Programming the Physical World with Device Shadows and Rules Engine
 
Docker for developers
Docker for developersDocker for developers
Docker for developers
 
Them's the Rules - Using a Rules Engine to Wrangle Complexity
Them's the Rules - Using a Rules Engine to Wrangle ComplexityThem's the Rules - Using a Rules Engine to Wrangle Complexity
Them's the Rules - Using a Rules Engine to Wrangle Complexity
 

Similar a Rules Engine - java(Drools) & ruby(ruleby)

JBoss Business Rules Management System (BRMS) Primer
JBoss Business Rules Management System (BRMS) PrimerJBoss Business Rules Management System (BRMS) Primer
JBoss Business Rules Management System (BRMS) PrimerEric D. Schabell
 
October Rules Fest 2008 - Distributed Data Processing with ILOG JRules
October Rules Fest 2008 - Distributed Data Processing with ILOG JRulesOctober Rules Fest 2008 - Distributed Data Processing with ILOG JRules
October Rules Fest 2008 - Distributed Data Processing with ILOG JRulesDan Selman
 
[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your application
[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your application[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your application
[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your applicationjavablend
 
SenchaCon 2016: Handling Undo-Redo in Sencha Applications - Nickolay Platonov
SenchaCon 2016: Handling Undo-Redo in Sencha Applications - Nickolay PlatonovSenchaCon 2016: Handling Undo-Redo in Sencha Applications - Nickolay Platonov
SenchaCon 2016: Handling Undo-Redo in Sencha Applications - Nickolay PlatonovSencha
 
Module Rules. Overview, use cases, API
Module Rules. Overview, use cases, APIModule Rules. Overview, use cases, API
Module Rules. Overview, use cases, APIArtem Berdishev
 
Project Description Of Incident Management System Developed by PRS (CRIS) , N...
Project Description Of Incident Management System Developed by PRS (CRIS) , N...Project Description Of Incident Management System Developed by PRS (CRIS) , N...
Project Description Of Incident Management System Developed by PRS (CRIS) , N...varunsunny21
 
EuroAD 2021: ChainRules.jl
EuroAD 2021: ChainRules.jl EuroAD 2021: ChainRules.jl
EuroAD 2021: ChainRules.jl Lyndon White
 
Rules SDK IBM WW BPM Forum March 2013
Rules SDK IBM WW BPM Forum March 2013Rules SDK IBM WW BPM Forum March 2013
Rules SDK IBM WW BPM Forum March 2013Dan Selman
 
Spring Batch Behind the Scenes
Spring Batch Behind the ScenesSpring Batch Behind the Scenes
Spring Batch Behind the ScenesJoshua Long
 
MarGotAspect - An AspectC++ code generator for the mARGOt framework
MarGotAspect - An AspectC++ code generator for the mARGOt frameworkMarGotAspect - An AspectC++ code generator for the mARGOt framework
MarGotAspect - An AspectC++ code generator for the mARGOt frameworkLeonardo Arcari
 
Rule Responder Nccu Taipei Mar2008 Talk [Compatibility Mode]
Rule Responder Nccu Taipei Mar2008 Talk [Compatibility Mode]Rule Responder Nccu Taipei Mar2008 Talk [Compatibility Mode]
Rule Responder Nccu Taipei Mar2008 Talk [Compatibility Mode]yuhana
 
Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts weili_at_slideshare
 
Building React Applications with Redux
Building React Applications with ReduxBuilding React Applications with Redux
Building React Applications with ReduxFITC
 
Flex 360 Rules Engine
Flex 360 Rules EngineFlex 360 Rules Engine
Flex 360 Rules EngineEffectiveUI
 
Flex 360 Rules Engine
Flex 360 Rules EngineFlex 360 Rules Engine
Flex 360 Rules EngineEffective
 
Java EE7
Java EE7Java EE7
Java EE7Jay Lee
 
Strategy and Template Pattern
Strategy and Template PatternStrategy and Template Pattern
Strategy and Template PatternJonathan Simon
 
Four ways to represent computer executable rules
Four ways to represent computer executable rulesFour ways to represent computer executable rules
Four ways to represent computer executable rulesJeff Long
 

Similar a Rules Engine - java(Drools) & ruby(ruleby) (20)

JBoss Business Rules Management System (BRMS) Primer
JBoss Business Rules Management System (BRMS) PrimerJBoss Business Rules Management System (BRMS) Primer
JBoss Business Rules Management System (BRMS) Primer
 
October Rules Fest 2008 - Distributed Data Processing with ILOG JRules
October Rules Fest 2008 - Distributed Data Processing with ILOG JRulesOctober Rules Fest 2008 - Distributed Data Processing with ILOG JRules
October Rules Fest 2008 - Distributed Data Processing with ILOG JRules
 
[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your application
[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your application[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your application
[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your application
 
SenchaCon 2016: Handling Undo-Redo in Sencha Applications - Nickolay Platonov
SenchaCon 2016: Handling Undo-Redo in Sencha Applications - Nickolay PlatonovSenchaCon 2016: Handling Undo-Redo in Sencha Applications - Nickolay Platonov
SenchaCon 2016: Handling Undo-Redo in Sencha Applications - Nickolay Platonov
 
Module Rules. Overview, use cases, API
Module Rules. Overview, use cases, APIModule Rules. Overview, use cases, API
Module Rules. Overview, use cases, API
 
Rules
RulesRules
Rules
 
Project Description Of Incident Management System Developed by PRS (CRIS) , N...
Project Description Of Incident Management System Developed by PRS (CRIS) , N...Project Description Of Incident Management System Developed by PRS (CRIS) , N...
Project Description Of Incident Management System Developed by PRS (CRIS) , N...
 
EuroAD 2021: ChainRules.jl
EuroAD 2021: ChainRules.jl EuroAD 2021: ChainRules.jl
EuroAD 2021: ChainRules.jl
 
Rules SDK IBM WW BPM Forum March 2013
Rules SDK IBM WW BPM Forum March 2013Rules SDK IBM WW BPM Forum March 2013
Rules SDK IBM WW BPM Forum March 2013
 
Spring Batch Behind the Scenes
Spring Batch Behind the ScenesSpring Batch Behind the Scenes
Spring Batch Behind the Scenes
 
MarGotAspect - An AspectC++ code generator for the mARGOt framework
MarGotAspect - An AspectC++ code generator for the mARGOt frameworkMarGotAspect - An AspectC++ code generator for the mARGOt framework
MarGotAspect - An AspectC++ code generator for the mARGOt framework
 
Rule Responder Nccu Taipei Mar2008 Talk [Compatibility Mode]
Rule Responder Nccu Taipei Mar2008 Talk [Compatibility Mode]Rule Responder Nccu Taipei Mar2008 Talk [Compatibility Mode]
Rule Responder Nccu Taipei Mar2008 Talk [Compatibility Mode]
 
Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts
 
Building React Applications with Redux
Building React Applications with ReduxBuilding React Applications with Redux
Building React Applications with Redux
 
Flex 360 Rules Engine
Flex 360 Rules EngineFlex 360 Rules Engine
Flex 360 Rules Engine
 
Flex 360 Rules Engine
Flex 360 Rules EngineFlex 360 Rules Engine
Flex 360 Rules Engine
 
Java EE7
Java EE7Java EE7
Java EE7
 
Strategy and Template Pattern
Strategy and Template PatternStrategy and Template Pattern
Strategy and Template Pattern
 
TY.BSc.IT Java QB U6
TY.BSc.IT Java QB U6TY.BSc.IT Java QB U6
TY.BSc.IT Java QB U6
 
Four ways to represent computer executable rules
Four ways to represent computer executable rulesFour ways to represent computer executable rules
Four ways to represent computer executable rules
 

Último

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Último (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
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...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

Rules Engine - java(Drools) & ruby(ruleby)

  • 1. Rule Engine– Java & Ruby Drools & Ruleby Ing. Martín Cabrera martin.cabrera@moove-it.com Moove-IT
  • 2. Content  Rules Engine ? What is this ?  When to use ?  RETE algorithm  In Java - JBoss Drools  features  Syntax  In ruby ?
  • 3. Motor de Reglas ¿what a #@!$ ? Application Rule engine Rule def. knowledge base Rule def
  • 4. When to use?  Infrastructure decoupled from the source  System to allow the final user to define their rules and change them dynamically  Developers are not the primary responsibility for changing rules  Moderate or high complexity of business rules  Performance !  Conclusion: down the rules of your system, so that they can be reused, decouple the code and allow the user to know the rules ... to modify !
  • 5. Tipical Code 01 if ((user.isMemberOf(AdministratorGroup) && user.isMemberOf(teleworkerGroup)) || 02 user.isSuperUser() { 03 // more checks for specific cases 04 if ((expenseRequest.code().equals("B203") || 05 (expenseRequest.code().equals("A903") && (totalExpenses < 200) && 06 (bossSignOff > totalExpenses)) && (deptBudget.notExceeded)) { 07 // issue payments 08 } 09 else if { 10 // check lots of other conditions 11 } 12 } Change this rules ! ... %&”@ ! 13 else { 14 // even more business logic 15 } 16 }
  • 6. Rete Algorithm – the Solution !  Pattern matching algorithm for implementing production rule systems (wikipedia)  http://en.wikipedia.org/wiki/Rete_algorithm  replaces if ... Then with an optimized logic network
  • 7. Rete 2  RETE – characteristics:  It reduces or eliminates certain types of redundancy through the use of node sharing.  It stores partial matches when performing joins between different fact types.  It allows for efficient removal of memory elements when facts are retracted from working memory.  Widely used to implement matching functionality within pattern- matching engines that exploit a match-resolve-act cycle to support forward and backward chaining and inferencing.  Forward-chaining (facts -> goals)  Backguard chaining (goals -> facts)
  • 8. Drools –  http://jboss.org/drools  Introduction video - http://blog.athico.com/2010/03/fosdem-50-minute-introduction-into.h  Introduction  Rules engine framework for java  It is used in other jboss projects like JBPM, SEAM, Jboss ESB and others  The rules can be written in Java, Python, Groovy Ruby and your own rule language  Jboss tools – plugin Eclipse to use this framework
  • 10. Syntax or rules definition rule “<name>” <attribute> <value> when <LHS> then <RHS> end
  • 11. Example – rule definition rule.drl package com.mooveit.rule import com.mooveit.rule.Global global Global global; rule "r1 - first rule" when instance : Entity( field1 > 2010) then ... end
  • 12. Example Business Action 1 StatefulSession session = getRulesBase().newStatefulSession(); session.setGlobal("rulesImpl", this); session.insert(instance); session.fireAllRules(); 2 3 knowledge base +instance Execute the “then” part for the instance that match the facts
  • 13. Drools Schema Rules files Repository of instances assert modify retract
  • 14. JBoss Rules Overview Agenda Rule Activation Rule Rule 1.Parse DRL RuleBase Rule Fact Rule Rule Activation Fact 2. Create Rule Fact Fact Fact Fact 3. Assert Facts WorkingMemory Fact Fact Fact Fact Fact es Fact ul R Fact ll A re Rule (5) activation Fi Rule -> consequence 4. Rule Rule Rule
  • 15. Examples in our projects  (demo)
  • 17. Rules Engine In ruby  Ruleby - https://github.com/codeaspects/ruleby  Rule engine for Ruby  Active project but with few people dedicated  October 11 of 2010 last push in the master branch  Install: gem install ruleby  Others  Ruby Rools - http://rools.rubyforge.org/  Last activity (ago 2009 in rools users)  Status: Beta  2 members  A few projects without activity: rein, ruby-rules  Treetop  language for describing languages  It's not a pure rule engine ... but can serve
  • 18. Ruleby Description  Provide a pure Ruby Domain Specific Language (DSL) rule [m.status == :HELLO] do |v| puts v[:m].message end  (LHS) Left hand side of the production (the ‘when’) is represented by the Array parameter  (RHS) The right hand side (the ‘then’) is represented by the block. engine :hello_engine do |e| HelloWorldRulebook.new(e).rules assert e, Message.new(:HELLO, ‘Hello World’) e.match end  Result:Hello World
  • 19. Ruleby links  The Ruleby DSL for more information.  https://github.com/codeaspects/ruleby/wiki/The-Ruleby  Download  http://gemcutter.org/gems/ruleby  User Group  http://groups-beta.google.com/group/ruleby