DrlParser不会解析Drools规则具有after,before和巧合

时间:2019-07-14 12:21:27

标签: java drools

我正在尝试使用Java中的DrlParser库解析规则文件。我能够解析所有规则,但不能解析具有CEP关键字(例如after,before,Coincides等)的规则。是否需要任何其他设置?

The highlighted below is the working rule.

全局java.util.Map patternIdNameMap

declare  LogEvent 
    @role( event )
    @timestamp( getTimeStamp() )

end

rule "BC0E7030-99B1-C7EA-F7D4-08D2B44E9B74"

when
    $eventB : LogEvent(getEventInfo().getEventID() == "063001051" )  

then
    if(patternIdNameMap.get("BC0E7030-99B1-C7EA-F7D4-08D2B44E9B74") == null)
    {
        patternIdNameMap.put("BC0E7030-99B1-C7EA-F7D4-08D2B44E9B74","06RMT ");
    }
end

When added with CEP conditions, the rule is not getting parsed by the DRLParser.

global java.util.Map patternIdNameMap

declare  LogEvent 
    @role( event )
    @timestamp( getTimeStamp() )

end

rule "BC0E7030-99B1-C7EA-F7D4-08D2B44E9B74"

when
    $eventB : LogEvent(getEventInfo().getEventID() == "063001051" )  

    $eventC : LogEvent( this after $eventB)
then
    if(patternIdNameMap.get("BC0E7030-99B1-C7EA-F7D4-08D2B44E9B74") == null)
    {
        patternIdNameMap.put("BC0E7030-99B1-C7EA-F7D4-08D2B44E9B74","06RMT ");
    }
end

public List<RuleDescr> readRulesNames (){
    List<RuleDescr> lstRuleDes = new ArrayList<>();
    KieFileSystem kieFileSystem = null;
    try {
        DrlParser drlParser = new DrlParser(LanguageLevelOption.DRL6);
        final Reader reader= new InputStreamReader(
                new FileInputStream(
                        new File(
                                "C:\\DawRules3.2.drl")));
        final PackageDescr packageDescr = drlParser.parse(reader);

        // Read the results
        boolean hasErrors = drlParser.hasErrors();
        if (hasErrors) {
            System.out.println("Has errors while parsing ?" + hasErrors);
            for (DroolsError droolsError: drlParser.getErrors()) {
                System.err.println(droolsError.getMessage());
            }
        }
        lstRuleDes = packageDescr != null ? packageDescr.getRules(): new ArrayList<>();
    }  catch (DroolsParserException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return lstRuleDes;
}

使用after,fore解析规则时出现以下错误。

[ERR 102] Line 27:29 mismatched input 'after' in rule "BC0E7030-99B1-C7EA-F7D4-08D2B44E9B74"

0 个答案:

没有答案