如何在ilog jrules中调用ilrmain函数,它是以内嵌方式调用的,还是必须显式调用,在后一种情况下,我该如何做?关于ilrmain函数,IBM文档非常模糊。
发布于 2012-03-21 22:15:05
IlrMain提供了一种简单的方法来测试您的规则,而没有太多的开销。您定义输入变量,创建测试用例,并使用context.execute调用规则执行。执行完成后,即可显示结果。
这里有一个小示例:假设您创建了一个规则集来决定是否发放贷款。您的输入称为LoanApplication类型的应用程序,并且您希望在输出中有一个决策。您的IlrMain将如下所示:
LoanApplication app = new LoanApplication();
app.loanAmount = 5000
Applicant applicant = new Applicant();
app.applicant = applicant;
applicant.dateOfBirth = new ilog.rules.xml.types.IlrDate("1980-01-01");
applicant.income = 2000;
applicant.fixedExpenses = 600;
input = app;
context.execute();
System.out.println("Loan Decision: "+output.decision);要启动IlrMain,请单击Run > Run Configurations...>规则项目,为您的规则项目创建新的运行配置。选择带有IlrMain-Function的项目,并选择带有ilrmain函数的舒尔Launch项目。在Parameters & Arguments下面,您应该选择,Clear All Values,这样您的IlrMain中的参数就可以用于执行。应用并运行
在您的命令行中,您的贷款决策应该会出现。类似于:
Loan Decision: green发布于 2012-04-18 23:34:36
注意:在您的“运行配置”中,您可以自动创建规则集。
因此,您不需要在每次更改规则时手动创建新的规则集...
如果您经常更改规则,那么导出规则集是一件痛苦的事情,就像您在测试规则工件中的某些东西时一样。
您的代码也可能如下所示:
IlrSessionFactory factory = new IlrJ2SESessionFactory();
IlrStatelessSession session = factory.createStatelessSession();
IlrSessionRequest sessionRequest = factory.createRequest();
sessionRequest.setRulesetPath(“/RuleAppName/rulesetName”);
sessionRequest.setTraceEnabled(true);
sessionRequest.getTraceFilter().setInfoAllFilters(true);
Map inputParameters = new HashMap ();
Report in_report = new Report(); // no-arg constructor
// ...populate the report...
inputParameters.put("report", in_report);
sessionRequest.setInputParameters(inputParameters);
IlrSessionResponse sessionResponse = session.execute(sessionRequest);
Report out_report = (Report)sessionResponse.getOutputParameters().get("report“);
使用Java报告或断言内容...
希望能有所帮助
发布于 2013-11-20 06:42:47
在Rule Project page /Tab中选择'Launch Project with function ilrmain‘后,从parameters页面中清除所有参数时会出现问题;如果没有设置参数,则无法运行ilrmain技术函数。您需要将参数表达式设置为某个值,它可以是emplty值。假设XOM具有不带参数的构造函数{Customer()};然后将参数表达式设置为'new Customer()‘保存并运行ilrmain。确保将CLASSPATH变量设置为rule-engine.jar文件并运行函数。应该能行得通。如果你还有任何问题,请回帖。下面是一个示例- (Rule fire count将确认规则是否被实际触发),使用ilrmain签名作为void ilrmain(Object Arg)。
customer.firstName="Abhishek";
customer.age=17;
int nrules = 0;
insert customer;
execute ();
System.out.println(" The last name of the customer is " + customer.lastName );
System.out.println("The first name of the customer is " +customer.firstName);
nrules += returnValues.getIntValue("ilog.rules.firedRulesCount");
System.out.println("The Number of rules fired " + nrules);
//retractAll();
//reset (); https://stackoverflow.com/questions/9718138
复制相似问题