Witmate

mate of your wit
The most performed Mobile/Embedded
java Logic/Rule Engine

 
     Home
     Get Start
          JSR-94 TCK
     Document
     Download
     News
     Contribution
     Contact
    
    
    
    
    
 

 

Get Start

As start, lets check the normal steps to use Witmate with a very simple logic set.

 

1. Define logic by Simple Logic Language

 
  LogicSet CustomerLevel
      Def text sex
      Def int age     
      If sex="female" and 16<age<25 Then Return "young_girl"
      If sex="male" and age>50  Then Return "old_man"
  and save to a file named logic.sl.

 

2. Load logic set into Witmate and run it through WitME, a JSR-94 like interface executable on J2ME.

 
  FileReader fr=new FileReader("logic.sl");
  //parse the logic set
  RuleServiceProvider serviceProvider = (RuleServiceProvider)Class.forName("witmate.core.kernel.ServiceProvider").newInstance();
  RuleExecutionSet res = serviceProvider.getRuleAdministrator().getLocalRuleExecutionSetProvider( null ).createRuleExecutionSet( fr, new Hashtable());
  //Register the RuleExecutionSet 
  serviceProvider.getRuleAdministrator().registerRuleExecutionSet("A Rule URI", res, null );
  //Get a RuleRuntime and invoke the rule engine.
  RuleRuntime ruleRuntime = serviceProvider.getRuleRuntime();
  //Generate inputs
  ConstantVariable V1=new ConstantVariable();
  V1.name="sex";  V1.type=ConstantValues.DT_STR;  V1.value="female";  
  ConstantVariable V2=new ConstantVariable();
  V2.name="age";  V2.type=ConstantValues.DT_INT;  V2.value=new Integer(20);
  Vector in_vars=new Vector();
  in_vars.addElement(V1);  in_vars.addElement(V2);
  //Create a StatelessRuleSession
  StatelessRuleSession statelessRuleSession = (StatelessRuleSession) ruleRuntime.createRuleSession(res.getName(), new Hashtable(),  RuleRuntime.STATELESS_SESSION_TYPE);
  //Run logic and get result.
  Vector results = statelessRuleSession.executeRules(in_vars);
  //Release the session.
  statelessRuleSession.release();

 

3. Get the result

   
 System.out.println(results.elementAt(0));     


Next: Replay JSR-94 TCK Witmate case or learn more.
 

Copyright 1998-2009, Witsign. All rights reserved.