use of org.dmg.pmml.ArrayType in project knime-core by knime.
the class PMMLConditionTranslator method parseSimpleSetPredicate.
/**
* Create a KNIME simple set predicate from a PMML simple set predicate.
*
* @param xmlSimpleSetPredicate the PMML simple set predicate element
* @return the KNIME Simple Set Predicate
*/
protected PMMLPredicate parseSimpleSetPredicate(final SimpleSetPredicate xmlSimpleSetPredicate) {
String field = m_nameMapper.getColumnName(xmlSimpleSetPredicate.getField());
String operator = xmlSimpleSetPredicate.getBooleanOperator().toString();
PMMLSimpleSetPredicate simpleSetPredicate = new PMMLSimpleSetPredicate(field, operator);
ArrayType pmmlArray = xmlSimpleSetPredicate.getArray();
PMMLArrayType arrayType = PMMLArrayType.STRING;
if (Type.REAL == pmmlArray.getType()) {
arrayType = PMMLArrayType.REAL;
} else if (Type.INT == pmmlArray.getType()) {
arrayType = PMMLArrayType.INT;
}
simpleSetPredicate.setArrayType(arrayType);
String content = pmmlArray.newCursor().getTextValue();
String[] stringValues;
content = content.trim();
if (content.contains(DOUBLE_QUOT)) {
content = content.replace(BACKSLASH + DOUBLE_QUOT, TAB);
// ==> <Array n="3" type="string">"Cheval Blanc" "TABTAB"
// "Latour"</Array>
stringValues = content.split(DOUBLE_QUOT + SPACE);
for (int i = 0; i < stringValues.length; i++) {
stringValues[i] = stringValues[i].replace(DOUBLE_QUOT, "");
stringValues[i] = stringValues[i].replace(TAB, DOUBLE_QUOT);
if (PMMLArrayType.STRING != arrayType) {
// do not trim string values
stringValues[i] = stringValues[i].trim();
}
}
} else {
stringValues = content.split("\\s+");
}
List<String> valueList = new ArrayList<String>();
for (String stringValue : stringValues) {
valueList.add(stringValue);
}
simpleSetPredicate.setValues(valueList);
return simpleSetPredicate;
}
use of org.dmg.pmml.ArrayType in project knime-core by knime.
the class ConditionExporter method setValuesFromPMMLSimpleSetPredicate.
private void setValuesFromPMMLSimpleSetPredicate(final SimpleSetPredicate to, final PMMLSimpleSetPredicate from) {
to.setField(m_derivedFieldMapper.getDerivedFieldName(from.getSplitAttribute()));
final Enum operator;
final PMMLSetOperator setOp = from.getSetOperator();
switch(setOp) {
case IS_IN:
operator = SimpleSetPredicate.BooleanOperator.IS_IN;
break;
case IS_NOT_IN:
operator = SimpleSetPredicate.BooleanOperator.IS_NOT_IN;
break;
default:
throw new IllegalStateException("Unknown set operator \"" + setOp + "\".");
}
to.setBooleanOperator(operator);
final Set<String> values = from.getValues();
ArrayType array = to.addNewArray();
array.setN(BigInteger.valueOf(values.size()));
org.w3c.dom.Node arrayNode = array.getDomNode();
arrayNode.appendChild(arrayNode.getOwnerDocument().createTextNode(setToWhitspaceSeparatedString(values)));
final org.dmg.pmml.ArrayType.Type.Enum type;
final PMMLArrayType arrayType = from.getArrayType();
switch(arrayType) {
case INT:
type = ArrayType.Type.INT;
break;
case REAL:
type = ArrayType.Type.REAL;
break;
case STRING:
type = ArrayType.Type.STRING;
break;
default:
throw new IllegalStateException("Unknown array type \"" + arrayType + "\".");
}
array.setType(type);
}
Aggregations