use of org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate 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);
}
use of org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate in project knime-core by knime.
the class TreeNodeNominalBinaryCondition method toPMMLPredicate.
/**
* {@inheritDoc}
*/
@Override
public PMMLPredicate toPMMLPredicate() {
final PMMLSimpleSetPredicate setPredicate = new PMMLSimpleSetPredicate(getAttributeName(), m_setLogic.getPmmlSetOperator());
setPredicate.setValues(Arrays.asList(getValues()));
setPredicate.setArrayType(PMMLArrayType.STRING);
if (!acceptsMissings()) {
// if condition rejects missing values return the set predicate
return setPredicate;
}
// otherwise create compound condition that allows missing values
final PMMLCompoundPredicate compPredicate = new PMMLCompoundPredicate(PMMLBooleanOperator.OR);
final PMMLSimplePredicate missing = new PMMLSimplePredicate();
missing.setSplitAttribute(getAttributeName());
missing.setOperator(PMMLOperator.IS_MISSING);
compPredicate.addPredicate(setPredicate);
compPredicate.addPredicate(missing);
return compPredicate;
}
use of org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate in project knime-core by knime.
the class PMMLExpressionFactory method in.
/**
* {@inheritDoc}
*/
@Override
public PMMLPredicate in(final Expression left, final Expression right) {
PMMLSimpleSetPredicate setIn = new PMMLSimpleSetPredicate(expressionToString(left), PMMLSetOperator.IS_IN);
if (left.getTreeType() == ASTType.ColRef) {
m_usedColumns.add(expressionToString(left));
} else {
throw new UnsupportedOperationException("PMML 4.1 supports only columns before IN.");
}
if (!right.isConstant()) {
throw new UnsupportedOperationException("PMML 4.1 supports only constants in arguments.");
}
List<Expression> children = right.getChildren();
List<String> values = new ArrayList<String>(children.size());
List<DataType> types = new ArrayList<DataType>(children.size());
for (Expression child : children) {
values.add(expressionToString(child));
types.add(child.getOutputType());
}
DataType outputType = RuleEngineNodeModel.computeOutputType(types, false);
if (outputType.isCompatible(IntValue.class)) {
setIn.setArrayType(PMMLArrayType.INT);
} else if (outputType.isCompatible(DoubleValue.class)) {
setIn.setArrayType(PMMLArrayType.REAL);
} else {
setIn.setArrayType(PMMLArrayType.STRING);
}
setIn.setValues(values);
return setIn;
}
use of org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate in project knime-core by knime.
the class PMMLRuleTranslator method setPredicate.
/**
* As the predicates can be of different subclasses of {@link PMMLPredicate}, creating them adding their properties
* to the {@code simpleRule} is done with this method.
*
* @param simpleRule An xml {@link SimpleRule} (recently created).
* @param predicate A {@link PMMLPredicate} with preferably from the Rule versions of
* {@link PMMLRuleSimplePredicate} and {@link PMMLRuleCompoundPredicate}.
* @since 2.12
*/
public void setPredicate(final SimpleRule simpleRule, final PMMLPredicate predicate) {
if (predicate instanceof PMMLFalsePredicate) {
simpleRule.addNewFalse();
} else if (predicate instanceof PMMLTruePredicate) {
simpleRule.addNewTrue();
} else if (predicate instanceof PMMLSimplePredicate) {
PMMLSimplePredicate simple = (PMMLSimplePredicate) predicate;
SimplePredicate pred = simpleRule.addNewSimplePredicate();
pred.setField(simple.getSplitAttribute());
setOperator(pred, simple);
if (simple.getThreshold() != null) {
pred.setValue(simple.getThreshold());
}
} else if (predicate instanceof PMMLCompoundPredicate) {
PMMLCompoundPredicate comp = (PMMLCompoundPredicate) predicate;
CompoundPredicate p = simpleRule.addNewCompoundPredicate();
setCompound(p, comp);
} else if (predicate instanceof PMMLSimpleSetPredicate) {
PMMLSimpleSetPredicate set = (PMMLSimpleSetPredicate) predicate;
SimpleSetPredicate s = simpleRule.addNewSimpleSetPredicate();
setSetPredicate(s, set);
}
}
use of org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate in project knime-core by knime.
the class PMMLRuleTranslator method setPredicate.
/**
* For an xml {@link CompoundPredicate} ({@code cp}) sets the parameters based on {@code pred}'s properties.
*
* @param cp An xml {@link CompoundPredicate}.
* @param pred The {@link PMMLPredicate} with the rule version subclasses.
*/
private void setPredicate(final CompoundPredicate cp, final PMMLPredicate pred) {
if (pred instanceof PMMLFalsePredicate) {
cp.addNewFalse();
} else if (pred instanceof PMMLTruePredicate) {
cp.addNewTrue();
} else if (pred instanceof PMMLSimplePredicate) {
PMMLSimplePredicate simple = (PMMLSimplePredicate) pred;
SimplePredicate s = cp.addNewSimplePredicate();
s.setField(simple.getSplitAttribute());
setOperator(s, simple);
s.setValue(simple.getThreshold());
} else if (pred instanceof PMMLCompoundPredicate) {
PMMLCompoundPredicate compound = (PMMLCompoundPredicate) pred;
CompoundPredicate c = cp.addNewCompoundPredicate();
setCompound(c, compound);
} else if (pred instanceof PMMLSimpleSetPredicate) {
PMMLSimpleSetPredicate set = (PMMLSimpleSetPredicate) pred;
SimpleSetPredicate ss = cp.addNewSimpleSetPredicate();
setSetPredicate(ss, set);
}
}
Aggregations