Pregunta

how do I invoke ilrmain function in ilog jrules , is it invoked implcitly or do we have to explcitly invoke , in the latter case , how do I do it. IBM documentation is very obscure regarding ilrmain function.

¿Fue útil?

Solución

IlrMain provides an easy way to test your rules without too much overhead. You define your input variables, create your testcase and invoke the rule execution with context.execute. After execution, you can display the result.

Here's a small example: Imagine you've created a ruleset to decide whether to grant a loan or not. Your input is called application of type LoanApplication and you expect a decision in your output. Your IlrMain would look something like this:

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);

To start the IlrMain, click on Run > Run Configurations... > Rule Project and create a new run configuration for your rule project. Select the project with your IlrMain-Function and make shure Launch project with function ilrmain is selected. Under Parameters & Arguments you should select Clear All Values so that the parameter from your IlrMain are being used for execution. Apply and Run

In your command line, your loan decision should appear. Something like:

Loan Decision: green

Otros consejos

Note: inside your "Run Configuration" you can make the ruleset creation automated.
So you don't need to create manually a new ruleset everytime you change a rule...
Exporting the ruleset is a pain in the back if you change the rules often, like when you are testing something in your rule artifacts.

Your code could look like this as well:

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“);

Play with you Report in Java or assert stuff...

Hope it helps

There's a problem with clearing all parameters from the parameters page, after selecting the 'Launch Project with function ilrmain' in the Rule Project Page/Tab; You cannot Run the ilrmain technical function without the arguments set. You need to set the argument expression to something, it could be emplty values. Suppose the XOM has constructor with no arguments {Customer()}; then set the argument expression to 'new Customer()' Save and run the ilrmain. Make sure the CLASSPATH VARIABLE IS SET to rule-engine.jar file and run the function. It should work. If you have any more questions, please post back. Here's a sample- (Rule fire count will confirm if the rule was acutally fired), use the ilrmain signature as 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 (); 
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top