Hello,
I am proposing we add YaRD into the kie-drools repository. YaRD is used
to describe Decisions, Rules and Declarative logic in the YAML format.
At the current state it supports Decision Tables and Literal
Expressions.
Example of a Decision Table is in attached file
"yard-dtable-example.txt". ( In .txt for easier viewing. )
A more complex example is in attached "costs.txt".
The YAML structure and the used scripting language is not set in stone
and the feature at the moment is experimental.
Under the YAML cover it runs Drools, in more detail the Drools Rule
Units DSL.
Due to the move to Apache we are in a weird situation where we already
have an editor for YaRD in kie-tools without a backend. The existing
editor has a simple autocomplete with support for Validation that finds
redundancy and subsumption from the Decision Tables. To follow the
Apache community rules and to show visibility I am now asking for
approval to add the backend in.
Thank you
Toni Rikkola
specVersion: alpha
kind: YaRD
name: 'MyDecision'
â¦
elements:
- name: 'Base price'
type: Decision
logic:
type: DecisionTable
inputs: ['Age', 'Previous incidents?']
rules:
- ['<21' , false, 800]
- ['<21' , true, 1000]
- ['>=21', false, 500]
- ['>=21', true, 600]
specVersion: alpha
kind: YaRD
name: "Traffic Violation"
expressionLang: jshell
inputs:
- name: Fragile
type: boolean
- name: Package Tracking
type: boolean
- name: Insurance
type: boolean
- name: Package Type
type: string
elements:
- name: Selected premiums
type: Decision
logic:
type: DecisionTable
# Collect all costs
hitPolicy: COLLECT
inputs: [ Package Type, Fragile, Package Tracking, Insurance ]
rules:
# Insurance for all packages, based on size and if the content is
fragile
- when: [ 'S', true, "-", true ]
then: '{ "Name": "Fragile insurance cost", "Price": 10}'
- when: [ 'M', true, "-", true ]
then: '{ "Name": "Fragile insurance cost", "Price": 20}'
- when: [ 'L', true, "-", true ]
then: '{ "Name": "Fragile insurance cost", "Price": 30}'
- when: [ 'XL', true, "-", true ]
then: '{ "Name": "Fragile insurance cost", "Price": 40}'
- when: [ "-", false, "-", true ]
then: '{ "Name": "Regular insurance cost", "Price": 5}'
# Tracking cost is same for all sizes
- when: [ "-", "-", true, "-" ]
then: '{ "Name": "Tracking cost", "Price": 5}'
# Fragile package extra care cost
- when: [ "-", true, "-", "-" ]
then: '{ "Name": "Fragile package shipping cost", "Price": 15}'
- name: "Total cost of premiums"
type: Decision
logic:
type: LiteralExpression
expression: |
((java.util.List<java.util.Map<String,Integer>>)`Selected
premiums`).stream().map(m -> m.get("Price")).mapToInt(Integer::valueOf).sum();
# Feels filthy compared to FEEL below
# expression: 'sum( for item in Selected premiums return item.Price )'
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@kie.apache.org
For additional commands, e-mail: dev-h...@kie.apache.org