Top Banner
Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions Simplifying the Development of Rules Using Domain Specific Languages in DROOLS Ludwig Ostermayer, Geng Sun, Dietmar Seipel University of W¨ urzburg, Dept. of Computer Science INAP 2013 – Kiel, 12.09.2013
32

Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Mar 18, 2018

Download

Documents

buicong
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Simplifying the Development of RulesUsing Domain Specific Languages in DROOLS

Ludwig Ostermayer, Geng Sun, Dietmar Seipel

University of Wurzburg, Dept. of Computer Science

INAP 2013 – Kiel, 12.09.2013

Page 2: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

1 Introduction

2 DROOLS

DROOLS Rule LanguageDSLs in DROOLS

3 DSL DesignDSL TemplatesAnnotations

4 The ToolDSL EditorDSL Rule EditorAttribute Editor

5 PROLOG–Based AnalysisTemplatesRules

Page 3: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Introduction

the business rules approach provides a methodology forsystem development creating applications as white boxesbusiness logic is visible, because it is separated intobusiness rulesBusiness Rule Management Systems (BRMS) have beendevelopedin BRMS you can define, deploy, execute, monitor, andmaintain decision logicDROOLS is a BRMS

a Domain Specific Language (DSL) is a programminglanguage of limited expressiveness for a particular problemdomainthe DSL Rule Generator (DSLR) is a tool improving thedevelopment process in DROOLS

Page 4: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

BRMS Project

Project with Trinodis GmbH:

development of business rules applicationsusage of PROLOG technology and related technologyseveral case studies in real business scenariosanalysis of business rulesbusiness analyst–friendly annotation of business rules

Page 5: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Introducing DROOLS

DROOLS – the Business Logic Integration PlatformJAVA–baseddeveloped by the JBOSS community

DROOLS consists of several modules:Expert (Inference Engine)Guvnor (Business Rules Manager)Fusion (Event Processing/Temporal Reasoning)Planner (Automated Planning)

Page 6: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Production Rule System DROOLS EXPERT

Page 7: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

DROOLS Rule Language

formerly: rules were written in XML

XML format is not supported any morenow: rules are written basically in the DROOLS RuleLanguangesimple text files with the extension .drlrules are packed by namespaces – referred to as packageglobal variables can be defined and used within rules viathe globals statementcomplex logic can be outsourced and used within rules viathe functions statement

Page 8: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

A Rule in the DROOLS Rule Language

package LoanApproval

rule "microfinance"when

application: Application(loan_amount < 10000,duration_year < 5 )

customer: Customer(credit_report == "good" )

thenapplication.approval();application.setInterest_rate(0.028);

end

Page 9: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

DSLs in DROOLS

rules in a DSL are developed in DROOLS in two stepsfirst step:

designing DSL expressions with the mapping information tothe DROOLS Rule Languagesave to a file with extension .dsl

second step:use the expressions of the DSL to write rulessave into a file with the extension .dslr

DROOLS transforms the rules of the .dslr-file internally intothe DROOLS Rule Languageusage of the mapping information contained in the .dsl-file

Page 10: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Fragment of a .dsl-File

[when] The customer withmonthly_income is greater than {value1}and credit_report is {value2}=customer: Customer(

monthly_income > {value1},credit_report == {value2} )

[when] indicates the expression as condition[then] is used for an action blockthe single equality sign ”=” separates the expressions inDSL format from the corresponding DRL format

Page 11: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

A Rule written in the DSL

rule "microfinance"when

The loan withloan_amount is smaller than 5000

and duration_year is no more than 3The customer with

monthly_income is greater than 2000and credit_report is "good"

thenThe loan will be approvedSet the interest_rate of the loan to 0.025

end

Page 12: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

DROOLS DSL Editor

a very ”basic” DSL editorlacks user friendliness and functionalityno content assistno package explorer for JAVA classes, attributes ormethodsno component to simply create rules in a DSL

lacks reusability

Page 13: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

DSLR Generator

a few guided steps to create rules in a readable format andwith correct syntaxdevelopment a DSL with the aid of generic templatesgraphical editors help during the construction of syntacticalcorrect rulesa brief example illustrating the usage

Page 14: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

A Template for a DSL Expression

The #instance with#field is smaller than {value} =

#instance: #class(#field < {value})

generic templates for expressions containing the mappinginformation between DSL and DRL

keywords and parameters in a template can be replacedtemplates are designed in JAVA

but transformed to XML to improve readability

Page 15: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Fragment of a Template in XML Format

<template><class>#class</class><instance>#instance</instance>...<condition>

<domain>Common</domain><dsl>

<expression>The #instance with #field is smallerthan {value}

</expression><code>

#instance:#class(#field < {value})</code>

</dsl></condition>

Page 16: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Annotations

form of syntactic meta-data added to JAVA source codeused to accomplish multilingual DSLsclasses, attributes and methods can be annotatedkeywords are replaced by annotation values

@EnExpression(value = "amount of loan")@GerExpression(value = "Kredithoehe")private double loan_amount;

Page 17: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Components

5 components for the creation of rules, each has a graphicaluser interface

Basic DSL Editor – designing simple expressionsComplex Condition Editor – composing conditionsDSL Rule Editor – designing rulesValue Editor – assigning valuesAttribute Editor – editing meta-data of rules

Page 18: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Basic DSL Editor

Page 19: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Complex Condition Editor

Page 20: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

DSL Rule Editor

Page 21: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Value Editor

Page 22: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Attribute Editor

Page 23: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

A Simple Rule created with DSLR Generator

rule "microfinance"when

The loan withamount of loan is smaller than 5000

and the duration in years is no more than 3The customer with

monthly income in dollar is greater than 2000and the credit report is "good"

thenThe loan will be approvedSet the rate of interest of the loan to 0.075

end

Page 24: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

PROLOG–Based Analysis

Templatesduplicateskeywords. . .

Rulesanalysis of the rules created with templatesanalysis and visualization of the interaction of rulesanomalies:

duplicatescontradictionsambiguities

Page 25: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Analysis of Templates

<template><class>#class</class><instance>#instance</instance>...<condition>

<domain>Common</domain><dsl>

<expression>The #instance with #field is smallerthan {value}

</expression><code>

#instance:#class(#field < {value})</code>

</dsl></condition>

Page 26: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Anomalies in Templates

analysis and update with the XML query, transformationand update language FNQUERY

dsl anomaly(+DSL 1, +DSL 2, -Anomaly):checks <dsl> elements for anomalies

dsl_anomaly(Dsl_1, Dsl_2, Anomaly) :-member(Tag, [expression, code]),X := Dsl_1/Tag,Y := Dsl_2/Tag,equivalent(X, Y),Anomaly = duplicate(Tag, X, Y).

Page 27: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Analysis of Rules

package LoanApproval

rule "microfinance"when

application: Application(loan_amount < 10000,duration_year < 5 )

customer: Customer(credit_report == "good" )

thenapplication.approval();application.setInterest_rate(0.028);

end

Page 28: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Transformation to Logical Rules

set the status to approved and the interest rate to 0.028

application(Cid, Loan, Duration, A, B, 0.028, approved) :-

application(Cid, Loan, Duration, A, B, _, _),Loan < 5000,Duration < 3,customer(Cid, _, Credit_Report, Income),Income > 2000,Credit_Report = good.

Transformed rules are analyzed, but usually cannot beexecuted.

Page 29: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Rule Anomalies

If there isa condition referencing a fact with identifier Id, e.g.,application, andan instruction modifyObject(Id) in the action block,

then DROOLS fires all appropriate rules again, which results ina loop. This can be avoided by the no-loop attribute.

drools anomaly(+Prolog, -Anomaly)

reports the anomalies on backtracking.

Further anomalies:duplicates,contradictions,in connection with prioritization.

Page 30: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Visualization: Proof Trees

red circles: derived atomsblue boxes: rule nodes are labeled by numbersorange circles: basic predicates from the configuration

Page 31: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Conclusions

What we have presented:a tool, DSLR Generator, for handling DSLsgraphical user interfaces supporting the rule developmentreusable and generic DSL templatesmaintenance of the meta–data for the rulesanalysis of templates

Future work:extension of the PROLOG–based anomaly analysis,especially for rulesa library of DSL templates for various problem domains

Page 32: Simplifying the Development of Rules Using Domain · PDF fileIntroduction DROOLS DSL Design The Tool PROLOG–Based AnalysisConclusions Simplifying the Development of Rules Using Domain

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Thank You for Your Attention

Questions?

http://www1.informatik.uni-wuerzburg.de/en/staff/ostermayer ludwig/[email protected]