It is a decision-making modeling notation specified by OMG (Object Managemnt Group). In recent years, it has been attracting attention as a decision-making automation method in the knowledge part of RPA.
https://www.omg.org/spec/DMN/About-DMN/
The biggest feature of DMN is that you can execute the decision-making model written in a way that is easy for humans to understand. You can test the operation of your DMN with Camunda's DMN Simulator (https://camunda.com/dmn/simulator/). In this sample, the optimal dish (Dish) is determined based on the season and the number of guests, and the optimal drink (Beverages) is determined based on the dish and the guests with children. To do. "Optimal" here means based on predetermined logic (knowledge of companies and individuals). DMN gives this logic in a table called a decision table. For more information, please see here.
Try setting Decision Table to Beverages, Guests with Children to true, Season to Fall, and How Many Guests to 2. Two drinks, Aecht Schlenkerla Rauchbier and Apple Juice, were output as below. From the screen, you can see that Spareribs was selected as the dish that meets the entered conditions. The German beer Aecht Schlenkerla Rauchbier was chosen as the drink for Spareribs. Apple Juice is for kids, isn't it? This is the result of selecting the most suitable drink from the "knowledge" called the decision table based on the entered season and the number of guests.
Behind the scenes of this simulator is the Camunda DMN Engine running the DMN. This time, run this Camunda DMN Engine locally to run the DMN.
This time, we will use Camunda's sample DMN file as the DMN for verification. Download the sample DMN file from the "Download DMN Table" on the DMN Simulator Page. A DMN design tool is required to view and edit DMN files. Personally, I recommend Camunda Modeler, which is standalone and easy to operate. By the way, if you just want to run DMN, you don't need any design tools.
The Camunda DMN Engine is published on Maven Central. Add the following dependency to the POM.
<dependency>
<groupId>org.camunda.bpm.dmn</groupId>
<artifactId>camunda-engine-dmn</artifactId>
</dependency>
Below is a sample Java code that executes a DMN.
//DMN file path and Decision Id settings
String dmnFilePath = "./simulation.dmn";
String decisionId = "beverages";
//Input data settings
Map<String, Object> input = new HashMap<String, Object>();
input.put("season", "Fall"); //autumn
input.put("guestCount", 2); //2 guests
input.put("guestsWithChildren",true); //With children
//DMN engine generation
DmnEngine dmnEngine = DmnEngineConfiguration.createDefaultDmnEngineConfiguration().buildEngine();
//Generation of Decision
DmnDecision decision = dmnEngine.parseDecision(decisionId,new FileInputStream(dmnFilePath));
//Run DMN
DmnDecisionResult result = dmnEngine.evaluateDecision(decision,input);
//Get execution result
for(Map<String,Object> entry : result.getResultList()) {
System.out.println(entry.get("beverages"));
}
Here, the decisionId is specified in the decision table Id, which is the value set in the following location on the decision table displayed by Camunda Modeler.
The input is given the same value as the example of running the DMN simulator earlier. When I run the above code, I get the same result as the DMN simulator as below.
Aecht Schlenkerla Rauchbier
Apple Juice
Since the output of the decision table "beverages" is only beverage, you can only get drinks at this decision table. But anyway I want to get both the food and drink of choice. So edit the decision table to increase the output. In the example below, Camunda Modeler is used to edit the decision table.
Add a column to the output of beverages as shown below. Then, the value of Dish, which is one of the inputs of this decision table, is used as the output. The "desired Dish" in this output column means a reference to the Dish Expression (variable name).
The Input item of the decision table has Label, which is a display label, Expression, which sets the variable name or expression of the value, and Type, which indicates the data type of the value. In Camunda Modeler, Expression is not displayed unless you click the Input header. In the sample DMN, the Expression of the Dish column is desiredDish, and use this value when referencing from other columns.
Next, rewrite "Get Execution Result" in the above Java code as follows so that both food and drink can be displayed.
//Get execution result
for(Map<String,Object> entry : result.getResultList()) {
System.out.println(entry.get("desiredDish") + " with " + entry.get("beverages"));
}
The execution result is shown below. You can now get both food and drinks.
Spareribs with Aecht Schlenkerla Rauchbier
Spareribs with Apple Juice
Recommended Posts