0

当我没有议程组时,我的口水工作正常,但如果我设置焦点,我会收到以下错误:

package drools;

import droolsexec.Message;
import droolsexec.Customer;


rule "Good Bye"
agenda-group "group1"
  dialect "java"

when


 message: Message( status =="GOODBYE" )
 customer: Customer(name == "NEHA")

then
  System.out.println( message.getStatus()); 
end

这是我的规则,我通过以下方式执行它:

public class ExecuteDrools {

private static PackageBuilder pbuilder = new PackageBuilder();
private static StatefulSession sessionObject;   
private static RuleBase rbase = RuleBaseFactory.newRuleBase();

public  void runDrools(ArrayList list){

    initialiseDrools();
    initiliseMessageObject(list);
    runRules();     

}



private  void initialiseDrools() {


    //1. Read the DRL File and add to package builder
    try {
        Reader reader = new InputStreamReader(ExecuteDrools.class.getResourceAsStream("/HelloWorld.drl"));

        pbuilder.addPackageFromDrl(reader);
    } catch (DroolsParserException ex) {
        Logger.getLogger(ExecuteDrools.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ExecuteDrools.class.getName()).log(Level.SEVERE, null, ex);
    }

    //2. Check for any errors
    PackageBuilderErrors errors = pbuilder.getErrors(); 
    if (errors.getErrors().length > 0) {
        System.out.println("Some errors exists in packageBuilder");
        for (int i = 0; i < errors.getErrors().length; i++) {
            System.out.println(errors.getErrors()[i]);
        }
        throw new IllegalArgumentException("Could not parse knowledge.");
    }
    //3. Add package to rule base
    try {
        rbase.addPackage(pbuilder.getPackage());
    } catch (Exception e) {
        System.out.println("Error: "+ e);
    }


}

private   void initiliseMessageObject(ArrayList list) {
    sessionObject = rbase.newStatefulSession();
    Iterator itr = list.iterator();
    while(itr.hasNext()){
        sessionObject.insert(itr.next());
    }
}


private  void runRules() {
    sessionObject.getAgenda().getAgendaGroup("group2").setFocus(); 
    sessionObject.fireAllRules();
}

}

我收到以下错误:

在 droolsexec.ExecuteDrools.runRules(ExecuteDrools.java:83) 在 droolsexec.ExecuteDrools.runDrools(ExecuteDrools. java:36) 在 droolsexec.MainClass.executeRules(MainClass.java:23) 在 droolsexec.MainClass.main(MainClass.java:9)

4

1 回答 1

0

您的 drl 文件中没有议程组 group2...您将其命名为 group 1

于 2014-10-23T14:37:35.150 回答