@Test
  public void test_whenSetPredicatesOnNewInstance()
      throws IllegalAccessException, InstantiationException {

    CompoundPredicate o = klass.newInstance();
    Predicate truePredicate = new TruePredicate();
    o.setPredicates(new Predicate[] {truePredicate});
    assertEquals(truePredicate, o.getPredicates()[0]);
  }
Ejemplo n.º 2
0
 private Predicate pCompoundPredicate(HashMap<String, String> attrs) {
   expect(">");
   CompoundPredicate cp =
       CompoundPredicate.make(BooleanOperators.valueOf(attrs.get("booleanOperator")));
   cp._l = skipWS().expect('<').pPredicate();
   cp._r = skipWS().expect('<').pPredicate();
   skipWS().expect("</CompoundPredicate>");
   return cp;
 }
  @Test(expected = IllegalStateException.class)
  public void test_whenSetPredicatesOnExistingPredicates_thenThrowException()
      throws IllegalAccessException, InstantiationException {

    CompoundPredicate o = klass.newInstance();
    Predicate truePredicate = new TruePredicate();
    o.setPredicates(new Predicate[] {truePredicate});

    Predicate falsePredicate = new FalsePredicate();
    o.setPredicates(new Predicate[] {falsePredicate});

    fail();
  }
Ejemplo n.º 4
0
  // Reads: group (compoundOperator group)*
  private Predicate readPredicate(Queue<String> tokens, ParameterList parameters) {
    Predicate predicate = readGroup(tokens, parameters);

    if (predicate != null) {
      for (String operator; (operator = tokens.peek()) != null; ) {

        operator = operator.toLowerCase(Locale.ENGLISH);
        String compoundOperator = getCompoundOperators().get(operator);
        if (compoundOperator == null) {
          break;
        }

        tokens.remove();
        predicate =
            CompoundPredicate.combine(compoundOperator, predicate, readGroup(tokens, parameters));
      }
    }

    return predicate;
  }
Ejemplo n.º 5
0
  protected void createFieldRestriction(
      PMML pmmlDocument, Characteristic c, Attribute scoreAttribute, StringBuilder stringBuilder) {
    stringBuilder.append("(");
    // String dataType = ScorecardPMMLUtils.getExtensionValue(c.getExtensions(),
    // PMMLExtensionNames.CHARACTERTISTIC_DATATYPE);
    String dataType =
        ScorecardPMMLUtils.getDataType(
            pmmlDocument, ScorecardPMMLUtils.extractFieldNameFromCharacteristic(c));
    if (XLSKeywords.DATATYPE_TEXT.equalsIgnoreCase(dataType)) {
      if (scoreAttribute.getSimplePredicate() != null) {
        SimplePredicate predicate = scoreAttribute.getSimplePredicate();
        String operator = predicate.getOperator();
        if (PMMLOperators.EQUAL.equalsIgnoreCase(operator)) {
          stringBuilder.append(predicate.getField());
          stringBuilder.append(" == ");
          stringBuilder.append("\"").append(predicate.getValue()).append("\"");
        } else if (PMMLOperators.NOT_EQUAL.equalsIgnoreCase(operator)) {
          stringBuilder.append(predicate.getField());
          stringBuilder.append(" != ");
          stringBuilder.append("\"").append(predicate.getValue()).append("\"");
        }
      } else if (scoreAttribute.getSimpleSetPredicate() != null) {
        SimpleSetPredicate simpleSetPredicate = scoreAttribute.getSimpleSetPredicate();
        String content = simpleSetPredicate.getArray().getContent();
        content = content.replaceAll(" ", "\",\"");

        stringBuilder
            .append(simpleSetPredicate.getField())
            .append(" in ( \"")
            .append(content)
            .append("\" )");
      }
    } else if (XLSKeywords.DATATYPE_BOOLEAN.equalsIgnoreCase(dataType)) {
      if (scoreAttribute.getSimplePredicate() != null) {
        SimplePredicate predicate = scoreAttribute.getSimplePredicate();
        String operator = predicate.getOperator();
        if (PMMLOperators.EQUAL.equalsIgnoreCase(operator)) {
          stringBuilder.append(predicate.getField());
          stringBuilder.append(" == ");
          stringBuilder.append(predicate.getValue().toLowerCase());
        } else if (PMMLOperators.NOT_EQUAL.equalsIgnoreCase(operator)) {
          stringBuilder.append(predicate.getField());
          stringBuilder.append(" != ");
          stringBuilder.append(predicate.getValue().toLowerCase());
        }
      }
    } else if (XLSKeywords.DATATYPE_NUMBER.equalsIgnoreCase(dataType)) {
      if (scoreAttribute.getSimplePredicate() != null) {
        SimplePredicate predicate = scoreAttribute.getSimplePredicate();
        String operator = predicate.getOperator();
        stringBuilder.append(predicate.getField());
        if (PMMLOperators.LESS_THAN.equalsIgnoreCase(operator)) {
          stringBuilder.append(" < ");
        } else if (PMMLOperators.GREATER_THAN.equalsIgnoreCase(operator)) {
          stringBuilder.append(" > ");
        } else if (PMMLOperators.NOT_EQUAL.equalsIgnoreCase(operator)) {
          stringBuilder.append(" <> ");
        } else if (PMMLOperators.EQUAL.equalsIgnoreCase(operator)) {
          stringBuilder.append(" == ");
        } else if (PMMLOperators.GREATER_OR_EQUAL.equalsIgnoreCase(operator)) {
          stringBuilder.append(" >= ");
        } else if (PMMLOperators.LESS_OR_EQUAL.equalsIgnoreCase(operator)) {
          stringBuilder.append(" <= ");
        }
        stringBuilder.append(predicate.getValue());
      } else if (scoreAttribute.getCompoundPredicate() != null) {
        CompoundPredicate predicate = scoreAttribute.getCompoundPredicate();
        String field = null;
        for (Object obj :
            predicate.getSimplePredicatesAndCompoundPredicatesAndSimpleSetPredicates()) {
          if (obj instanceof SimplePredicate) {
            SimplePredicate simplePredicate = (SimplePredicate) obj;
            String operator = simplePredicate.getOperator();
            if (field == null) {
              stringBuilder.append(simplePredicate.getField());
              field = simplePredicate.getField();
            } else {
              stringBuilder.append(" && ");
            }
            if (PMMLOperators.LESS_THAN.equalsIgnoreCase(operator)) {
              stringBuilder.append(" < ");
            } else if (PMMLOperators.GREATER_THAN.equalsIgnoreCase(operator)) {
              stringBuilder.append(" > ");
            } else if (PMMLOperators.NOT_EQUAL.equalsIgnoreCase(operator)) {
              stringBuilder.append(" <> ");
            } else if (PMMLOperators.EQUAL.equalsIgnoreCase(operator)) {
              stringBuilder.append(" == ");
            } else if (PMMLOperators.GREATER_OR_EQUAL.equalsIgnoreCase(operator)) {
              stringBuilder.append(" >= ");
            } else if (PMMLOperators.LESS_OR_EQUAL.equalsIgnoreCase(operator)) {
              stringBuilder.append(" <= ");
            }
            stringBuilder.append(simplePredicate.getValue());
          }
        }
      }
    }
    stringBuilder.append(")");
  }