Usage

Installation

To install ruly-dmn, call:

pip install ruly-dmn

Command line

Installing after installing ruly-dmn, the simplest way to use it is by creating a DMN file in Camunda Modeler and calling the ruly-dmn command-line program:

usage: main.py [-h] [--output-file path] file goal [inputs [inputs ...]]

positional arguments:
  file                  DMN file.
  goal                  Name of the goal decision.
  inputs                Input value pairs in format <input name>=<value>,
                        where value will be attempted to be parsed as JSON,
                        otherwise it will be interpreted as a string. i.e. a=1
                        b=xyz c='"{"json": "value"}"'

optional arguments:
  -h, --help            show this help message and exit
  --output-file path, -o path
                        Output DMN file path, in case new rules are added. Can
                        be the same path as the input file. If not set, DMN
                        changes are not written anywhere.

Library

Ruly-dmn may also be used as a library, with the following set of available classes:

class ruly_dmn.DMN(handler, rule_factory_cb=None)

Class that contains the DMN implementation.

Parameters
  • handler (ruly_dmn.ModelHandler) – model handler

  • rule_factory_cb (Optional[Callable]) – function that creates a rule factory - if None, a factory that uses console is used. Signature should match the signature of ruly_dmn.rule_factory_cb()

property inputs

List[str]: input variables for all available decisions

decide(inputs, decision)

Attempts to solve for decision based on given inputs. May create new rules if the factory creates them.

Parameters
  • inputs (Dict[str, Any]) – name-value pairs of all inputs

  • decision (str) – name of the decision that should be resolved

Returns

calculated decision

Return type

Any

Raises
class ruly_dmn.ModelHandler

Abstract class representing a connection between an encoded DMN model and ruly’s rules. Implementation should parse initial rules from the model and be available for updates with new rules.

abstract property dependencies

Dict[str, Tuple(str)]: output-input variable name pairs

abstract property rules

List[ruly.Rule]: all rules available in the model

abstract property hit_policies

Dict[str, ruly_dmn.HitPolicy]: hit policies for outputs

abstract update(knowledge_base)

Updates handler with a new knowledge base

Parameters

knowledge_base (ruly.KnowledgeBase) – new knowledge base

class ruly_dmn.RuleFactory

Abstract class whose instances should implement rule creation methods

abstract create_rule(state, fired_rules, output_names)

Creates a new rule

Parameters
  • state (Dict[str, Any]) – state

  • fired_rules (List[ruly.Rule]) – rules activated for state and output combination

  • output_names (str) – output values for the new rule’s consequent

Returns

generated rule, if None, new rule couldn’t be created with given inputs

Return type

Optional[ruly.Rule]

class ruly_dmn.HitPolicy(value)

An enumeration.

exception ruly_dmn.HitPolicyViolation

Exception raised when a hit policy is violated

ruly_dmn.rule_factory_cb(handler)

Placeholder function containing the signature for rule factory callbacks

Parameters

handler (ruly_dmn.ModelHandler) – model handler

Returns

rule factory

Return type

ruly_dmn.RuleFactory

class ruly_dmn.CamundaModelerHandler(path, dump_path=None)

Implementation of the handler that expects a Camunda Modeler DMN file

Parameters
  • path (pathlib.Path) – path to the DMN file

  • dump_path (Optional[pathlib.Path]) – path where updated DMN files will be dumped. Can be the same as path. If None, they aren’t dumped anywhere

property dependencies

Dict[str, Tuple(str)]: output-input variable name pairs

property rules

List[ruly.Rule]: all rules available in the model

property hit_policies

Dict[str, ruly_dmn.HitPolicy]: hit policies for outputs

update(knowledge_base)

Updates handler with a new knowledge base

Parameters

knowledge_base (ruly.KnowledgeBase) – new knowledge base