dsntk-examples 0.3.0

ÐecisionToolkit | Examples
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions namespace="https://dsntk.io/"
             name="compliance-level-3-test-0092"
             id="_65c7b4cc-a125-4e92-8e7c-6057a6dc275c"
             xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/">
    <description>FEEL lambda</description>

    <!-- ============================================================================================= -->

    <itemDefinition name="lambda_number_returns_number">
        <functionItem outputTypeRef="number">
            <parameters name="n" typeRef="number"/>
        </functionItem>
    </itemDefinition>

    <!-- ============================================================================================= -->

    <!-- decision returns a UDF lambda (no closures) -->
    <decision name="decision_001_2" id="_decision_001_2">
        <variable name="decision_001_2"/>
        <literalExpression>
            <text>function (a) 1 + a</text>
        </literalExpression>
    </decision>

    <decision name="decision_001_1" id="_decision_001_1">
        <variable name="decision_001_1"/>
        <informationRequirement>
            <requiredDecision href="#_decision_001_2"/>
        </informationRequirement>
        <!-- invokes a lambda supplied by another decision -->
        <literalExpression>
            <text>decision_001_2(2)</text>
        </literalExpression>
    </decision>

    <!-- ============================================================================================= -->

    <!-- decision returns a function definition lambda (no closures) -->
    <decision name="decision_002_2" id="_decision_002_2">
        <variable name="decision_002_2"/>
        <functionDefinition>
            <formalParameter name="a" typeRef="number"/>
            <literalExpression>
                <text>1 + a</text>
            </literalExpression>
        </functionDefinition>
    </decision>

    <decision name="decision_002_1" id="_decision_002_1">
        <variable name="decision_002_1"/>
        <informationRequirement>
            <requiredDecision href="#_decision_002_2"/>
        </informationRequirement>
        <!-- invokes a lambda supplied by another decision -->
        <literalExpression>
            <text>decision_002_2(3)</text>
        </literalExpression>
    </decision>

    <!-- ============================================================================================= -->

    <!-- BKM returns a UDF lambda (no closures) -->
    <businessKnowledgeModel name="bkm_003_1" id="_bkm_003_1">
        <variable name="bkm_003_1"/>
        <encapsulatedLogic>
            <literalExpression>
                <text>function (a) 1 + a</text>
            </literalExpression>
        </encapsulatedLogic>
    </businessKnowledgeModel>

    <decision name="decision_003_1" id="_decision_003_1">
        <variable name="decision_003_1"/>
        <knowledgeRequirement>
            <requiredKnowledge href="#_bkm_003_1"/>
        </knowledgeRequirement>
        <!-- invokes a lambda supplied by bkm -->
        <literalExpression>
            <text>bkm_003_1()(4)</text>
        </literalExpression>
    </decision>

    <!-- ============================================================================================= -->

    <!-- BKM returns a Function Definition lambda (no closures) -->
    <businessKnowledgeModel name="bkm_004_1" id="_bkm_004_1">
        <variable name="bkm_004_1"/>
        <encapsulatedLogic>
            <functionDefinition>
                <formalParameter name="a" typeRef="number"/>
                <literalExpression>
                    <text>1 + a</text>
                </literalExpression>
            </functionDefinition>
        </encapsulatedLogic>
    </businessKnowledgeModel>

    <decision name="decision_004_1" id="_decision_004_1">
        <variable name="decision_004_1"/>
        <knowledgeRequirement>
            <requiredKnowledge href="#_bkm_004_1"/>
        </knowledgeRequirement>
        <!-- invokes a lambda supplied by bkm -->
        <literalExpression>
            <text>bkm_004_1()(5)</text>
        </literalExpression>
    </decision>

    <!-- ============================================================================================= -->

    <!-- BKM has a single param.  It returns a UDF lambda that uses that bkm param in closure -->
    <businessKnowledgeModel name="bkm_005_1" id="_bkm_005_1">
        <variable name="bkm_005_1"/>
        <encapsulatedLogic>
            <formalParameter name="a" typeRef="number"/>
            <literalExpression>
                <text>function (b) a * b</text>
            </literalExpression>
        </encapsulatedLogic>
    </businessKnowledgeModel>

    <decision name="decision_005_1" id="_decision_005_1">
        <variable name="decision_005_1"/>
        <knowledgeRequirement>
            <requiredKnowledge href="#_bkm_005_1"/>
        </knowledgeRequirement>
        <!-- invokes bkm.  The bkm returns a function with '10' closed over.   -->
        <literalExpression>
            <text>bkm_005_1(10)(2)</text>
        </literalExpression>
    </decision>

    <!-- ============================================================================================= -->

    <!-- BKM has a single param.  It returns a function definition lambda that uses that bkm param in closure -->
    <businessKnowledgeModel name="bkm_006_1" id="_bkm_006_1">
        <variable name="bkm_006_1"/>
        <encapsulatedLogic>
            <formalParameter name="a" typeRef="number"/>
            <functionDefinition>
                <formalParameter name="b" typeRef="number"/>
                <literalExpression>
                    <text>a * b</text>
                </literalExpression>
            </functionDefinition>
        </encapsulatedLogic>
    </businessKnowledgeModel>

    <decision name="decision_006_1" id="_decision_006_1">
        <variable name="decision_006_1"/>
        <knowledgeRequirement>
            <requiredKnowledge href="#_bkm_006_1"/>
        </knowledgeRequirement>
        <!-- invokes bkm.  The bkm returns a function with '10' closed over.   -->
        <literalExpression>
            <text>bkm_006_1(10)(3)</text>
        </literalExpression>
    </decision>

    <!-- ============================================================================================= -->

    <inputData name="input_007_1" id="_input_007_1">
        <variable name="input_007_1" typeRef="number"/>
    </inputData>

    <!-- decision returns a UDF lambda that closes over an info requirement input data value -->
    <decision name="decision_007_2" id="_decision_007_2">
        <variable name="decision_007_2"/>
        <informationRequirement>
            <requiredInput href="#_input_007_1"/>
        </informationRequirement>
        <literalExpression>
            <text>function (a: number) a * input_007_1</text>
        </literalExpression>
    </decision>

    <decision name="decision_007_1" id="_decision_007_1">
        <variable name="decision_007_1"/>
        <informationRequirement>
            <requiredDecision href="#_decision_007_2"/>
        </informationRequirement>
        <!-- invokes a lambda that has the value of input_007_1 closed over -->
        <literalExpression>
            <text>decision_007_2(5)</text>
        </literalExpression>
    </decision>

    <!-- ============================================================================================= -->

    <!-- BKM has a param.  It returns a UDF lambda that has the same name as one of its own params -->
    <businessKnowledgeModel name="bkm_008_1" id="_bkm_008_1">
        <variable name="bkm_008_1"/>
        <encapsulatedLogic>
            <formalParameter name="a" typeRef="number"/>
            <literalExpression>
                <text>function (a, b) a * b</text>
            </literalExpression>
        </encapsulatedLogic>
    </businessKnowledgeModel>

    <decision name="decision_008_1" id="_decision_008_1">
        <variable name="decision_008_1"/>
        <knowledgeRequirement>
            <requiredKnowledge href="#_bkm_008_1"/>
        </knowledgeRequirement>
        <!-- invokes lambda passing 10 as param 'a', but as lambda has an 'a' param the 10 is not closed over -->
        <literalExpression>
            <text>bkm_008_1(10)(2, 3)</text>
        </literalExpression>
    </decision>

    <!-- ============================================================================================= -->

    <!-- BKM returns a UDF with a closed over 'a' -->
    <businessKnowledgeModel name="bkm_009_1" id="_bkm_009_1">
        <variable name="bkm_009_1"/>
        <encapsulatedLogic>
            <formalParameter name="a" typeRef="number"/>
            <literalExpression>
                <text>function (b) a * b</text>
            </literalExpression>
        </encapsulatedLogic>
    </businessKnowledgeModel>

    <decision name="decision_009_1" id="_decision_009_1">
        <variable name="decision_009_1"/>
        <knowledgeRequirement>
            <requiredKnowledge href="#_bkm_009_1"/>
        </knowledgeRequirement>
        <context>
            <contextEntry>
                <!-- var 'a' in scope for expression below -->
                <variable name="a"/>
                <literalExpression>
                    <text>10</text>
                </literalExpression>
            </contextEntry>
            <contextEntry>
                <!-- lambda from bkm has 'a' closed over with value 100 - so it gets used, not the 10 from context
                var above -->
                <literalExpression>
                    <text>bkm_009_1(100)(2)</text>
                </literalExpression>
            </contextEntry>
        </context>
    </decision>

    <!-- ============================================================================================= -->

    <!-- bkm has UDF lambda that has a currying-like multiple levels of closure -->
    <businessKnowledgeModel name="bkm_010_1" id="_bkm_010_1">
        <variable name="bkm_010_1"/>
        <encapsulatedLogic>
            <formalParameter name="a" typeRef="number"/>
            <literalExpression>
                <text>function (b) function(c) function(d) a*b*c*d</text>
            </literalExpression>
        </encapsulatedLogic>
    </businessKnowledgeModel>

    <decision name="decision_010_2" id="_decision_010_2">
        <variable name="decision_010_2"/>
        <knowledgeRequirement>
            <requiredKnowledge href="#_bkm_010_1"/>
        </knowledgeRequirement>
        <!-- invokes lambda passing param that close over multiple levels, but last level is not invoked
        so expression result is actually the final nested lambda -->
        <literalExpression>
            <text>bkm_010_1(2)(3)(4)</text>
        </literalExpression>
    </decision>

    <decision name="decision_010_1" id="_decision_010_1">
        <variable name="decision_010_1"/>
        <informationRequirement>
            <requiredDecision href="#_decision_010_2"/>
        </informationRequirement>
        <!-- invokes lambda passing param that close over multiple levels -->
        <literalExpression>
            <text>decision_010_2(5)</text>
        </literalExpression>
    </decision>

    <!-- ============================================================================================= -->

    <!-- bkm has function definition lambda that a currying-like multiple levels of closure -->
    <businessKnowledgeModel name="bkm_010_1_a" id="_bkm_010_1_a">
        <variable name="bkm_010_1_a"/>
        <encapsulatedLogic>
            <formalParameter name="a" typeRef="number"/>
            <functionDefinition>
                <formalParameter name="b" typeRef="number"/>
                <functionDefinition>
                    <formalParameter name="c" typeRef="number"/>
                    <functionDefinition>
                        <formalParameter name="d" typeRef="number"/>
                        <literalExpression>
                            <text>a*b*c*d</text>
                        </literalExpression>
                    </functionDefinition>
                </functionDefinition>
            </functionDefinition>
        </encapsulatedLogic>
    </businessKnowledgeModel>

    <decision name="decision_010_2_a" id="_decision_010_2_a">
        <variable name="decision_010_2_a"/>
        <knowledgeRequirement>
            <requiredKnowledge href="#_bkm_010_1_a"/>
        </knowledgeRequirement>
        <!-- invokes lambda passing param that close over multiple levels, but last level is not invoked
        so expression result is actually the final nested lambda -->
        <literalExpression>
            <text>bkm_010_1_a(2)(3)(4)</text>
        </literalExpression>
    </decision>

    <decision name="decision_010_1_a" id="_decision_010_1_a">
        <variable name="decision_010_1_a"/>
        <informationRequirement>
            <requiredDecision href="#_decision_010_2_a"/>
        </informationRequirement>
        <!-- invokes lambda passing param that close over multiple levels -->
        <literalExpression>
            <text>decision_010_2_a(5)</text>
        </literalExpression>
    </decision>

    <!-- ============================================================================================= -->

    <!-- BKM take two lambda params -->
    <businessKnowledgeModel name="bkm_011_1" id="_bkm_011_1">
        <variable name="bkm_011_1"/>
        <encapsulatedLogic>
            <formalParameter name="fn1"/>
            <formalParameter name="fn2"/>
            <literalExpression>
                <text>fn1(5)*fn2(10)</text>
            </literalExpression>
        </encapsulatedLogic>
    </businessKnowledgeModel>

    <inputData name="input_011_1" id="_input_011_1">
        <variable name="input_011_1" typeRef="number"/>
    </inputData>

    <decision name="decision_011_1" id="_decision_011_1">
        <variable name="decision_011_1"/>
        <informationRequirement>
            <requiredInput href="#_input_011_1"/>
        </informationRequirement>
        <knowledgeRequirement>
            <requiredKnowledge href="#_bkm_011_1"/>
        </knowledgeRequirement>
        <literalExpression>
            <!-- two UDF lambdas are passed to bkm_011_1 -->
            <text>bkm_011_1(function (a) input_011_1 * a, function (b) input_011_1 * b)</text>
        </literalExpression>
    </decision>

    <!-- ============================================================================================= -->

    <!-- BKM take two lambda params -->
    <businessKnowledgeModel name="bkm_012_1" id="_bkm_012_1">
        <variable name="bkm_012_1"/>
        <encapsulatedLogic>
            <formalParameter name="fn1"/>
            <formalParameter name="fn2"/>
            <literalExpression>
                <text>fn1(5)*fn2(10)</text>
            </literalExpression>
        </encapsulatedLogic>
    </businessKnowledgeModel>

    <businessKnowledgeModel name="bkm_012_2" id="_bkm_012_2">
        <variable name="bkm_012_2"/>
        <encapsulatedLogic>
            <formalParameter name="a"/>
            <literalExpression>
                <text>a * 10</text>
            </literalExpression>
        </encapsulatedLogic>
    </businessKnowledgeModel>

    <decision name="decision_012_1" id="_decision_012_1">
        <variable name="decision_012_1"/>
        <knowledgeRequirement>
            <requiredKnowledge href="#_bkm_012_1"/>
        </knowledgeRequirement>
        <knowledgeRequirement>
            <requiredKnowledge href="#_bkm_012_2"/>
        </knowledgeRequirement>
        <!-- bkm_012_2 is not executed here but is passed on to bkm_012_1 -->
        <literalExpression>
            <text>bkm_012_1(bkm_012_2, bkm_012_2)</text>
        </literalExpression>
    </decision>

    <!-- ============================================================================================= -->

    <inputData name="input_013_1" id="_input_013_1">
        <variable name="input_013_1" typeRef="number"/>
    </inputData>

    <decisionService name="decisionService_013_1" id="_decisionService_013_1">
        <variable name="decisionService_013_1"/>
        <outputDecision href="#_decision_013_2"/>
        <inputData href="#_input_013_1"/>
    </decisionService>

    <decision name="decision_013_2" id="_decision_013_2">
        <variable name="decision_013_2"/>
        <informationRequirement>
            <requiredInput href="#_input_013_1"/>
        </informationRequirement>
        <literalExpression>
            <text>input_013_1 * 10</text>
        </literalExpression>
    </decision>

    <!-- BKM take two DS lambda params (each DS returns a context)-->
    <businessKnowledgeModel name="bkm_013_1" id="_bkm_013_1">
        <variable name="bkm_013_1"/>
        <encapsulatedLogic>
            <formalParameter name="fn1"/>
            <formalParameter name="fn2"/>
            <literalExpression>
                <!-- DS invocations - with param.  Each DS invocation returns a context -->
                <text>fn1(5)*fn2(10)</text>
            </literalExpression>
        </encapsulatedLogic>
    </businessKnowledgeModel>

    <decision name="decision_013_1" id="_decision_013_1">
        <variable name="decision_013_1"/>
        <knowledgeRequirement>
            <requiredKnowledge href="#_bkm_013_1"/>
        </knowledgeRequirement>
        <knowledgeRequirement>
            <requiredKnowledge href="#_decisionService_013_1"/>
        </knowledgeRequirement>
        <!-- decisionService_013_1 is not executed here but is passed on to bkm_013_1 -->
        <literalExpression>
            <text>bkm_013_1(decisionService_013_1, decisionService_013_1)</text>
        </literalExpression>
    </decision>

    <!-- ============================================================================================= -->

    <!-- BKM take two lambda params -->
    <businessKnowledgeModel name="bkm_014_1" id="_bkm_014_1">
        <variable name="bkm_014_1"/>
        <encapsulatedLogic>
            <formalParameter name="fn1" typeRef="lambda_number_returns_number"/>
            <formalParameter name="fn2" typeRef="lambda_number_returns_number"/>
            <literalExpression>
                <text>fn1(-5)*fn2(25)</text>
            </literalExpression>
        </encapsulatedLogic>
    </businessKnowledgeModel>

    <decision name="decision_014_1" id="_decision_014_1">
        <variable name="decision_014_1"/>
        <knowledgeRequirement>
            <requiredKnowledge href="#_bkm_014_1"/>
        </knowledgeRequirement>
        <literalExpression>
            <text>bkm_014_1(abs, sqrt)</text>
        </literalExpression>
    </decision>

    <!-- ============================================================================================= -->

    <businessKnowledgeModel name="bkm_015_1" id="_bkm_015_1">
        <variable name="bkm_015_1"/>
        <encapsulatedLogic>
            <formalParameter name="fn1"/>
            <literalExpression>
                <!-- pass in 'sum' func is used both in sum(list) and sum(list..) modes -->
                <text>fn1([1,2,3])*fn1(1,2)</text>
            </literalExpression>
        </encapsulatedLogic>
    </businessKnowledgeModel>

    <decision name="decision_015_1" id="_decision_015_1">
        <variable name="decision_015_1"/>
        <knowledgeRequirement>
            <requiredKnowledge href="#_bkm_015_1"/>
        </knowledgeRequirement>
        <!-- passed overloadable built-in function as param  -->
        <literalExpression>
            <text>bkm_015_1(sum)</text>
        </literalExpression>
    </decision>

    <!-- ============================================================================================= -->

    <businessKnowledgeModel name="bkm_016_1" id="_bkm_016_1">
        <variable name="bkm_016_1"/>
        <encapsulatedLogic>
            <formalParameter name="fn1"/>
            <literalExpression>
                <!-- passed in 'sqrt' func is invoked with too many params -->
                <text>fn1(10,2)</text>
            </literalExpression>
        </encapsulatedLogic>
    </businessKnowledgeModel>

    <decision name="decision_016_1" id="_decision_016_1">
        <variable name="decision_016_1"/>
        <knowledgeRequirement>
            <requiredKnowledge href="#_bkm_016_1"/>
        </knowledgeRequirement>
        <literalExpression>
            <text>bkm_016_1(sqrt)</text>
        </literalExpression>
    </decision>

    <!-- ============================================================================================= -->

    <businessKnowledgeModel name="bkm_017_1" id="_bkm_017_1">
        <variable name="bkm_017_1"/>
        <encapsulatedLogic>
            <formalParameter name="fn1"/>
            <literalExpression>
                <!-- passed in 'precedes' lambda is passed again to sort() -->
                <text>sort(["a","z", "a", "z"], fn1)</text>
            </literalExpression>
        </encapsulatedLogic>
    </businessKnowledgeModel>

    <inputData name="input_017_1" id="_input_017_1">
        <variable name="input_017_1" typeRef="string"/>
    </inputData>

    <decision name="decision_017_1" id="_decision_017_1">
        <variable name="decision_017_1"/>
        <informationRequirement>
            <requiredInput href="#_input_017_1"/>
        </informationRequirement>
        <knowledgeRequirement>
            <requiredKnowledge href="#_bkm_017_1"/>
        </knowledgeRequirement>
        <literalExpression>
            <text>bkm_017_1(function (a,b) if a = input_017_1 then true else false)</text>
        </literalExpression>
    </decision>

    <!-- ============================================================================================= -->

    <businessKnowledgeModel name="bkm_018" id="_bkm_018">
        <variable name="bkm_018"/>
        <encapsulatedLogic>
            <formalParameter name="p1"/>
            <formalParameter name="p2"/>
            <literalExpression>
                <text>if p1 = "a" then true else false</text>
            </literalExpression>
        </encapsulatedLogic>
    </businessKnowledgeModel>

    <!-- decision pass a BKM to the sort() function -->
    <decision name="decision_018" id="_decision_018">
        <variable name="decision_018"/>
        <knowledgeRequirement>
            <requiredKnowledge href="#_bkm_018"/>
        </knowledgeRequirement>
        <literalExpression>
            <text>sort(["a","z", "a", "z"], bkm_018)</text>
        </literalExpression>
    </decision>

</definitions>