SlideShare uma empresa Scribd logo
1 de 20
Baixar para ler offline
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 !

Mais conteúdo relacionado

Mais procurados

Exception Handling in C#
Exception Handling in C#Exception Handling in C#
Exception Handling in C#Abid Kohistani
 
Developing Complex Business Rules with Drools Integration
Developing Complex Business Rules with Drools IntegrationDeveloping Complex Business Rules with Drools Integration
Developing Complex Business Rules with Drools IntegrationBonitasoft
 
Object Oriented with Java Programmazione Base
Object Oriented with Java Programmazione BaseObject Oriented with Java Programmazione Base
Object Oriented with Java Programmazione BaseFelice Pescatore
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOPDzmitry Naskou
 
Using ML with Amazon SageMaker & GuardDuty to identify anomalous traffic - SE...
Using ML with Amazon SageMaker & GuardDuty to identify anomalous traffic - SE...Using ML with Amazon SageMaker & GuardDuty to identify anomalous traffic - SE...
Using ML with Amazon SageMaker & GuardDuty to identify anomalous traffic - SE...Amazon Web Services
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)arvind pandey
 
Exception Handling In Java
Exception Handling In JavaException Handling In Java
Exception Handling In Javaparag
 
Javascript under the hood 1
Javascript under the hood 1Javascript under the hood 1
Javascript under the hood 1Thang Tran Duc
 
Effective Spring Transaction Management
Effective Spring Transaction ManagementEffective Spring Transaction Management
Effective Spring Transaction ManagementUMA MAHESWARI
 
Introdução ao Java Swing (Interface)
Introdução ao Java Swing (Interface)Introdução ao Java Swing (Interface)
Introdução ao Java Swing (Interface)Sérgio Souza Costa
 
Spring Framework - Spring Security
Spring Framework - Spring SecuritySpring Framework - Spring Security
Spring Framework - Spring SecurityDzmitry Naskou
 
this keyword in Java.pptx
this keyword in Java.pptxthis keyword in Java.pptx
this keyword in Java.pptxParvizMirzayev2
 

Mais procurados (20)

Java Inheritance
Java InheritanceJava Inheritance
Java Inheritance
 
JavaFX Presentation
JavaFX PresentationJavaFX Presentation
JavaFX Presentation
 
Exception Handling in C#
Exception Handling in C#Exception Handling in C#
Exception Handling in C#
 
Developing Complex Business Rules with Drools Integration
Developing Complex Business Rules with Drools IntegrationDeveloping Complex Business Rules with Drools Integration
Developing Complex Business Rules with Drools Integration
 
Object Oriented with Java Programmazione Base
Object Oriented with Java Programmazione BaseObject Oriented with Java Programmazione Base
Object Oriented with Java Programmazione Base
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
 
Java OCA teoria 5
Java OCA teoria 5Java OCA teoria 5
Java OCA teoria 5
 
Using ML with Amazon SageMaker & GuardDuty to identify anomalous traffic - SE...
Using ML with Amazon SageMaker & GuardDuty to identify anomalous traffic - SE...Using ML with Amazon SageMaker & GuardDuty to identify anomalous traffic - SE...
Using ML with Amazon SageMaker & GuardDuty to identify anomalous traffic - SE...
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Exception Handling In Java
Exception Handling In JavaException Handling In Java
Exception Handling In Java
 
Clean code
Clean codeClean code
Clean code
 
Javascript under the hood 1
Javascript under the hood 1Javascript under the hood 1
Javascript under the hood 1
 
Effective Spring Transaction Management
Effective Spring Transaction ManagementEffective Spring Transaction Management
Effective Spring Transaction Management
 
Introdução ao Java Swing (Interface)
Introdução ao Java Swing (Interface)Introdução ao Java Swing (Interface)
Introdução ao Java Swing (Interface)
 
Completable future
Completable futureCompletable future
Completable future
 
Spring Framework - Spring Security
Spring Framework - Spring SecuritySpring Framework - Spring Security
Spring Framework - Spring Security
 
this keyword in Java.pptx
this keyword in Java.pptxthis keyword in Java.pptx
this keyword in Java.pptx
 
Sequelize
SequelizeSequelize
Sequelize
 
OOP java
OOP javaOOP java
OOP java
 
Drools
DroolsDrools
Drools
 

Destaque

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
 

Destaque (16)

Ruleby
RulebyRuleby
Ruleby
 
Business Rule Engine
Business Rule EngineBusiness Rule Engine
Business Rule Engine
 
Drools
DroolsDrools
Drools
 
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
 

Semelhante 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
 

Semelhante 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

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Último (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

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