Search in sources :

Example 6 with ArrayType

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;
}
Also used : ArrayType(org.dmg.pmml.ArrayType) ArrayList(java.util.ArrayList)

Example 7 with ArrayType

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);
}
Also used : Enum(org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate.BooleanOperator.Enum) PMMLArrayType(org.knime.base.node.mine.decisiontree2.PMMLArrayType) ArrayType(org.dmg.pmml.ArrayType) PMMLArrayType(org.knime.base.node.mine.decisiontree2.PMMLArrayType) ArrayType(org.dmg.pmml.ArrayType) PMMLArrayType(org.knime.base.node.mine.decisiontree2.PMMLArrayType) PMMLSetOperator(org.knime.base.node.mine.decisiontree2.PMMLSetOperator)

Aggregations

ArrayType (org.dmg.pmml.ArrayType)7 XmlCursor (org.apache.xmlbeans.XmlCursor)3 ClusterDocument (org.dmg.pmml.ClusterDocument)2 ClusteringField (org.dmg.pmml.ClusteringFieldDocument.ClusteringField)2 ClusteringModelDocument (org.dmg.pmml.ClusteringModelDocument)2 ClusteringModel (org.dmg.pmml.ClusteringModelDocument.ClusteringModel)2 ComparisonMeasureDocument (org.dmg.pmml.ComparisonMeasureDocument)2 PMML (org.dmg.pmml.PMMLDocument.PMML)2 Enum (org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate.BooleanOperator.Enum)2 PMMLArrayType (org.knime.base.node.mine.decisiontree2.PMMLArrayType)2 PMMLSetOperator (org.knime.base.node.mine.decisiontree2.PMMLSetOperator)2 DerivedFieldMapper (org.knime.core.node.port.pmml.preproc.DerivedFieldMapper)2 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1 SchemaType (org.apache.xmlbeans.SchemaType)1 ClusteringFieldDocument (org.dmg.pmml.ClusteringFieldDocument)1 ScoreDistribution (org.dmg.pmml.ScoreDistributionDocument.ScoreDistribution)1 SimplePredicate (org.dmg.pmml.SimplePredicateDocument.SimplePredicate)1 SimpleSetPredicate (org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate)1