You are on page 1of 45

Drools Tutorial

Practice

Caroline Rizzi Raymundo


carol.rizziray@gmail.com

Orientadora: Patrícia Dockhorn Costa


Elements of

RULE FILE
Rule File Elements

Package Imports Globals

Functions Queries Rules


Package

Rule
 Unique
... Rule

 Not related to Package


files or folders Rule Rule

Rule Rule
Import

 Like import statements in Java


Global

 Variables available to all of the rules


 Not inserted in the Working Memory
 The engine can’t notify or track global changes
 Packages with the same global identifier
 Must be of the same type
 All the packages will reference the same value
Functions

 To put semantic code in the rule file


 Java code
Query

Just RHS

Result captured
by a java loop
Type Declaration

Fact Type
Metadata

Attribute
Metadata
THE RULE
Main Elements

Left Side Hand

when conditions

Right Side Hand

then actions
Structure
Attributes
The LHS

LEFT HAND SIDE


Conditional Elements
Pattern

eval and

accumulate or

collect not

from exists

forall
Pattern Structure
Restrictions

Constraints

Pattern
Pattern

 Most important conditional element


 Contains zero or more constraints
 Has a optional pattern binding

Binding

Pattern
Constraint
Binding Acces on
Variable Java Beans

AND separator: Java Expressions


comma (restrictions)
Restriction Operators

Relational Continence Pertinence Equality

<
<= contains memberOf matches
>
>=
== not not not
contains memberOf matches
!=
The RHS

RIGHT HAND SIDE


Modifying the WM

Insert

Modify insertLogical

Working
Memory

Update Retract
Starting the Practice

HANDS-ON
Sample: Home Aware

• Devices and Sensors of the House


• TV
• Stereo
• Lamps
• Air Conditioner
• GPS
• Android Mobile

Context Aware System


Components

• Mobile
• Place
• TV Home
• TVConfig Objects Aware

Inferences
• TurnOnTV
Package and Imports
Global Variable
Some rules
Inference Rules
CalcDistance Function
Active Rules
Test
Mary
Position: At home

John
Position: Away from home
Result
Test
Mary
Position: At home

John
Position: Away from home
Result
Starting the Practice

DROOLS FUSION
What is Drools Fusion?

 Module of Drools responsible for enabling


event processing behavior.
 Extras:
 Session Clock
 Streams Support
 Temporal Reasoning
 Sliding Window
Declaration
Metadata

role
timestamp
duration
expires
Session Clock
Real Clock

Pseudo Clock
• Default • Controlled by the
• System Clock application
Envent Entry Point

Event

Different Entry
Points

Event
Envent Entry Point

User instance
Temporal Reasoning

After Overlaps Starts


Before Overlaped By Started By

Meets
Coincides
Met By

During Finishes
Includes Finished By
Temporal Reasoning
Sliding Window

The last X
events that Lenght
ocurred

Events
Time Ocurring in the
last X time
units
Sliding Window
References
 Jboss, Drools Expert User Guide.
http://docs.jboss.org/drools/release/5.3.0.CR1/drools-expert-
docs/html_single/index.html
 Jboss, Drools Fusion User Guide.
http://docs.jboss.org/drools/release/5.3.0.CR1/drools-fusion-
docs/html_single/index.html
 Jboss, Overview (Drools :: API 5.1.1).
http://downloads.jboss.com/drools/docs/5.1.1.34858.FINAL/
apidocs/
 Grupo de Estudo:
https://groups.google.com/forum/#!forum/drools-ufes

You might also like