简体   繁体   English

如何在Drools规则中声明列表

[英]How to declare a List in Drools rule

I've got a simple object construction. 我有一个简单的对象构造。 The class ContextDroolsObject has a property of type Map called objects . ContextDroolsObject具有Map类型的属性,称为objects Inside that map there's a key "imageThemes" with an ArrayList and this rule here never matches: 在该映射内,有一个带有ArrayList的键"imageThemes" ,这里的规则永远不匹配:

import java.util.ArrayList;
import java.util.Map;
import com.my.ContextDroolsObject;

dialect 'java'


rule 'Soccer Image Theme'
    salience 100
    when
        s : ContextDroolsObject()
        objectsm : Map() from s.objects
         imageThemesList : ArrayList() from outputsm.imageThemes
    then
System.out.println("-----------------------soccer");
    end

I've also tried with List() with same result. 我也尝试过用List()获得相同的结果。

¿How to match the list declaration? ¿如何匹配列表声明?

Hi you can rewrite your rule in this way: 嗨,您可以通过以下方式重写规则:

import java.util.ArrayList;
import java.util.Map;
import com.my.ContextDroolsObject;

dialect 'java'


rule 'Soccer Image Theme'
salience 100
when
    s : ContextDroolsObject( imageThemesList : objects#Map.get("imageThemes") )
then
    System.out.println("-----------------------soccer");
end

Using a hierarchical structure for fact objects is ver frequently a design flaw. 对事实对象使用分层结构通常是设计缺陷。 You may not be able to reason conveniently over the list elements. 您可能无法方便地对列表元素进行推理。

Anyway, this is the way to extract the list within the map from the ContextDroolsObject. 无论如何,这是从ContextDroolsObject提取地图中列表的方法。

rule 'Soccer Image Theme'
  salience 100
when
  s: ContextDroolsObject() 
  imageThemesList: ArrayList() from s.getObjects().get( "imageThemes" )
then
  System.out.println("-----------------------soccer");
end

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

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