1

我一直在为特定的问题陈述编写规则。我有一个 excel 文件,其中包含列 id、specialty、salary。专业可以取“肿瘤学”,“泌尿学”等值。我必须计算每个专业对应的总工资。有两种方法可以做到这一点。

第一的:

rule "Total salary of Oncology" 

no-loop
lock-on-active
salience 100
    when

    $m : Masterclass( $id : phyid , $p : p,spec=="Oncology")
     not Masterclass( spec=="Oncology", phyid < $id)
    $total : Number() from accumulate ( Masterclass(  $salary : salary ,spec=="Oncology") ,
                init( double total =0;), 
                action(total+=$salary;),
                result(  new Double (total)))
    then
    System.out.println($m.getSpec());
    System.out.println("Total target pay is : " + $total + " of specialty : "+ $m.getSpec());
    retract($m);
end 

其他专业也是如此。这条规则很好用。

第二:只写一条规则,读取专业值,然后总结对应的工资。我试图实现这一点,但没有成功。任何帮助将不胜感激。

4

1 回答 1

2

这远非完美。但请注意,您不必插入一些特定的字符串。运行没有字符串匹配的规则无论如何都会产生所有专业的累积总和。

而且您应该将 String 包装到一个 Java 类中——我只是懒得发明一个具有一个字段的适当 Java 类。

rule "trigger read"
when
  not String()
then
  String s = read_any_way_you_want();
  insert( s );
end;

rule "Total salary of something" 
when
  $spec: String()
  $m : Masterclass( $id: phyid , spec == $spec)
  not Masterclass( spec == $spec, phyid < $id)
  $total : Number() from
     accumulate ( Masterclass($salary: salary, spec == $spec) ,
            init( double total =0;), 
            action(total+=$salary;),
            result( new Double (total)))
then
  System.out.println($m.getSpec());
  System.out.println("Total target pay is : " + $total + 
                     " o specialty : "+ $m.getSpec());
  retract($spec);
end 
于 2016-02-08T12:42:13.117 回答