Comparing Drools Decision Table objects gives inverted results

I was struggling with a problem regarding Drools, and this is kind of a last resort.

Suppose I have a list of 3 people: [1, 2, 3]. Think of this list as a list of identification values ​​for these people. Now I want to evaluate all the unique pairs of these people in the following order:

  • Person 1 vs Person 2;
  • Person 1 vs. Person 3;
  • Person 2 vs. Person 3.

My RuleTable table is as follows:

RuleTable PSBR

The trick mentioned in this commentary is used: Drools compares two objects in the decision table .

The Person class was correctly imported, three people were inserted into the session, and each Person object has a method getId().

fireAllRules() :

  • 1 1
  • 2 1
  • 2 2
  • 3 1
  • 3 2
  • 3 3

, , .

! , id > $id1 id < $id1 , , , .

, , :

rule "same-company"
    when
        $p1 : Person($id1 : id)
        $p2 : Person($id2 : id, id > $id1)
    then
        System.out.println($p1.getId() + " " + $p2.getId());
end

, , .drl!

, :

  • , ?
  • , ?

I also have some more complex variables inside Person objects to which I would like to apply logic (line maps for each person with whom I would like to compare values), to which the same thing happens; Drools tables seem to overlook the rule when the conditions that I set are NOT met. Targeting the opposite is possible and works, but for me it doesn't look like how it should work.

Thanks in advance!


Edit 1: Generated DRL using Drools - using "from" in the decision table returns the following result:
package org.ps.dtable;
//generated from Decision Table
import org.ps.orm.Person;
// rule values at C12, header at C7
rule "PSBR_12"
    when
        $p1:Person ($id1: id) $p2:Person($id2:id, id > $id1 /*param*/ == "X")
    then
        System.out.println($p1 + " vs " + $p2);
end

The Excel spreadsheet is as follows: Spreadsheet

Edit 2: $ In was /*$param*/missing and caused a weird pricing. The lesson is learned; never forget about money.

+4
1

, < > - 1 vs 1, , , .

, , 5.5.

, , -. , (, 4), 3 ( , == ).

CONDITION
$p1:Person($id1:id) $p2:Person()
$id2:id > $id1 /*$param*/
pairs ordered by ascending id

, .

PS: DRL. . Drools - Using "from"

PPS: . , /* param */ , == "X" . , , . , , "true", "false", , . . ( , MVEL , .)

+2

Source: https://habr.com/ru/post/1623484/


All Articles