private void setupSimpleSetPredicate(int index, String fieldName, String operator, Array values) { if (index < 0 || index >= simpleSetPredicate.length) { throw new IndexOutOfBoundsException("Invalid index for setting up SimpleSetPredicate"); } simpleSetPredicate[index] = new SimpleSetPredicate(); simpleSetPredicate[index].setField(fieldName); simpleSetPredicate[index].setBooleanOperator(operator); simpleSetPredicate[index].setArray(values); }
public SimpleSetSegmentPredicate(SimpleSetPredicate predicate) { this.setType = predicate.getArray().getType(); this.operator = predicate.getBooleanOperator(); this.baseFieldName = predicate.getField(); this.setValuesString = predicate.getArray().getContent(); this.valueCount = predicate.getArray().getN(); this.valuesList = getValueObjects(); if (this.valueCount != null && this.valueCount.intValue() != this.valuesList.size()) { throw new IllegalStateException("PMML-SimpleSetPredicate: Number of values found (" +valuesList.size()+") does not equal number of values declared (" +this.valueCount+")"); } if (this.operator == null || (!this.operator.equals("isIn") && !this.operator.equals("isNotIn"))) { throw new IllegalStateException("PMML-SimpleSetPredicate: booleanOperator was not one of the allowed values (\"isIn\" or \"isNotIn\")"); } }
@Before public void setUp() throws Exception { predicate = new SimpleSetPredicate(); predicate.setField("TF1"); predicate.setBooleanOperator("isIn"); }
@Test public void testNegativeMembership() { Array array = new Array(); array.setType("real"); array.setContent("3.14 29.5 17 71"); array.setN(new BigInteger("4")); predicate.setArray(array); predicate.setBooleanOperator("isNotIn"); String expected = "( mTF1 == false ) && ( vTF1 not in ( 3.14, 29.5, 17.0, 71.0 ) )"; doPredicateRetrieve(expected); }
/** * Create an instance of {@link SimpleSetPredicate } * */ public SimpleSetPredicate createSimpleSetPredicate() { return new SimpleSetPredicate(); }
@Test public void testSimpleStringSet() { Array array = new Array(); array.setType("string"); StringBuilder bldr = new StringBuilder(); for (int x = 0; x < 4; x++) { bldr.append("\"").append("testValue ").append(x).append("\" "); } array.setContent(bldr.toString()); array.setN(new BigInteger("4")); predicate.setArray(array); String expected = "( mTF1 == false ) && ( vTF1 in ( \"testValue 0\" , \"testValue 1\" , \"testValue 2\" , \"testValue 3\" ) )"; doPredicateRetrieve(expected); }
public static String extractFieldNameFromCharacteristic(Characteristic c) { String field = ""; Attribute scoreAttribute = c.getAttributes().get(0); if (scoreAttribute.getSimplePredicate() != null) { field = scoreAttribute.getSimplePredicate().getField(); } else if (scoreAttribute.getSimpleSetPredicate() != null) { field = scoreAttribute.getSimpleSetPredicate().getField(); } else if (scoreAttribute.getCompoundPredicate() != null) { Object predicate = scoreAttribute.getCompoundPredicate().getSimplePredicatesAndCompoundPredicatesAndSimpleSetPredicates().get(0); if (predicate instanceof SimplePredicate){ field = ((SimplePredicate)predicate).getField(); } else if (predicate instanceof SimpleSetPredicate){ field = ((SimpleSetPredicate)predicate).getField(); } } return field; }
@Test(expected=IllegalStateException.class) public void testInvalidItemCount() { Array array = new Array(); array.setType("int"); array.setContent("1 33 45"); array.setN(new BigInteger("2")); predicate.setArray(array); // Note: Since we expect an exception it doesn't matter // what is passed as the expected value doPredicateRetrieve(null); }
SimpleSetPredicate simpleSetPredicate = new SimpleSetPredicate(); if ("!=".equalsIgnoreCase(operator)) { simpleSetPredicate.setBooleanOperator(PMMLOperators.IS_NOT_IN); } else { simpleSetPredicate.setBooleanOperator(PMMLOperators.IS_IN); simpleSetPredicate.setField(field); predicateAsString = predicateAsString.trim(); if (predicateAsString.endsWith(",")) { array.setType("string"); array.setN(BigInteger.valueOf(predicateAsString.split(",").length)); simpleSetPredicate.setArray(array); pmmlAttribute.setSimpleSetPredicate(simpleSetPredicate); } else {
@Test public void testSimpleRealSet() { Array array = new Array(); array.setType("real"); array.setContent("3.14 29.5 17 71"); array.setN(new BigInteger("4")); predicate.setArray(array); String expected = "( mTF1 == false ) && ( vTF1 in ( 3.14, 29.5, 17.0, 71.0 ) )"; doPredicateRetrieve(expected); }
@Test public void testSimpleIntSet() { Array array = new Array(); array.setType("int"); array.setContent("1 33 45"); array.setN(new BigInteger("3")); predicate.setArray(array); String expected = "( mTF1 == false ) && ( vTF1 in ( 1, 33, 45 ) )"; doPredicateRetrieve(expected); }