Skip to content

Experimental YAML format for decision model #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ uriparse = "0.6.4"
url = "2.5.4"
urlencoding = "2.1.3"
walkdir = "2.5.0"
yaml-rust = "0.4.5"
dsntk-common = { path = "common" }
dsntk-evaluator = { path = "evaluator" }
dsntk-examples = { path = "examples" }
Expand Down
5 changes: 5 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ tasks:
cmds:
- cmd: cargo +stable test -p dsntk-feel-parser

test-model:
desc: Runs tests in debug mode
cmds:
- cmd: cargo +stable test -p dsntk-model

test-recognizer:
desc: Runs tests in debug mode
cmds:
Expand Down
2 changes: 1 addition & 1 deletion bbt/tests/cli/noargs/0001_OK/expected
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dsntk | DecisionToolkit | 0.2.0
dsntk | DecisionToolkit | 0.3.0-dev
Try 'dsntk --help' to see all available commands.
For more information, visit https://decision-toolkit.org
2 changes: 1 addition & 1 deletion bbt/tests/cli/version/long-version/expected
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.0
0.3.0-dev
2 changes: 1 addition & 1 deletion bbt/tests/cli/version/short-version/expected
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.0
0.3.0-dev
2 changes: 1 addition & 1 deletion bbt/tests/server/action_none/expected
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dsntk | DecisionToolkit | 0.2.0
dsntk | DecisionToolkit | 0.3.0-dev
Try 'dsntk --help' to see all available commands.
For more information, visit https://decision-toolkit.org
2 changes: 1 addition & 1 deletion common/src/href.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::DsntkError;
use uriparse::URIReference;

/// URI reference used for utilizing `href` attribute.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct HRef {
/// Namespace built from URI's path components.
namespace: Option<String>,
Expand Down
2 changes: 2 additions & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ mod href;
mod idents;
mod jsonify;
mod namespace;
mod text_utils;
mod uri;

pub use errors::{DsntkError, Result, ToErrorMessage};
pub use href::HRef;
pub use idents::gen_id;
pub use jsonify::Jsonify;
pub use namespace::to_rdnn;
pub use text_utils::trim_multiline;
pub use uri::{encode_segments, to_uri, Uri};
4 changes: 4 additions & 0 deletions common/src/text_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// Trims whitespaces before and after each line, preserves empty lines.
pub fn trim_multiline(input: String) -> String {
input.trim().lines().map(|line| line.trim().to_string()).collect::<Vec<String>>().join("\n")
}
8 changes: 4 additions & 4 deletions dsntk/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ fn export_decision_table(dectab_file_name: &str, html_file_name: &str, dectab_fi
/// Parses DMN model loaded from XML file and prints ASCII report.
fn parse_dmn_model(dmn_file_name: &str, cm: ColorMode) {
match fs::read_to_string(dmn_file_name) {
Ok(dmn_file_content) => match dsntk_model::parse(&dmn_file_content) {
Ok(dmn_file_content) => match dsntk_model::from_xml(&dmn_file_content) {
Ok(definitions) => {
dsntk_gendoc::print_model(definitions, cm);
}
Expand All @@ -1012,7 +1012,7 @@ fn evaluate_dmn_model(input_file_name: &str, dmn_file_name: &str, invocable_name
match fs::read_to_string(dmn_file_name) {
Ok(dmn_file_content) => match fs::read_to_string(input_file_name) {
Ok(input_file_content) => match dsntk_evaluator::evaluate_context(&FeelScope::default(), &input_file_content) {
Ok(input_data) => match dsntk_model::parse(&dmn_file_content) {
Ok(input_data) => match dsntk_model::from_xml(&dmn_file_content) {
Ok(definitions) => {
let model_namespace = definitions.namespace().to_string();
let model_name = definitions.name().to_string();
Expand Down Expand Up @@ -1043,7 +1043,7 @@ fn test_dmn_model(test_file_name: &str, dmn_file_name: &str, invocable_name: &st
return;
}
};
let definitions = match dsntk_model::parse(&dmn_file_content) {
let definitions = match dsntk_model::from_xml(&dmn_file_content) {
Ok(definitions) => definitions,
Err(reason) => {
eprintln!("parsing model file failed with reason: {reason}");
Expand Down Expand Up @@ -1085,7 +1085,7 @@ fn test_dmn_model(test_file_name: &str, dmn_file_name: &str, invocable_name: &st
/// Exports DMN model loaded from `XML` file to `HTML` output file.
fn export_dmn_model(dmn_file_name: &str, html_file_name: &str) {
match fs::read_to_string(dmn_file_name) {
Ok(dmn_file_content) => match dsntk_model::parse(&dmn_file_content) {
Ok(dmn_file_content) => match dsntk_model::from_xml(&dmn_file_content) {
Ok(definitions) => {
let html_output = dsntk_gendoc::dmn_model_to_html(&definitions);
if let Err(reason) = fs::write(html_file_name, html_output) {
Expand Down
80 changes: 80 additions & 0 deletions examples/src/compatibility/level_2/2_0001.dmm
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
MODEL
NAMESPACE https://decision-toolkit.org/2_0001/
NAME 2_0001
ID _2_0001
VERSION https://www.omg.org/spec/DMN/20191111/MODEL/
DESCRIPTION
Compliance level 2: Test 0001

The decision named **Greeting Message** has a label defined in diagram definition.
In the diagram this decision is depicted as **GREETING MESSAGE**.
The output variable name remains **Greeting Message**.

DECISION
NAME Greeting Message
ID _75b3add2-4d36-4a19-a76c-268b49b2f436
DESCRIPTION
This decision prepares a greeting message.
"Hello" is prepended to the value of the input variable named 'Full Name'.
QUESTION
What is the greeting suitable for our customer?
ALLOWED_ANSWERS
The proper greeting is in the format:
Hello {customer's full name}
VARIABLE
NAME Greeting Message
ID _3215b422-b937-4360-9d1c-4c677cae5dfd
TYPE_REF string
LABEL "GREETING MESSAGE"
INFORMATION_REQUIREMENT
ID _70c3f69a-63f3-4197-96ce-b206c8bd2a6b
INPUT #_cba86e4d-e91c-46a2-9176-e9adf88e15db
LITERAL_EXPRESSION
ID _5baa6245-f6fc-4685-8973-fa873817e2c1
TEXT "Hello " + Full Name

INPUT_DATA
NAME Full Name
ID _cba86e4d-e91c-46a2-9176-e9adf88e15db
DESCRIPTION Full name of the customer provided by calling service.
VARIABLE
NAME "Full Name"
ID _4bc2161f-2f3b-4260-b454-0a01aed0e46b
LABEL Customer's name
TYPE_REF string
DESCRIPTION
Full name of the person that will be sent greetings from this decision model.

DIAGRAM
NAME Decision Requirement Diagram
ID _d3a3312e-5924-4f7b-ac0e-232ef9203ff6
RESOLUTION 300
SIZE 190.0 240.0
SHAPE
DMN_ELEMENT_REF _75b3add2-4d36-4a19-a76c-268b49b2f436
ID _ebf33cfc-0ee3-4708-af8b-91c52237b7d6
BOUNDS 20.0 20.0 150.0 60.0
LABEL
TEXT `GREETING MESSAGE`
SHARED-STYLE style1
SHARED_STYLE style1
SHAPE
DMN_ELEMENT_REF _cba86e4d-e91c-46a2-9176-e9adf88e15db
ID _48ea7a1d-2575-4cb7-8b63-8baa4cb3b371
BOUNDS 20.0 160.0 150.0 60.0
SHARED_STYLE style2
EDGE
ID _e9a73517-0ba2-4b31-b308-82279ae21591
DMN_ELEMENT_REF: _70c3f69a-63f3-4197-96ce-b206c8bd2a6b
WAYPOINTS 95.0 160.0, 95.0 80.0
STYLE
ID style1
FONT bold underline italic strikethrough 18 Arial, Helvetica, sans-serif
LABEL_VERTICAL_ALIGN start
FILL_COLOR 10 255 255
STROKE_COLOR 255 0 0
FONT_COLOR 0 200 0
STYLE
ID style2
FONT bold underline 12 Arial, "Fira Sans", sans-serif
STROKE_COLOR 255 0 0
85 changes: 41 additions & 44 deletions examples/src/compatibility/level_2/2_0001.dmn
Original file line number Diff line number Diff line change
@@ -1,75 +1,72 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions namespace="https://dsntk.io/2_0001/"
name="2_001"
<definitions namespace="https://decision-toolkit.org/2_0001/"
name="2_0001"
id="_2_0001"
xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/"
xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/"
xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/"
xmlns:dmndi="https://www.omg.org/spec/DMN/20191111/DMNDI/">
<description>
Compliance level 2: Test 0001

The decision named **Greeting Message** has a label defined in diagram definition.

In the diagram this decision is depicted as **GREETING MESSAGE**.

The output variable name remains **Greeting Message**.

The decision named **Greeting Message** has a label defined in diagram definition.
In the diagram this decision is depicted as **GREETING MESSAGE**.
The output variable name remains **Greeting Message**.
</description>

<decision name="Greeting Message" id="_75b3add2-4d36-4a19-a76c-268b49b2f436">
<description>
This decision prepares a greeting message.
'Hello' is prepended to the value of the input variable named 'Full Name'.
"Hello" is prepended to the value of the input variable named 'Full Name'.
</description>
<question>
What is the greeting suitable for our customer?
</question>
<allowedAnswers>
The proper greeting is in the format:
Hello {customer's full name}
The proper greeting is in the format: Hello {customer's full name}
</allowedAnswers>
<variable typeRef="string" name="Greeting Message" label="GREETING MESSAGE"/>
<informationRequirement id="_8c935b50-10b7-426b-80a9-dddb4264b4a9">
<variable typeRef="string" name="Greeting Message" label="GREETING MESSAGE" id="_3215b422-b937-4360-9d1c-4c677cae5dfd"/>
<informationRequirement id="_70c3f69a-63f3-4197-96ce-b206c8bd2a6b">
<requiredInput href="#_cba86e4d-e91c-46a2-9176-e9adf88e15db"/>
</informationRequirement>
<literalExpression>
<literalExpression id="_5baa6245-f6fc-4685-8973-fa873817e2c1">
<text>"Hello " + Full Name</text>
</literalExpression>
</decision>

<inputData name="Full Name" id="_cba86e4d-e91c-46a2-9176-e9adf88e15db">
<description>
Full name of the customer provided by calling service.
</description>
<variable typeRef="string" name="Full Name" label="Customer's name" id="_id_variable_full_name">
<variable typeRef="string" name="Full Name" label="Customer's name" id="_4bc2161f-2f3b-4260-b454-0a01aed0e46b">
<description>Full name of the person that will be sent greetings from this decision model.</description>
</variable>
</inputData>
<dmndi:DMNDI>
<dmndi:DMNDiagram name="Decision Requirement Diagram" resolution="300" id="_d3a3312e-5924-4f7b-ac0e-232ef9203ff6">
<dmndi:Size width="190.0" height="240.0"/>
<dmndi:DMNShape dmnElementRef="_75b3add2-4d36-4a19-a76c-268b49b2f436" id="_ebf33cfc-0ee3-4708-af8b-91c52237b7d6" sharedStyle="style1">
<dc:Bounds x="20.0" y="20.0" width="150.0" height="60.0"/>
<dmndi:DMNLabel sharedStyle="style1">
<dmndi:Text>GREETING MESSAGE</dmndi:Text>
</dmndi:DMNLabel>
</dmndi:DMNShape>
<dmndi:DMNShape dmnElementRef="_cba86e4d-e91c-46a2-9176-e9adf88e15db" id="_48ea7a1d-2575-4cb7-8b63-8baa4cb3b371" sharedStyle="style2">
<dc:Bounds x="20.0" y="160.0" width="150.0" height="60.0"/>
</dmndi:DMNShape>
<dmndi:DMNEdge dmnElementRef="_8c935b50-10b7-426b-80a9-dddb4264b4a9" id="_e9a73517-0ba2-4b31-b308-82279ae21591">
<di:waypoint x="95.0" y="160.0"/>
<di:waypoint x="95.0" y="80.0"/>
</dmndi:DMNEdge>
</dmndi:DMNDiagram>
<dmndi:DMNStyle id="style1" fontFamily="Arial,Helvetica,sans-serif" fontSize="18" fontBold="true" fontUnderline="true" fontItalic="true" fontStrikeThrough="true" labelVerticalAlignment="start">
<dmndi:FillColor red="10" green="255" blue="255"/>
<dmndi:StrokeColor red="255" green="0" blue="0"/>
<dmndi:FontColor red="0" green="200" blue="0"/>
</dmndi:DMNStyle>
<dmndi:DMNStyle id="style2" fontFamily="Arial,sans-serif" fontSize="12" fontBold="true" fontUnderline="true">
<dmndi:StrokeColor red="255" green="0" blue="0"/>
</dmndi:DMNStyle>
</dmndi:DMNDI>

<!-- <dmndi:DMNDI>-->
<!-- <dmndi:DMNDiagram name="Decision Requirement Diagram" resolution="300" id="_d3a3312e-5924-4f7b-ac0e-232ef9203ff6">-->
<!-- <dmndi:Size width="190.0" height="240.0"/>-->
<!-- <dmndi:DMNShape dmnElementRef="_75b3add2-4d36-4a19-a76c-268b49b2f436" id="_ebf33cfc-0ee3-4708-af8b-91c52237b7d6" sharedStyle="style1">-->
<!-- <dc:Bounds x="20.0" y="20.0" width="150.0" height="60.0"/>-->
<!-- <dmndi:DMNLabel sharedStyle="style1">-->
<!-- <dmndi:Text>GREETING MESSAGE</dmndi:Text>-->
<!-- </dmndi:DMNLabel>-->
<!-- </dmndi:DMNShape>-->
<!-- <dmndi:DMNShape dmnElementRef="_cba86e4d-e91c-46a2-9176-e9adf88e15db" id="_48ea7a1d-2575-4cb7-8b63-8baa4cb3b371" sharedStyle="style2">-->
<!-- <dc:Bounds x="20.0" y="160.0" width="150.0" height="60.0"/>-->
<!-- </dmndi:DMNShape>-->
<!-- <dmndi:DMNEdge dmnElementRef="_70c3f69a-63f3-4197-96ce-b206c8bd2a6b" id="_e9a73517-0ba2-4b31-b308-82279ae21591">-->
<!-- <di:waypoint x="95.0" y="160.0"/>-->
<!-- <di:waypoint x="95.0" y="80.0"/>-->
<!-- </dmndi:DMNEdge>-->
<!-- </dmndi:DMNDiagram>-->
<!-- <dmndi:DMNStyle id="style1" fontFamily="Arial,Helvetica,sans-serif" fontSize="18" fontBold="true" fontUnderline="true" fontItalic="true" fontStrikeThrough="true" labelVerticalAlignment="start">-->
<!-- <dmndi:FillColor red="10" green="255" blue="255"/>-->
<!-- <dmndi:StrokeColor red="255" green="0" blue="0"/>-->
<!-- <dmndi:FontColor red="0" green="200" blue="0"/>-->
<!-- </dmndi:DMNStyle>-->
<!-- <dmndi:DMNStyle id="style2" fontFamily="Arial,sans-serif" fontSize="12" fontBold="true" fontUnderline="true">-->
<!-- <dmndi:StrokeColor red="255" green="0" blue="0"/>-->
<!-- </dmndi:DMNStyle>-->
<!-- </dmndi:DMNDI>-->
</definitions>
Loading