Drools - 使用“from”在决策表中 [英] Drools - Using "from" in decision table

查看:683
本文介绍了Drools - 使用“from”在决策表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些麻烦,得到一个规则,我知道工作在.drl形式,以工作在决策表。



这是我的规则在drl形式:

  rule =slider1
dialectmvel

$ person: Person()
ArrayList(size> = 2)
from collect(TestResult(testA,testB),result ==high)
from $ person .getLabResults()

then
$ person.setString(It worked);
end

这是我在电子表格中尝试的:

 条件
-------------------
$ person:Person ()
-------------------
ArrayList(size> = 1)
from collect(TestResult ,result =='high')
from $ person.getLabResults())
-------------------
实验室名称
-------------------
TestA,TestB

当我尝试从电子表格运行规则时,我收到此错误:

 创建KieBase时出错[Message [id = 1,level = ERROR,path = com / creo / drools / decisiontables / sample-decision-table.xls,line = 11,column = 0 
text = [ERR 102]行11:53不匹配的输入'from'在规则年轻安全包1],消息[id = 2,level =错误,路径= com / creo / drools / decisiontables / ,line = 0,column = 0
text = Parser返回一个空包]]

似乎有些东西不能正确地与从子句,但我不知道为什么。我已经尝试了大量的谷歌搜索,这是我能找到的唯一的东西: http://drools-moved.46999.n3.nabble.com/Question-on-excel-decision-table-with-quot -variable-Type-from-collection-quot-td1186138.html



任何想法?

解决方案

你想要的模式格式是不可能的与Drools电子表格编译器。如果你阅读文档,它会说,CONDITION下的单元格提供模式CE,通常是类名,下面的单元格指定一个约束,即一个表达式必须适合之间的括号对添加到上面的模式。



添加缺少的括号,然后将 $ param 您的条件扩展为(无效)DRL代码:

  $ person:Person(ArrayList(size> = 1)
from collect(TestResult(name in(TestA,TestB),result =='high')
from $ person.getLabResults()))
/ pre>

这会导致您报告的错误消息,因为从 c>错误放置。



我有这个代码片段,如果你可以从任何地方导入类SpreadsheetCompiler,调用将显示生成的DRL,对或错。

  private void testSpreadsheet(String dtPath){
File dtf = new File(dtPath);
InputStream is;
try {
is = new FileInputStream(dtf);
SpreadsheetCompiler ssComp = new SpreadsheetCompiler();
String s = ssComp.compile(is,InputType.XLS);
System.out.println(=== Begin generated DRL ===);
System.out.println(s);
System.out.println(=== End generated DRL ===);
} catch(IOException e){
// TODO自动生成的catch块
e.printStackTrace();
}
}



如果你需要生成大量的规则列表测试结果,你应该看看Drools模板。使用这种技术,可以将参数插入到任意规则文本中。其他解决方法也是可行的,例如,DRL和电子表格规则的组合。


I'm having some trouble getting a rule that I know works in .drl form, to work in a decision table.

Here is my rule in drl form:

rule = "slider1"
    dialect "mvel"
    when
        $person: Person()
        ArrayList( size >= 2 )
            from collect( TestResult( name in ("TestA","TestB"), result == "high" )
                           from $person.getLabResults()
                        )
    then
        $person.setString("It worked");
end

Here is what I am trying in the spreadsheet:

CONDITION
-------------------
$person:Person()
-------------------
ArrayList( size >= 1 ) 
    from collect( TestResult( name in $param, result == 'high' ) 
       from $person.getLabResults() ) 
-------------------
Lab Names
-------------------
"TestA","TestB"

When I try to run the rule from the spread sheet, I am getting this error:

Error while creating KieBase[Message [id=1, level=ERROR, path=com/creo/drools/decisiontables/sample-decision-table.xls, line=11, column=0
text=[ERR 102] Line 11:53 mismatched input 'from' in rule "Young safe package 1"], Message [id=2, level=ERROR, path=com/creo/drools/decisiontables/sample-decision-table.xls, line=0, column=0
text=Parser returned a null Package]]

It seems like something isn't working correctly with the from clause, but I have no idea why. I have tried numerous google searches and this is the only thing I could find: http://drools-moved.46999.n3.nabble.com/Question-on-excel-decision-table-with-quot-variable-Type-from-collection-quot-td1186138.html

Any ideas? It's driving me crazy why this won't work in the spread sheet.

解决方案

The pattern format you want to have is not possible with the Drools spreadsheet compiler. If you read the documentation, it will say that the cell under CONDITION provides the pattern CE, typically a class name, and the next cell below specifies a constraint, i.e., an expression that must fit between the pair of parentheses added to the pattern above. The placeholder $param will then repeatedly be replaced by cell values further down the column.

Adding the missing parentheses, your condition expands into (invalid) DRL code:

$person:Person( ArrayList( size >= 1 ) 
from collect( TestResult( name in ("TestA","TestB"), result == 'high' ) 
   from $person.getLabResults() ) )

This causes just the error message you've reported, due to the misplaced from.

I have this snippet of code lying around, and if you can import class SpreadsheetCompiler from wherever it is, a call will display the generated DRL, right or wrong.

private void testSpreadsheet(String dtPath){
  File dtf = new File( dtPath );
  InputStream is;
  try {
    is = new FileInputStream( dtf );
    SpreadsheetCompiler ssComp = new SpreadsheetCompiler();
    String s = ssComp.compile( is, InputType.XLS );
    System.out.println( "=== Begin generated DRL ===" );
    System.out.println( s );
    System.out.println( "=== End generated DRL ===" );
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
}

If you need to generate lots of rules with lists of test results you should look into Drools templates. With this technique, parameter insertion into arbitrary rule text is possible. Other workarounds may also be viable, e.g., a combination of DRL and spreadsheet rules.

这篇关于Drools - 使用“from”在决策表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆