Drools Tutorial Practice - Informática · PDF fileDrools Tutorial Practice Caroline...
Transcript of Drools Tutorial Practice - Informática · PDF fileDrools Tutorial Practice Caroline...
Drools Tutorial Practice
Caroline Rizzi Raymundo [email protected]
Orientadora: Patrícia Dockhorn Costa
RULE FILE Elements of
Rule File Elements
Package Imports Globals
Functions Queries Rules
Package
Unique
Not related to files or folders
Package
Rule
Rule
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
Right Side Hand
then actions
Left Side Hand
when conditions
Structure
Attributes
LEFT HAND SIDE The LHS
Pattern
and
or
not
exists
forall
from
collect
accumulate
eval
Conditional Elements
Pattern Structure
Restrictions
Constraints
Pattern
Pattern
Most important conditional element
Contains zero or more constraints
Has a optional pattern binding
Pattern
Binding
Constraint
Binding Variable
Acces on Java Beans
Java Expressions (restrictions)
AND separator: comma
Restriction Operators
Relational
<
<=
>
>=
==
!=
Continence
contains
not contains
Pertinence
memberOf
not memberOf
Equality
matches
not matches
RIGHT HAND SIDE The RHS
Modifying the WM
Working Memory
Insert
insertLogical
Retract Update
Modify
HANDS-ON Starting the Practice
Sample: Home Aware
• Devices and Sensors of the House • TV • Stereo • Lamps • Air Conditioner
• GPS • Android Mobile
Context Aware System
Components
Home Aware
Inferences
Objects
• TurnOnTV
• Mobile • Place • TV • TVConfig
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
DROOLS FUSION Starting the Practice
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 R
eal C
lock
• Default
• System Clock
Pse
ud
o C
lock
• Controlled by the application
Envent Entry Point
Event
Event
Different Entry
Points
Envent Entry Point
User instance
Temporal Reasoning
After
Before
Coincides
During Includes
Finishes
Finished By
Meets
Met By
Overlaps
Overlaped By
Starts
Started By
Temporal Reasoning
Sliding Window
Lenght
Time
The last X events that
ocurred
Events 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