首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

drools中运用excel

2013-08-23 
drools中使用excel在drools中如果使用规则表? ? ??典型的用法就是根据excel创建KnowledgeBase,然后将它丢

drools中使用excel

    • 在drools中如果使用规则表? ? ??典型的用法就是根据excel创建KnowledgeBase,然后将它丢给session执行,执行的参数和结果都在params里面

      ??
      1. RuleSet关键字是必须的,名字是可选的
      2. Import语句非常像java的import,如果有多个import,用逗号隔开
      3. RuleTable关键字也是必须的,它指示了后面将会有一批rule,ruletable的名称将会作为以后生成rule的前缀
      4. 条件如果不写的话默认就是==, 比如上面的contract.get("productLine"),其实就是contract.get("productLine") == $param, 如果有多个参数可以使用$1,$2,比如我们经常用到的一个区间数据,这个占位符就派上用场了
      5. 所有的关键字都是忽略大小写的
      6. 默认情况下规则引擎只解析第一个sheet的规则
      规则区域所支持的关键字KeywordValueUsageRuleSetThe package name for the generated DRL file. Optional, the default is?rule_table.(默认值是rule_table)Must be First entry.Sequential"true" or "false". If "true", then salience is used to ensure that rules fire from the top down.(规则触发是从上朝下,如果是false就是乱序)Optional, at most once. If omitted, no firing order is imposed.ImportA comma-separated list of Java classes to import.(逗号隔开)Optional, may be used repeatedly.VariablesDeclarations of DRL globals, i.e., a type followed by a variable name. Multiple global definitions must be separated with a comma.?全局变量定义,多个用逗号隔开Optional, may be used repeatedly.FunctionsOne or more function definitions, according to DRL syntax.Optional, may be used repeatedly.QueriesOne or more query definitions, according to DRL syntax.Optional, may be used repeatedly.? ? ? ? 需要特别注意的是这些关键字只能出现一次!?
    • Rule Table的头部所支持的关键字KeywordInitialValueUsageNAMENProvides the name for the rule generated from that row. The default is constructed from the text following the RuleTable tag and the row number.At most one columnDESCRIPTIONIA text, resulting in a comment within the generated rule.At most one columnCONDITIONCCode snippet and interpolated values for constructing a constraint within a pattern in a condition.At least one per rule tableACTIONACode snippet and interpolated values for constructing an action for the consequence of the rule.At least one per rule tableMETADATA@Code snippet and interpolated values for constructing a metadata entry for the rule.Optional, any number of columns
    • 将excel编译成规则文件

      ? ?

      ? ? ? ? 编译后的结果如下:

      ? ? ? ??

      ? ? ?// "John".equals(person.getFirstName())? ? ?Person( firstName == "John" )?? ? ?The != operator has null-safe !equals() semantics:? ? ?// Similar to: !java.util.Objects.equals(person.getFirstName(), "John")? ? ? Person( firstName != "John" )

      ?

      ??????

  • 热点排行