コード例 #1
0
ファイル: AbstractDRLEmitter.java プロジェクト: adinn/drools
  protected void createSummationRules(List<Rule> ruleList, Scorecard scorecard) {
    String objectClass = scorecard.getModelName().replaceAll(" ", "");
    Rule calcTotalRule = new Rule(objectClass + "_calculateTotalScore", 1, 1);
    StringBuilder stringBuilder = new StringBuilder();
    Condition condition = new Condition();
    stringBuilder
        .append("$calculatedScore : Double() from accumulate (PartialScore(scorecardName ==\"")
        .append(objectClass)
        .append("\", $partialScore:score), sum($partialScore))");
    condition.setSnippet(stringBuilder.toString());
    calcTotalRule.addCondition(condition);
    if (scorecard.getInitialScore() > 0) {
      condition = new Condition();
      stringBuilder = new StringBuilder();
      stringBuilder
          .append("InitialScore(scorecardName == \"")
          .append(objectClass)
          .append("\", $initialScore:score)");
      condition.setSnippet(stringBuilder.toString());
      calcTotalRule.addCondition(condition);
    }
    ruleList.add(calcTotalRule);

    if (scorecard.isUseReasonCodes()) {
      String ruleName = objectClass + "_collectReasonCodes";
      Rule rule = new Rule(ruleName, 1, 1);
      rule.setDescription("collect and sort the reason codes as per the specified algorithm");
      condition = new Condition();
      stringBuilder = new StringBuilder();
      stringBuilder
          .append("$reasons : List() from accumulate ( PartialScore(scorecardName == \"")
          .append(objectClass)
          .append("\", $reasonCode : reasoncode ); collectList($reasonCode) )");
      condition.setSnippet(stringBuilder.toString());
      rule.addCondition(condition);
      ruleList.add(rule);

      addAdditionalReasonCodeCondition(rule, scorecard);
      addAdditionalReasonCodeConsequence(rule, scorecard);
    }

    addAdditionalSummationCondition(calcTotalRule, scorecard);
    addAdditionalSummationConsequence(calcTotalRule, scorecard);
  }
コード例 #2
0
 /**
  * This makes sure that the rules have all their components added. As when there are
  * merged/spanned cells, they may be left out.
  */
 private void flushRule() {
   for (Iterator<SourceBuilder> iter = sourceBuilders.iterator(); iter.hasNext(); ) {
     SourceBuilder src = iter.next();
     if (src.hasValues()) {
       switch (src.getActionTypeCode()) {
         case CONDITION:
           Condition cond = new Condition();
           cond.setSnippet(src.getResult());
           _currentRule.addCondition(cond);
           break;
         case ACTION:
           Consequence cons = new Consequence();
           cons.setSnippet(src.getResult());
           _currentRule.addConsequence(cons);
           break;
         case METADATA:
           _currentRule.addMetadata(src.getResult());
           break;
       }
       src.clearValues();
     }
   }
 }
コード例 #3
0
ファイル: AbstractDRLEmitter.java プロジェクト: adinn/drools
  protected void createInitialRule(List<Rule> ruleList, Scorecard scorecard) {
    if (scorecard.getInitialScore() > 0 || scorecard.isUseReasonCodes()) {
      String objectClass = scorecard.getModelName().replaceAll(" ", "");
      String ruleName = objectClass + "_init";
      Rule rule = new Rule(ruleName, 999, 1);
      rule.setDescription("set the initial score");

      Condition condition = createInitialRuleCondition(scorecard, objectClass);
      rule.addCondition(condition);
      if (scorecard.getInitialScore() > 0) {
        Consequence consequence = new Consequence();
        // consequence.setSnippet("$sc.setInitialScore(" + scorecard.getInitialScore() + ");");
        consequence.setSnippet(
            "insertLogical(new InitialScore(\""
                + objectClass
                + "\","
                + scorecard.getInitialScore()
                + "));");
        rule.addConsequence(consequence);
      }
      if (scorecard.isUseReasonCodes()) {
        for (Object obj : scorecard.getExtensionsAndCharacteristicsAndMiningSchemas()) {
          if (obj instanceof Characteristics) {
            Characteristics characteristics = (Characteristics) obj;
            for (Characteristic characteristic : characteristics.getCharacteristics()) {
              String field = ScorecardPMMLUtils.extractFieldNameFromCharacteristic(characteristic);
              Consequence consequence = new Consequence();
              if (characteristic.getBaselineScore() == null
                  || characteristic.getBaselineScore() == 0) {
                consequence.setSnippet(
                    "insertLogical(new BaselineScore(\""
                        + objectClass
                        + "\",\""
                        + field
                        + "\","
                        + scorecard.getBaselineScore()
                        + "));");
                // consequence.setSnippet("$sc.setBaselineScore(\"" + field +
                // "\","+scorecard.getBaselineScore()+");");
              } else {
                consequence.setSnippet(
                    "insertLogical(new BaselineScore(\""
                        + objectClass
                        + "\",\""
                        + field
                        + "\","
                        + characteristic.getBaselineScore()
                        + "));");
                // consequence.setSnippet("$sc.setBaselineScore(\"" + field +
                // "\","+characteristic.getBaselineScore()+");");
              }
              rule.addConsequence(consequence);
            }
          }
        }
        if (scorecard.getReasonCodeAlgorithm() != null) {
          Consequence consequence = new Consequence();
          if ("pointsAbove".equalsIgnoreCase(scorecard.getReasonCodeAlgorithm())) {
            // TODO: ReasonCode Algorithm
            consequence.setSnippet(
                "//$sc.setReasonCodeAlgorithm(DroolsScorecard.REASON_CODE_ALGORITHM_POINTSABOVE);");
          } else if ("pointsBelow".equalsIgnoreCase(scorecard.getReasonCodeAlgorithm())) {
            consequence.setSnippet(
                "//$sc.setReasonCodeAlgorithm(DroolsScorecard.REASON_CODE_ALGORITHM_POINTSBELOW);");
          }
          rule.addConsequence(consequence);
        }
      }
      ruleList.add(rule);
    }
  }