简体   繁体   中英

drools reading drt from excel sheet in java

I am reading an excel sheet through drt. The excel sheet looks like attached image.

In this sheet, actual information starts from 4 row. However, information from row 2 is also important. It is saying that if there is no values in the corresponding cells, it will go blank but in the RULE, it would take any thing.

As for example:, if I am passing a fact with attribute value 5,6,4 respectively for attribute Attr1, Attr2 ande Attr3 ; the first row rule will be executed in the rule. However, if I am sending value say 55,57,58 respectively for attr1, attr2 and attr3 the third rule should execute. Plese have a look and suggest some solution.

EDIT Example:

  1. I am reading excel sheet and creating fact. The fact say Xconfig contains :

    Public class XConfig{

     private String attr1; private String attr2; private String attr3; //getter and setter } 

    Public class XLine{

     private String attr1; private String attr2; private String attr3; private String price=0.0; //getter and setter } 

Now through drt; I am reading it row wise and thus created three facts.

1. XConfig(attr1 = 5, attr2=6,attr3=4);
2. XConfig(attr1 = "", attr2=10,attr3=54);
3. XConfig(attr1 = "", attr2="",attr3="");

Note: ""= it is blank string.

The above three config fact is inserted in to working memory.

Now I am writing a drool rule:

when
   $xline : XLine($at1 : attr1, $at2 : attr2, $at3 : attr3, price == 0.0)
   $xconfig : XConfig(attr1 == $at1, attr2 == $at2, attr3 == $at3)
then 
   // do somthing

Now Scenario 1: I am inserting a fact XLine(attr1 = 5, attr2=6,attr3=4) in working memory. This will select XConfig(attr1 = 5, attr2=6,attr3=4) object through the above rule.

Scenario 2:

I am inserting a fact XLine(attr1 = "", attr2="",attr3=4) in working memory. This should select same object XConfig(attr1 = 5, attr2=6,attr3=4) through the above rule. Because attr1 is accepting "ANY" means any value will go in that place if some of the attribute is matching in the same configuration object. It means if one attribute value of XLine object is matching with the same attribute value of XConfig object; we need to consider that XConfig Object to check that is other attribute that is not matching with XCOnfig object; is marked with ANY in the BLANK_VALUE place. if it is marked with ANY, we can take any value on the place of XConfig object.

I hope I would be able to make you understand what I would be willing to do through rules.

Thanks 在此输入图像描述

You may use null in place of "" . You cannot have String and Integer as types for anything at the same time. Then this rule is sufficient to find matching pairs:

when
  $xline : XConfig($at1 : attr1, $at2 : attr2, $at3 : attr3)
  $xconfig : XLine(attr1 == null || == $at1,
                   attr2 == null || == $at2,
                   attr3 == null || == $at3)
then 

You may consider writing explicit rules - as many as required - instead of inserting XLine objects. This lets you distinguish what is actually matched, eg

rule match564
when
    XConfig( attr1 == 5, attr2 == 6, attr3 == 4)
then ... end
rule match xx4
when
    XConfig( attr1 == null, attr2 == null, attr3 == 4)
then ... end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM