SlideShare ist ein Scribd-Unternehmen logo
1 von 35
Downloaden Sie, um offline zu lesen
RuleBox => Modern & Natural Rule Engine!
WHO AM I?
• Luis Majano
• Computer Engineer
• Born in El Salvador ->Texas
• CEO of Ortus Solutions
• Sandals -> ESRI -> Ortus
@lmajano
@ortussolutions
What is RuleBox
Why RuleBox was created
The Problem
What is a Rule Engine
Why use a Rule Engine
Implementation of RuleBox
What is RuleBox
• A modern and natural language rule engine
• Inspired by RuleBook (Java Project)
• Rules are written in the RuleBox Domain Specific Language (DSL)
• Modeled after Given-When-Then
• Dynamic and Expressive
https://forgebox.io/view/rulebox
Reference: https://github.com/rulebook-rules/rulebook
install rulebox
Why Create RuleBox
• Thanks to RevAgency for inspiration:
• Real world problem to handle cruise promotions
• Legacy app plagued with nested if-then-else
• Logic and data mixed
• Much more…
• Did my research:
• Majority of rule engines are complex and convoluted
• Nothing in ColdFusion (CFML) Landscape
• Found RuleBook articles inspiring
• Lots of caffeine, and RuleBox was born!
The
Problem
The Problem
• Ever nesting of if-then-else logic
• Imperative algorithms showing how instead of what?
• No Logic and Data Separation
• Logic is not easily followed
• Maintenance pain
• How testable is that code? Has it really been tested?
• The Domino Effect:
Single if statement can rule them all
What is a rule engine?
• Alternative computational model to traditional imperative programming
• Imperative: Sequence of commands with conditionals, loops and data
• Set of rules that have a condition and an action based on data=>facts
• The engine evaluates rules in the appropriate order and make sense of it
• You focus on the conditions and actions and not the how you do it.
Advantages
• Functional and Declarative Programming
• Speed and Scalability of development
• Understandable and Named Rules
• Increase Maintenance
• Increase Encapsulation of Logic
• Logic and Data Separation
When?
When…
• Remember the problem
• Logic and data intermixed
• Maintenance is painful
• Logic is brittle
• The logic changes often
• 500 lines of if-else statements
How?
How does it work?
How does it work?
Chain of Responsibility
• RuleBox Models CoR
• A RuleBook defines rules and chains them
together to provider order
• Facts flow to each rule (data-binding)
• RuleBooks control results
• Each Rule has a condition, an exception
and one or more actions
https://sourcemaking.com/design_patterns/chain_of_responsibility
RuleBox Flow
install rulebox
Create RuleBooks
Define Rules: when/then
Run Rules with Given Facts
Process Results
WireBox Mappings
• Rule@rulebox - A transient rule object
• RuleBook@rulebox - A transient rule book object
• Builder@rulebox - A static class that can be used to build a-la-carte rules
and rulebooks.
• Result@rulebox - RuleBooks produce results and this is the object that
models such results. Similar to Java Optionals
RuleBox DSL
• Given( name, value ) - The facts
• GivenAll( struct ) - Struct of facts

• When( closure/lambda ) - The conditions
• Except( closure/lambda ) - The exceptions
• Then( closure/lambda ) - The actions/consumers
Rules
Against a RuleBook
RuleBooks
component extends="rulebox.models.RuleBook"{
    function defineRules(){
setName( “My RuleBook” );
        // Add a new rule to this rulebook
        addRule(
            newRule( "MyRule" )
                .when( function( facts ){
                    return facts.keyExists( “hello” );
                } )
                .then( function( facts ){
                    systemOutput( "World" );
                } )
        );
    }
}
• ATransient CFC inherits from rulebox.models.RuleBook
• Can have a name property
• 1 Method: defineRules()
• Create rules using the DSL
Creating Rules
addRule(
    newRule( “name” )
    .when( function( facts ){
    } )
    .except( function( facts ){
    } )
    .then( function( facts, result ) {
    } )
)
.addRule( function( rule ){
    rule
    .setName( ‘name’ )
    .when( function( facts ){
    } )
    .except( function( facts ){
    } )
    .then( function( facts, result ) {
    } )
.stop();
} )
• Using the addRule( rule ) method
• Alternative Syntax, choose your comfort!
• Each Rule can have the following:
• Name (optional)
• 1 when()
• 0,1 except()
• * then()
• 1 stop()
• Best friend:Api Docs
https://apidocs.ortussolutions.com/#/coldbox-modules/rulebox/
When()
addRule(
    newRule()
        .when( function( facts ){
            return facts.keyExists( "hello" );
        })
        .then( function( facts ){
            sytemOutput( facts.hello );
        } )
)
• The condition portion
• Argument is a closure/lambda
• Must evaluate to boolean
• True => Executes Consumers (thens)
• False => Rule does not apply, skip consumers
• Receives facts as a struct
Except()
addRule(
    newRule()
        .when( function( facts ){
            return facts.keyExists( "hello" );
        })
.except( function( facts ){
    return facts.accountDisabled;
} )
        .then( function( facts ){
            sytemOutput( facts.hello );
        } )
)
• Negates the when() condition
• True => Skip consumers (thens)
• False => Continue to consumers
• Special cases and of course exceptions
• Why?To not pollute the when() with negated logic
Consumers : then()
then( function( facts, result ){ sytemOutput( facts.world ); } )
then( function( facts, result ){ result.setValue( result.getValue() * 0.80 ); } )
• The actions for your logic
• Closure that receives
• Facts => A struct of facts
• Results => A RuleBox Result object
• Can have multiple actions
• If the action returns true then it stops the chain of consumers
• Best friend:Api Docs
https://apidocs.ortussolutions.com/#/coldbox-modules/rulebox/
Stopping Consumers
.then( function( facts, result ) ){
    // do stuff
    // break the next then()
    return true;
})
.then( function( facts, result ) ){
    // This never fires
})
Stopping Rules
//credit score under 600 gets a 4x rate increase
addRule(
    newRule()
    .when( function( facts ){ return facts.applicant.getCreditScore() < 600; } )
    .then( function( facts, result ){ result.setValue( result.getValue() * 4 ); } )
    .stop()
);
• stop() on a rule
• Breaks the rule chain
• No more rules are processed if a stop() is issued
Result Object
• Rules can work on a result object’s value (rulebox.models.Result)
• Seed it with a default value
Operation Description
reset() Reset the value with the default value
getValue() Get the value
getDefaultValue() Get the default value (if any)
isPresent() Verifies the value is not null
ifPresent( consumer ) If a value is present, the consumer will be called and the value passed to it.
orElse( other ) If value is not set, then return other else the actual value
orElseGet( producer ) If value is not set, then call the producer and return its value, else return the
actual value
setValue() Set the value in the result object
setDefaultValue() Override the default value in the result object
Build a Loan Rule Engine
component extends="rulebox.models.RuleBook"{
    function defineRules(){
        addRule(
            newRule( “//credit score under 600 gets a 4x rate increase” )
            .when( function( facts ){ return facts[ "creditScore" ] < 600; } )
.then( function( facts, result ){ result.setValue( result.getValue() * 4 ); } )

.stop()
        )
        .addRule( //credit score between 600 and 700 pays a 1 point increase
            newRule()
            .when( function( facts ){ return facts[ "creditScore" ] < 700; } )
            .then( function( facts, result ){ result.setValue( result.getValue() + 1 ); } )
        )
        .addRule( //credit score is 700 and they have at least $25,000 cash on hand
            newRule()
            .when( function( facts ){
                return ( facts[ "creditScore" ] >= 700 && facts[ "cashOnHand" ] >= 25000 );
            } )
            .then( function( facts, result ){ result.setValue( result.getValue() - 0.25 ); } )
        )
        .addRule( // first time homebuyers get 20% off their rate (except if they have a creditScore < 600)
            newRule()
            .when( function( facts ){ return facts[ "firstTimeHomeBuyer" ]; } )
            .then( function( facts, result ){ result.setValue( result.getValue() * 0.80 ); } )
        );
    }
}
What’s Missing?
Execute Rules
Executing Rules
• Create the RuleBook and then we can:
• Set a result default value: withDefaultResult()
• Bind a fact: given( name, value )
• Bind multiple facts: givenAll( struct )
• Execute the rules: run( {facts} )
• Retrieve the Result object (if any): getResult()
describe( "Home Loan Rate Rules", function(){
    it( "Can calculate a first time home buyer with 20,000 down and 650 credit score", function(){
        var homeLoans = getInstance( "tests.resources.HomeLoanRateRuleBook" )
            .withDefaultResult( 4.5 )
            .given( "creditScore", 650 )
            .given( "cashOnHand", 20000 )
            .given( "firstTimeHomeBuyer", true );
        homeLoans.run();
        expect( homeLoans.getResult().isPresent() ).toBeTrue();
        expect( homeLoans.getResult().getValue() ).toBe( 4.4 );
    });
    it( "Can calculate a non first home buyer with 20,000 down and 650 credit score", function(){
        var homeLoans = getInstance( "tests.resources.HomeLoanRateRuleBook" )
            .withDefaultResult( 4.5 )
            .givenAll( {
                "creditScore" : 650,
                "cashOnHand" : 20000,
                "firstTimeHomeBuyer" : false
            } );
        homeLoans.run();
        expect( homeLoans.getResult().isPresent() ).toBeTrue();
        expect( homeLoans.getResult().getValue() ).toBe( 5.5 );
    });
});
Auditing Rules
• All rules are audited for execution
• Important to name them in a human readable form
• Else, love the UUID created for you
• Methods for status:
• getRuleStatus( ruleName ) - Get a single rule status
• getRuleStatusMap() - All rule statuses
Status Description
NONE Rule never executed (default)
SKIPPED Rule was skipped
EXECUTED Rule was executed
Still in infancy
Need your feedback
Stay true to simplicity
Focus on Functional Programming
Nested Rules
StatusVisualizer
Dynamic rules from DB/Storage
More Docs
More Samples
Roadmap
QUESTIONS?
Go Build Some Rules!!
www.ortussolutions.com
@ortussolutions

Weitere ähnliche Inhalte

Was ist angesagt?

Art of Javascript
Art of JavascriptArt of Javascript
Art of JavascriptTarek Yehia
 
Drools 6.0 (Red Hat Summit)
Drools 6.0 (Red Hat Summit)Drools 6.0 (Red Hat Summit)
Drools 6.0 (Red Hat Summit)Mark Proctor
 
Take Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorksTake Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorksNodejsFoundation
 
Ajax tutorial
Ajax tutorialAjax tutorial
Ajax tutorialKat Roque
 
Appengine Java Night #2a
Appengine Java Night #2aAppengine Java Night #2a
Appengine Java Night #2aShinichi Ogawa
 
Appengine Java Night #2b
Appengine Java Night #2bAppengine Java Night #2b
Appengine Java Night #2bShinichi Ogawa
 
Moving from JFreeChart to JavaFX with JavaFX Chart Extensions
Moving from JFreeChart to JavaFX with JavaFX Chart ExtensionsMoving from JFreeChart to JavaFX with JavaFX Chart Extensions
Moving from JFreeChart to JavaFX with JavaFX Chart ExtensionsBruce Schubert
 
Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript EverywherePascal Rettig
 
Object Oriented Programing in JavaScript
Object Oriented Programing in JavaScriptObject Oriented Programing in JavaScript
Object Oriented Programing in JavaScriptAkshay Mathur
 
Drools, jBPM OptaPlanner presentation
Drools, jBPM OptaPlanner presentationDrools, jBPM OptaPlanner presentation
Drools, jBPM OptaPlanner presentationMark Proctor
 
Activator and Reactive at Play NYC meetup
Activator and Reactive at Play NYC meetupActivator and Reactive at Play NYC meetup
Activator and Reactive at Play NYC meetupHenrik Engström
 
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)Stephen Chin
 
Creating Single Page Web App using Backbone JS
Creating Single Page Web App using Backbone JSCreating Single Page Web App using Backbone JS
Creating Single Page Web App using Backbone JSAkshay Mathur
 
Getting the most out of Java [Nordic Coding-2010]
Getting the most out of Java [Nordic Coding-2010]Getting the most out of Java [Nordic Coding-2010]
Getting the most out of Java [Nordic Coding-2010]Sven Efftinge
 
Scala ActiveRecord
Scala ActiveRecordScala ActiveRecord
Scala ActiveRecordscalaconfjp
 
appengine java night #1
appengine java night #1appengine java night #1
appengine java night #1Shinichi Ogawa
 
Lille2010markp
Lille2010markpLille2010markp
Lille2010markpCh'ti JUG
 
"Migrate large gwt applications - Lessons Learned" By Harald Pehl
"Migrate large gwt applications - Lessons Learned" By Harald Pehl"Migrate large gwt applications - Lessons Learned" By Harald Pehl
"Migrate large gwt applications - Lessons Learned" By Harald PehlGWTcon
 
iOS for ERREST - alternative version
iOS for ERREST - alternative versioniOS for ERREST - alternative version
iOS for ERREST - alternative versionWO Community
 

Was ist angesagt? (20)

Art of Javascript
Art of JavascriptArt of Javascript
Art of Javascript
 
ORM Pink Unicorns
ORM Pink UnicornsORM Pink Unicorns
ORM Pink Unicorns
 
Drools 6.0 (Red Hat Summit)
Drools 6.0 (Red Hat Summit)Drools 6.0 (Red Hat Summit)
Drools 6.0 (Red Hat Summit)
 
Take Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorksTake Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorks
 
Ajax tutorial
Ajax tutorialAjax tutorial
Ajax tutorial
 
Appengine Java Night #2a
Appengine Java Night #2aAppengine Java Night #2a
Appengine Java Night #2a
 
Appengine Java Night #2b
Appengine Java Night #2bAppengine Java Night #2b
Appengine Java Night #2b
 
Moving from JFreeChart to JavaFX with JavaFX Chart Extensions
Moving from JFreeChart to JavaFX with JavaFX Chart ExtensionsMoving from JFreeChart to JavaFX with JavaFX Chart Extensions
Moving from JFreeChart to JavaFX with JavaFX Chart Extensions
 
Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript Everywhere
 
Object Oriented Programing in JavaScript
Object Oriented Programing in JavaScriptObject Oriented Programing in JavaScript
Object Oriented Programing in JavaScript
 
Drools, jBPM OptaPlanner presentation
Drools, jBPM OptaPlanner presentationDrools, jBPM OptaPlanner presentation
Drools, jBPM OptaPlanner presentation
 
Activator and Reactive at Play NYC meetup
Activator and Reactive at Play NYC meetupActivator and Reactive at Play NYC meetup
Activator and Reactive at Play NYC meetup
 
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
 
Creating Single Page Web App using Backbone JS
Creating Single Page Web App using Backbone JSCreating Single Page Web App using Backbone JS
Creating Single Page Web App using Backbone JS
 
Getting the most out of Java [Nordic Coding-2010]
Getting the most out of Java [Nordic Coding-2010]Getting the most out of Java [Nordic Coding-2010]
Getting the most out of Java [Nordic Coding-2010]
 
Scala ActiveRecord
Scala ActiveRecordScala ActiveRecord
Scala ActiveRecord
 
appengine java night #1
appengine java night #1appengine java night #1
appengine java night #1
 
Lille2010markp
Lille2010markpLille2010markp
Lille2010markp
 
"Migrate large gwt applications - Lessons Learned" By Harald Pehl
"Migrate large gwt applications - Lessons Learned" By Harald Pehl"Migrate large gwt applications - Lessons Learned" By Harald Pehl
"Migrate large gwt applications - Lessons Learned" By Harald Pehl
 
iOS for ERREST - alternative version
iOS for ERREST - alternative versioniOS for ERREST - alternative version
iOS for ERREST - alternative version
 

Ähnlich wie RuleBox : A natural language Rule Engine

Learn AJAX at ASIT
Learn AJAX at ASITLearn AJAX at ASIT
Learn AJAX at ASITASIT
 
Кирилл Безпалый, .NET Developer, Ciklum
Кирилл Безпалый, .NET Developer, CiklumКирилл Безпалый, .NET Developer, Ciklum
Кирилл Безпалый, .NET Developer, CiklumAlina Vilk
 
SharePoint and jQuery Essentials
SharePoint and jQuery EssentialsSharePoint and jQuery Essentials
SharePoint and jQuery EssentialsMark Rackley
 
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)Jen Wong
 
EXPERTALKS: Feb 2013 - Rise of the Single Page Application
EXPERTALKS: Feb 2013 - Rise of the Single Page ApplicationEXPERTALKS: Feb 2013 - Rise of the Single Page Application
EXPERTALKS: Feb 2013 - Rise of the Single Page ApplicationEXPERTALKS
 
ERRest - Designing a good REST service
ERRest - Designing a good REST serviceERRest - Designing a good REST service
ERRest - Designing a good REST serviceWO Community
 
Developer testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing FanaticDeveloper testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing FanaticLB Denker
 
Getting Started with Javascript
Getting Started with JavascriptGetting Started with Javascript
Getting Started with JavascriptAkshay Mathur
 
fuser interface-development-using-jquery
fuser interface-development-using-jqueryfuser interface-development-using-jquery
fuser interface-development-using-jqueryKostas Mavridis
 
SwampDragon presentation: The Copenhagen Django Meetup Group
SwampDragon presentation: The Copenhagen Django Meetup GroupSwampDragon presentation: The Copenhagen Django Meetup Group
SwampDragon presentation: The Copenhagen Django Meetup GroupErnest Jumbe
 
Lecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdfLecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdfLê Thưởng
 
Rethinking Syncing at AltConf 2019
Rethinking Syncing at AltConf 2019Rethinking Syncing at AltConf 2019
Rethinking Syncing at AltConf 2019Joe Keeley
 
Alternatives of JPA/Hibernate
Alternatives of JPA/HibernateAlternatives of JPA/Hibernate
Alternatives of JPA/HibernateSunghyouk Bae
 
CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)Ortus Solutions, Corp
 
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...Ortus Solutions, Corp
 
Spring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffSpring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffJAX London
 

Ähnlich wie RuleBox : A natural language Rule Engine (20)

Dapper performance
Dapper performanceDapper performance
Dapper performance
 
Django Pro ORM
Django Pro ORMDjango Pro ORM
Django Pro ORM
 
Jquery Fundamentals
Jquery FundamentalsJquery Fundamentals
Jquery Fundamentals
 
JS Essence
JS EssenceJS Essence
JS Essence
 
Learn AJAX at ASIT
Learn AJAX at ASITLearn AJAX at ASIT
Learn AJAX at ASIT
 
Кирилл Безпалый, .NET Developer, Ciklum
Кирилл Безпалый, .NET Developer, CiklumКирилл Безпалый, .NET Developer, Ciklum
Кирилл Безпалый, .NET Developer, Ciklum
 
SharePoint and jQuery Essentials
SharePoint and jQuery EssentialsSharePoint and jQuery Essentials
SharePoint and jQuery Essentials
 
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
 
EXPERTALKS: Feb 2013 - Rise of the Single Page Application
EXPERTALKS: Feb 2013 - Rise of the Single Page ApplicationEXPERTALKS: Feb 2013 - Rise of the Single Page Application
EXPERTALKS: Feb 2013 - Rise of the Single Page Application
 
ERRest - Designing a good REST service
ERRest - Designing a good REST serviceERRest - Designing a good REST service
ERRest - Designing a good REST service
 
Developer testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing FanaticDeveloper testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing Fanatic
 
Getting Started with Javascript
Getting Started with JavascriptGetting Started with Javascript
Getting Started with Javascript
 
fuser interface-development-using-jquery
fuser interface-development-using-jqueryfuser interface-development-using-jquery
fuser interface-development-using-jquery
 
SwampDragon presentation: The Copenhagen Django Meetup Group
SwampDragon presentation: The Copenhagen Django Meetup GroupSwampDragon presentation: The Copenhagen Django Meetup Group
SwampDragon presentation: The Copenhagen Django Meetup Group
 
Lecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdfLecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdf
 
Rethinking Syncing at AltConf 2019
Rethinking Syncing at AltConf 2019Rethinking Syncing at AltConf 2019
Rethinking Syncing at AltConf 2019
 
Alternatives of JPA/Hibernate
Alternatives of JPA/HibernateAlternatives of JPA/Hibernate
Alternatives of JPA/Hibernate
 
CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)
 
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...
 
Spring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffSpring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard Wolff
 

Mehr von Ortus Solutions, Corp

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Secure your Secrets and Settings in ColdFusion
Secure your Secrets and Settings in ColdFusionSecure your Secrets and Settings in ColdFusion
Secure your Secrets and Settings in ColdFusionOrtus Solutions, Corp
 
Daniel Garcia ContentBox: CFSummit 2023
Daniel Garcia ContentBox: CFSummit 2023Daniel Garcia ContentBox: CFSummit 2023
Daniel Garcia ContentBox: CFSummit 2023Ortus Solutions, Corp
 
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdf
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdfITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdf
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdfOrtus Solutions, Corp
 
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdfITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdfOrtus Solutions, Corp
 
ITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdf
ITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdfITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdf
ITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdfOrtus Solutions, Corp
 
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdfITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdfOrtus Solutions, Corp
 
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdf
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdfITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdf
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdfOrtus Solutions, Corp
 
ITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdf
ITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdfITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdf
ITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdfOrtus Solutions, Corp
 
ITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdf
ITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdfITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdf
ITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdfOrtus Solutions, Corp
 
ITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdf
ITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdfITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdf
ITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdfOrtus Solutions, Corp
 
ITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdf
ITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdfITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdf
ITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdfOrtus Solutions, Corp
 
ITB_2023_Chatgpt_Box_Scott_Steinbeck.pdf
ITB_2023_Chatgpt_Box_Scott_Steinbeck.pdfITB_2023_Chatgpt_Box_Scott_Steinbeck.pdf
ITB_2023_Chatgpt_Box_Scott_Steinbeck.pdfOrtus Solutions, Corp
 
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdfITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdfOrtus Solutions, Corp
 
ITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdf
ITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdfITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdf
ITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdfOrtus Solutions, Corp
 
ITB2023 Developing for Performance - Denard Springle.pdf
ITB2023 Developing for Performance - Denard Springle.pdfITB2023 Developing for Performance - Denard Springle.pdf
ITB2023 Developing for Performance - Denard Springle.pdfOrtus Solutions, Corp
 

Mehr von Ortus Solutions, Corp (20)

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Ortus Government.pdf
Ortus Government.pdfOrtus Government.pdf
Ortus Government.pdf
 
Luis Majano The Battlefield ORM
Luis Majano The Battlefield ORMLuis Majano The Battlefield ORM
Luis Majano The Battlefield ORM
 
Brad Wood - CommandBox CLI
Brad Wood - CommandBox CLI Brad Wood - CommandBox CLI
Brad Wood - CommandBox CLI
 
Secure your Secrets and Settings in ColdFusion
Secure your Secrets and Settings in ColdFusionSecure your Secrets and Settings in ColdFusion
Secure your Secrets and Settings in ColdFusion
 
Daniel Garcia ContentBox: CFSummit 2023
Daniel Garcia ContentBox: CFSummit 2023Daniel Garcia ContentBox: CFSummit 2023
Daniel Garcia ContentBox: CFSummit 2023
 
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdf
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdfITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdf
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdf
 
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdfITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
 
ITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdf
ITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdfITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdf
ITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdf
 
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdfITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
 
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdf
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdfITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdf
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdf
 
ITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdf
ITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdfITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdf
ITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdf
 
ITB_2023_CBWire_v3_Grant_Copley.pdf
ITB_2023_CBWire_v3_Grant_Copley.pdfITB_2023_CBWire_v3_Grant_Copley.pdf
ITB_2023_CBWire_v3_Grant_Copley.pdf
 
ITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdf
ITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdfITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdf
ITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdf
 
ITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdf
ITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdfITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdf
ITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdf
 
ITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdf
ITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdfITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdf
ITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdf
 
ITB_2023_Chatgpt_Box_Scott_Steinbeck.pdf
ITB_2023_Chatgpt_Box_Scott_Steinbeck.pdfITB_2023_Chatgpt_Box_Scott_Steinbeck.pdf
ITB_2023_Chatgpt_Box_Scott_Steinbeck.pdf
 
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdfITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
 
ITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdf
ITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdfITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdf
ITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdf
 
ITB2023 Developing for Performance - Denard Springle.pdf
ITB2023 Developing for Performance - Denard Springle.pdfITB2023 Developing for Performance - Denard Springle.pdf
ITB2023 Developing for Performance - Denard Springle.pdf
 

Kürzlich hochgeladen

Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
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
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 

Kürzlich hochgeladen (20)

Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
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
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 

RuleBox : A natural language Rule Engine

  • 1.
  • 2. RuleBox => Modern & Natural Rule Engine!
  • 3. WHO AM I? • Luis Majano • Computer Engineer • Born in El Salvador ->Texas • CEO of Ortus Solutions • Sandals -> ESRI -> Ortus @lmajano @ortussolutions
  • 4. What is RuleBox Why RuleBox was created The Problem What is a Rule Engine Why use a Rule Engine Implementation of RuleBox
  • 5. What is RuleBox • A modern and natural language rule engine • Inspired by RuleBook (Java Project) • Rules are written in the RuleBox Domain Specific Language (DSL) • Modeled after Given-When-Then • Dynamic and Expressive https://forgebox.io/view/rulebox Reference: https://github.com/rulebook-rules/rulebook install rulebox
  • 6. Why Create RuleBox • Thanks to RevAgency for inspiration: • Real world problem to handle cruise promotions • Legacy app plagued with nested if-then-else • Logic and data mixed • Much more… • Did my research: • Majority of rule engines are complex and convoluted • Nothing in ColdFusion (CFML) Landscape • Found RuleBook articles inspiring • Lots of caffeine, and RuleBox was born!
  • 8. The Problem • Ever nesting of if-then-else logic • Imperative algorithms showing how instead of what? • No Logic and Data Separation • Logic is not easily followed • Maintenance pain • How testable is that code? Has it really been tested? • The Domino Effect: Single if statement can rule them all
  • 9. What is a rule engine? • Alternative computational model to traditional imperative programming • Imperative: Sequence of commands with conditionals, loops and data • Set of rules that have a condition and an action based on data=>facts • The engine evaluates rules in the appropriate order and make sense of it • You focus on the conditions and actions and not the how you do it.
  • 10. Advantages • Functional and Declarative Programming • Speed and Scalability of development • Understandable and Named Rules • Increase Maintenance • Increase Encapsulation of Logic • Logic and Data Separation
  • 11. When?
  • 12. When… • Remember the problem • Logic and data intermixed • Maintenance is painful • Logic is brittle • The logic changes often • 500 lines of if-else statements
  • 13. How?
  • 14. How does it work?
  • 15. How does it work?
  • 16. Chain of Responsibility • RuleBox Models CoR • A RuleBook defines rules and chains them together to provider order • Facts flow to each rule (data-binding) • RuleBooks control results • Each Rule has a condition, an exception and one or more actions https://sourcemaking.com/design_patterns/chain_of_responsibility
  • 17. RuleBox Flow install rulebox Create RuleBooks Define Rules: when/then Run Rules with Given Facts Process Results
  • 18. WireBox Mappings • Rule@rulebox - A transient rule object • RuleBook@rulebox - A transient rule book object • Builder@rulebox - A static class that can be used to build a-la-carte rules and rulebooks. • Result@rulebox - RuleBooks produce results and this is the object that models such results. Similar to Java Optionals
  • 19. RuleBox DSL • Given( name, value ) - The facts • GivenAll( struct ) - Struct of facts
 • When( closure/lambda ) - The conditions • Except( closure/lambda ) - The exceptions • Then( closure/lambda ) - The actions/consumers Rules Against a RuleBook
  • 20. RuleBooks component extends="rulebox.models.RuleBook"{     function defineRules(){ setName( “My RuleBook” );         // Add a new rule to this rulebook         addRule(             newRule( "MyRule" )                 .when( function( facts ){                     return facts.keyExists( “hello” );                 } )                 .then( function( facts ){                     systemOutput( "World" );                 } )         );     } } • ATransient CFC inherits from rulebox.models.RuleBook • Can have a name property • 1 Method: defineRules() • Create rules using the DSL
  • 21. Creating Rules addRule(     newRule( “name” )     .when( function( facts ){     } )     .except( function( facts ){     } )     .then( function( facts, result ) {     } ) ) .addRule( function( rule ){     rule     .setName( ‘name’ )     .when( function( facts ){     } )     .except( function( facts ){     } )     .then( function( facts, result ) {     } ) .stop(); } ) • Using the addRule( rule ) method • Alternative Syntax, choose your comfort! • Each Rule can have the following: • Name (optional) • 1 when() • 0,1 except() • * then() • 1 stop() • Best friend:Api Docs https://apidocs.ortussolutions.com/#/coldbox-modules/rulebox/
  • 22. When() addRule(     newRule()         .when( function( facts ){             return facts.keyExists( "hello" );         })         .then( function( facts ){             sytemOutput( facts.hello );         } ) ) • The condition portion • Argument is a closure/lambda • Must evaluate to boolean • True => Executes Consumers (thens) • False => Rule does not apply, skip consumers • Receives facts as a struct
  • 23. Except() addRule(     newRule()         .when( function( facts ){             return facts.keyExists( "hello" );         }) .except( function( facts ){     return facts.accountDisabled; } )         .then( function( facts ){             sytemOutput( facts.hello );         } ) ) • Negates the when() condition • True => Skip consumers (thens) • False => Continue to consumers • Special cases and of course exceptions • Why?To not pollute the when() with negated logic
  • 24. Consumers : then() then( function( facts, result ){ sytemOutput( facts.world ); } ) then( function( facts, result ){ result.setValue( result.getValue() * 0.80 ); } ) • The actions for your logic • Closure that receives • Facts => A struct of facts • Results => A RuleBox Result object • Can have multiple actions • If the action returns true then it stops the chain of consumers • Best friend:Api Docs https://apidocs.ortussolutions.com/#/coldbox-modules/rulebox/
  • 25. Stopping Consumers .then( function( facts, result ) ){     // do stuff     // break the next then()     return true; }) .then( function( facts, result ) ){     // This never fires })
  • 26. Stopping Rules //credit score under 600 gets a 4x rate increase addRule(     newRule()     .when( function( facts ){ return facts.applicant.getCreditScore() < 600; } )     .then( function( facts, result ){ result.setValue( result.getValue() * 4 ); } )     .stop() ); • stop() on a rule • Breaks the rule chain • No more rules are processed if a stop() is issued
  • 27. Result Object • Rules can work on a result object’s value (rulebox.models.Result) • Seed it with a default value Operation Description reset() Reset the value with the default value getValue() Get the value getDefaultValue() Get the default value (if any) isPresent() Verifies the value is not null ifPresent( consumer ) If a value is present, the consumer will be called and the value passed to it. orElse( other ) If value is not set, then return other else the actual value orElseGet( producer ) If value is not set, then call the producer and return its value, else return the actual value setValue() Set the value in the result object setDefaultValue() Override the default value in the result object
  • 28. Build a Loan Rule Engine
  • 29. component extends="rulebox.models.RuleBook"{     function defineRules(){         addRule(             newRule( “//credit score under 600 gets a 4x rate increase” )             .when( function( facts ){ return facts[ "creditScore" ] < 600; } ) .then( function( facts, result ){ result.setValue( result.getValue() * 4 ); } )
 .stop()         )         .addRule( //credit score between 600 and 700 pays a 1 point increase             newRule()             .when( function( facts ){ return facts[ "creditScore" ] < 700; } )             .then( function( facts, result ){ result.setValue( result.getValue() + 1 ); } )         )         .addRule( //credit score is 700 and they have at least $25,000 cash on hand             newRule()             .when( function( facts ){                 return ( facts[ "creditScore" ] >= 700 && facts[ "cashOnHand" ] >= 25000 );             } )             .then( function( facts, result ){ result.setValue( result.getValue() - 0.25 ); } )         )         .addRule( // first time homebuyers get 20% off their rate (except if they have a creditScore < 600)             newRule()             .when( function( facts ){ return facts[ "firstTimeHomeBuyer" ]; } )             .then( function( facts, result ){ result.setValue( result.getValue() * 0.80 ); } )         );     } }
  • 31. Executing Rules • Create the RuleBook and then we can: • Set a result default value: withDefaultResult() • Bind a fact: given( name, value ) • Bind multiple facts: givenAll( struct ) • Execute the rules: run( {facts} ) • Retrieve the Result object (if any): getResult()
  • 32. describe( "Home Loan Rate Rules", function(){     it( "Can calculate a first time home buyer with 20,000 down and 650 credit score", function(){         var homeLoans = getInstance( "tests.resources.HomeLoanRateRuleBook" )             .withDefaultResult( 4.5 )             .given( "creditScore", 650 )             .given( "cashOnHand", 20000 )             .given( "firstTimeHomeBuyer", true );         homeLoans.run();         expect( homeLoans.getResult().isPresent() ).toBeTrue();         expect( homeLoans.getResult().getValue() ).toBe( 4.4 );     });     it( "Can calculate a non first home buyer with 20,000 down and 650 credit score", function(){         var homeLoans = getInstance( "tests.resources.HomeLoanRateRuleBook" )             .withDefaultResult( 4.5 )             .givenAll( {                 "creditScore" : 650,                 "cashOnHand" : 20000,                 "firstTimeHomeBuyer" : false             } );         homeLoans.run();         expect( homeLoans.getResult().isPresent() ).toBeTrue();         expect( homeLoans.getResult().getValue() ).toBe( 5.5 );     }); });
  • 33. Auditing Rules • All rules are audited for execution • Important to name them in a human readable form • Else, love the UUID created for you • Methods for status: • getRuleStatus( ruleName ) - Get a single rule status • getRuleStatusMap() - All rule statuses Status Description NONE Rule never executed (default) SKIPPED Rule was skipped EXECUTED Rule was executed
  • 34. Still in infancy Need your feedback Stay true to simplicity Focus on Functional Programming Nested Rules StatusVisualizer Dynamic rules from DB/Storage More Docs More Samples Roadmap
  • 35. QUESTIONS? Go Build Some Rules!! www.ortussolutions.com @ortussolutions