32
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

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

  • Upload
    buicong

  • View
    220

  • Download
    2

Embed Size (px)

Citation preview

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

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

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

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

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)

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Production Rule System DROOLS EXPERT

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

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

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

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

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

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

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

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

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>

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;

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

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Basic DSL Editor

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Complex Condition Editor

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

DSL Rule Editor

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Value Editor

Introduction DROOLS DSL Design The Tool PROLOG–Based Analysis Conclusions

Attribute Editor

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

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

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>

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).

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

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.

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.

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

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

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]