zoukankan      html  css  js  c++  java
  • Drools 规则文件 ——语法属性

    1.salience 
    功能:设置规制执行的优先级
    值:数字(数字越大执行优先级越高)
    示例:
    rule "rule1" 
      salience
      when 
    eval(true) 
      then  
    System.out.println("rule1");
    end 
     
    2.no-loop
    功能:控制已经执行的规则条件再次满足是否再次执行
    值:true/false
    示例:
    rule "rule1" 
      no-loop true 
      when 
      $customer:Customer(name=="张三") 
      then  
       update($customer); 
      System.out.println("customer name:"+$customer.getName()); 
      End
     
    3.activation-group
    功能:若干个规则划分成一个组
    值:分组名称
     
    示例:
    rule "rule2"
     activation-group "test"
     salience 10 
     when
      eval(true)
      then
        System.out.println("rule2 execute");
     end
     
     rule "rule1"
     activation-group "test"
     salience 9
     when
     eval(true)
     then
     System.out.println("rule1 execute");
    end 
     
    note:
    如果同一组规则,谁的salience高就执行谁,没有则按顺序执行最后同组最后那个规则
     
     
     
    4.declare
    作用:
    Drools除了可以接受用户在外部向 WorkingMemory当中插入现成的
    Fact对象,还允许用户在规则文件当中定义一个新的 Fact对象。
     
    语法:
    declare Address
    熟悉名 : 类型
    end
     
    示例:
    package com.demo.fact
     
    declare Address
    city : String
    addressName : String
    end
     
    rule "rule1"
    salience 2
    when
    eval(true);
    then 
    Address add = new Address();
    add.setCity("中国上海");
    add.setAddressName("中国上海松江区");
    insert(add);
    end
     
     
    5.date-expires
    功能:当系统时间<=date-expires后才会触发
    值:日期默认格式为dd-MMM-yyyy
    可以设置其它时间格式如yyyy-MM-dd,需在代码设置系统时间格式System.setProperty("drools.dateformat", "yyyy-MM-dd");
     
    示例:
    rule "rule1" 
      date-expires "2009-09-27" 
      when 
      eval(true); 
      then  
      System.out.println("rule1 is execution!");  
      end 
       
  • 相关阅读:
    tyvj1117 拯救ice-cream
    codevs3410 别墅房间
    codevs1099 字串变换
    codevs1226 倒水问题
    codevs2449 骑士精神
    codevs1225 八数码难题
    Wikioi 3776 生活大爆炸版石头剪子布
    codevs1197 Vigenère密码
    枚举 + exgcd
    C++ 排序引用的优化
  • 原文地址:https://www.cnblogs.com/kunpengit/p/3105627.html
Copyright © 2011-2022 走看看