규칙 세트 실행 메소드 편집

규칙용 Java™ 프로젝트를 작성한 후 기본 클래스는 작성되지만 매개변수를 정의하고 필요에 따라 클래스를 완성하기 위해 편집해야 합니다.

프로시저

  1. 규칙 세트를 로드하십시오.
    try {
         // --------------------------------------------------------------------
         // Retrieve the ruleset archive JAR file using the Java I/O API.
         // --------------------------------------------------------------------
       FileInputStream fileStream = 
          new FileInputStream(the_archive_rule_name);
       JarInputStream jarStream = new JarInputStream(fileStream);
         // ----------------------------------------------
         // Create the ruleset archive parsing objects.
         // ----------------------------------------------
       IlrJarArchiveLoader loader = 
          new IlrJarArchiveLoader(jarStream);
       IlrRulesetArchiveParser parser = 
          new IlrRulesetArchiveParser();
         // ----------------------------------------------
         // Create a ruleset to store the parsed rules.
         // ----------------------------------------------
       IlrRuleset ruleset = new IlrRuleset();
         // -----------------------------------------------------------------
         // Connect the Ruleset to the Ruleset Archive parser so that
         // the parsed rules are accumulated in the Ruleset as the parsing
         // is peformed.
         // -----------------------------------------------------------------
       parser.setRuleset(ruleset);
         // ---------------------------------------------
         // Launch the parsing of the Ruleset Archive:
         // ---------------------------------------------
       if (! parser.parseArchive(loader)) {
             // -----------------------------------
             // In case of errors, list the errors.
             // -----------------------------------
           String[] errors = parser.getErrors();
           for (int i = 0; i < errors.length; i++) {
                String error = errors[i];
                System.err.println("Error while parsing Ruleset Archive:" 
                                    + error);
           }
       }
       else {
           // ----------------------------------------------------------------
           // [Optional] Optimize the ruleset if in RETE and if runtime
           // resources (time) permit.
           // ----------------------------------------------------------------
           IlrRulesetOptimConfig config = new IlrRulesetOptimConfig();
           config.hasherGeneration = true;   
           
           // adapt the optimization to your needs
           config.wmModifiedByCode = false;  
           
           // adapt the optimization to your needs
           ruleset.optimize(config);
       }
    catch (Exception exception) {
    exception.printStackTrace(System.err);
    }
  2. 규칙 세트를 기반으로 엔진을 작성하십시오.
    IlrContext engine = new IlrContext(ruleset);
  3. 규칙 세트 매개변수값을 설정하고 작업 메모리에 오브젝트를 삽입하십시오.
    engine.setParameterValue(“myParam”,myValue);
    ...
    engine.insert(myObject);
    ...
  4. 엔진을 실행하십시오.
    engine.execute();
  5. 다른 실행을 위해 규칙 엔진을 준비하십시오.
    1. 규칙 엔진에서 수정한 후 오브젝트를 검색하십시오.
      engine.retractAll();
    2. 규칙 세트 매개변수값을 정리하십시오.
      engine.cleanRulesetVariables();
      ();
    3. 규칙 플로우를 다시 설정하십시오.
      engine.resetRuleflow();
  6. [선택사항] 규칙 엔진을 종료하고 메모리를 여유롭게 하십시오.
    engine.end();
    참고:

    구문 분석된 규칙 세트는 구문 분석이 발생할 때 반드시 비어 있는 것은 아닙니다. 규칙 세트가 이미 엔진에 있는 경우 충돌 시 규칙, 기능, 태스크 등의 최근 버전을 고려하여 병합이 자동으로 발생합니다.