简体   繁体   English

Drools从Java的Excel工作表中读取Drt

[英]drools reading drt from excel sheet in java

I am reading an excel sheet through drt. 我正在通过drt阅读Excel表格。 The excel sheet looks like attached image. Excel工作表看起来像附加的图像。

In this sheet, actual information starts from 4 row. 在此工作表中,实际信息从4行开始。 However, information from row 2 is also important. 但是,第2行的信息也很重要。 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. 就是说,如果相应单元格中没有值,它将变为空白,但在RULE中,它将采取任何措施。

As for example:, if I am passing a fact with attribute value 5,6,4 respectively for attribute Attr1, Attr2 ande Attr3 ; 例如:如果我要传递一个属性值分别为属性Attr1,Attr2和Attr3的事实5,6,4; 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. 但是,如果我要分别向attr1,attr2和attr3发送值,分别说55、57、58,则应该执行第三条规则。 Plese have a look and suggest some solution. 请看一下并提出一些解决方案。

EDIT Example: 编辑示例:

  1. I am reading excel sheet and creating fact. 我正在阅读Excel工作表并创建事实。 The fact say Xconfig contains : Xconfig包含以下事实:

    Public class XConfig{ 公共类XConfig {

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

    Public class XLine{ 公共课程XLine {

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

Now through drt; 现在通过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. 现在,方案1:我在工作内存中插入一个事实XLine(attr1 = 5, attr2=6,attr3=4) This will select XConfig(attr1 = 5, attr2=6,attr3=4) object through the above rule. 通过上面的规则XConfig(attr1 = 5, attr2=6,attr3=4)这将选择XConfig(attr1 = 5, attr2=6,attr3=4)对象。

Scenario 2: 场景2:

I am inserting a fact XLine(attr1 = "", attr2="",attr3=4) in working memory. 我在工作内存中插入一个事实XLine(attr1 = "", attr2="",attr3=4) This should select same object XConfig(attr1 = 5, attr2=6,attr3=4) through the above rule. 这应通过上述规则选择相同的对象XConfig(attr1 = 5, attr2=6,attr3=4) 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. 因为attr1接受“ ANY”,这意味着如果某些属性在同一配置对象中匹配,则任何值都将放在该位置。 It means if one attribute value of XLine object is matching with the same attribute value of XConfig object; 这意味着XLine对象的一个​​属性值是否与XConfig对象的相同属性值匹配; we need to consider that XConfig Object to check that is other attribute that is not matching with XCOnfig object; 我们需要考虑使用XConfig对象来检查是否与XCOnfig对象不匹配的其他属性; is marked with ANY in the BLANK_VALUE place. 在BLANK_VALUE位置标记为ANY。 if it is marked with ANY, we can take any value on the place of XConfig object. 如果标记为ANY,则可以在XConfig对象的位置取任何值。

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 "" . 您可以使用null代替"" You cannot have String and Integer as types for anything at the same time. 您不能同时将String和Integer作为任何类型的类型。 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. 您可以考虑编写显式规则-根据需要编写-而不是插入XLine对象。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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