Search in sources :

Example 1 with PMMLOperator

use of org.knime.base.node.mine.decisiontree2.PMMLOperator in project knime-core by knime.

the class PMMLExpressionFactory method compare.

/**
 * {@inheritDoc}
 */
@Override
public PMMLPredicate compare(final Expression left, final Expression right, final DataValueComparator cmp, final int... possibleValues) {
    final PMMLOperator op;
    if (Arrays.equals(possibleValues, LT)) {
        op = PMMLOperator.LESS_THAN;
    } else if (Arrays.equals(possibleValues, LE)) {
        op = PMMLOperator.LESS_OR_EQUAL;
    } else if (Arrays.equals(possibleValues, GT)) {
        op = PMMLOperator.GREATER_THAN;
    } else if (Arrays.equals(possibleValues, GE)) {
        op = PMMLOperator.GREATER_OR_EQUAL;
    } else if (Arrays.equals(possibleValues, EQ)) {
        op = PMMLOperator.EQUAL;
    } else {
        throw new IllegalStateException("" + Arrays.toString(possibleValues));
    }
    handleSameType(left, right);
    if (left.getTreeType() == ASTType.ColRef) {
        m_usedColumns.add(expressionToString(left));
    }
    if (right.getTreeType() == ASTType.ColRef) {
        m_usedColumns.add(expressionToString(right));
        final PMMLOperator opposite;
        switch(op) {
            case EQUAL:
                opposite = op;
                break;
            case GREATER_OR_EQUAL:
                opposite = PMMLOperator.LESS_OR_EQUAL;
                break;
            case GREATER_THAN:
                opposite = PMMLOperator.LESS_THAN;
                break;
            case LESS_OR_EQUAL:
                opposite = PMMLOperator.GREATER_OR_EQUAL;
                break;
            case LESS_THAN:
                opposite = PMMLOperator.GREATER_THAN;
                break;
            default:
                throw new UnsupportedOperationException("Not supported: " + op);
        }
        return new PMMLSimplePredicate(expressionToString(right), opposite, expressionToString(left));
    }
    return new PMMLSimplePredicate(expressionToString(left), op, expressionToString(right));
}
Also used : PMMLOperator(org.knime.base.node.mine.decisiontree2.PMMLOperator) PMMLSimplePredicate(org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate)

Example 2 with PMMLOperator

use of org.knime.base.node.mine.decisiontree2.PMMLOperator in project knime-core by knime.

the class PMMLRuleTranslator method setOperator.

/**
 * Sets the operator of {@code pred} based on the properties of {@code simple.}
 *
 * @param pred An xml {@link SimplePredicate}.
 * @param simple A {@link PMMLSimplePredicate}.
 */
private void setOperator(final SimplePredicate pred, final PMMLSimplePredicate simple) {
    PMMLOperator x = simple.getOperator();
    Enum e = PMMLPredicateTranslator.getOperator(x);
    if (e == null) {
        throw new UnsupportedOperationException("Unknown operator: " + x);
    }
    pred.setOperator(e);
}
Also used : Enum(org.dmg.pmml.SimplePredicateDocument.SimplePredicate.Operator.Enum) PMMLOperator(org.knime.base.node.mine.decisiontree2.PMMLOperator)

Example 3 with PMMLOperator

use of org.knime.base.node.mine.decisiontree2.PMMLOperator in project knime-core by knime.

the class TreeModelPMMLTranslator method setValuesFromPMMLSimplePredicate.

private static void setValuesFromPMMLSimplePredicate(final SimplePredicate to, final PMMLSimplePredicate from) {
    to.setField(from.getSplitAttribute());
    Operator.Enum operator;
    final PMMLOperator op = from.getOperator();
    switch(op) {
        case EQUAL:
            operator = Operator.EQUAL;
            to.setValue(from.getThreshold());
            break;
        case GREATER_OR_EQUAL:
            operator = Operator.GREATER_OR_EQUAL;
            to.setValue(from.getThreshold());
            break;
        case GREATER_THAN:
            operator = Operator.GREATER_THAN;
            to.setValue(from.getThreshold());
            break;
        case IS_MISSING:
            operator = Operator.IS_MISSING;
            break;
        case IS_NOT_MISSING:
            operator = Operator.IS_NOT_MISSING;
            break;
        case LESS_OR_EQUAL:
            operator = Operator.LESS_OR_EQUAL;
            to.setValue(from.getThreshold());
            break;
        case LESS_THAN:
            operator = Operator.LESS_THAN;
            to.setValue(from.getThreshold());
            break;
        case NOT_EQUAL:
            operator = Operator.NOT_EQUAL;
            to.setValue(from.getThreshold());
            break;
        default:
            throw new IllegalStateException("Unknown pmml operator \"" + op + "\".");
    }
    to.setOperator(operator);
}
Also used : PMMLOperator(org.knime.base.node.mine.decisiontree2.PMMLOperator) Operator(org.dmg.pmml.SimplePredicateDocument.SimplePredicate.Operator) PMMLBooleanOperator(org.knime.base.node.mine.decisiontree2.PMMLBooleanOperator) PMMLSetOperator(org.knime.base.node.mine.decisiontree2.PMMLSetOperator) Enum(org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate.BooleanOperator.Enum) PMMLOperator(org.knime.base.node.mine.decisiontree2.PMMLOperator)

Example 4 with PMMLOperator

use of org.knime.base.node.mine.decisiontree2.PMMLOperator in project knime-core by knime.

the class TreeNodeNumericCondition method toPMMLPredicate.

/**
 * {@inheritDoc}
 */
@Override
public PMMLPredicate toPMMLPredicate() {
    PMMLCompoundPredicate compound = new PMMLCompoundPredicate(PMMLBooleanOperator.OR);
    switch(m_numericOperator) {
        case LargerThanOrMissing:
            compound.addPredicate(new PMMLSimplePredicate(getAttributeName(), PMMLOperator.GREATER_THAN, Double.toString(m_splitValue)));
            compound.addPredicate(new PMMLSimplePredicate(getAttributeName(), PMMLOperator.IS_MISSING, Double.toString(m_splitValue)));
            return compound;
        case LessThanOrEqualOrMissing:
            compound.addPredicate(new PMMLSimplePredicate(getAttributeName(), PMMLOperator.LESS_OR_EQUAL, Double.toString(m_splitValue)));
            compound.addPredicate(new PMMLSimplePredicate(getAttributeName(), PMMLOperator.IS_MISSING, Double.toString(m_splitValue)));
            return compound;
    }
    final PMMLOperator pmmlOperator = m_numericOperator.m_pmmlOperator;
    if (pmmlOperator == null) {
        throw new IllegalStateException("There is no equivalent PMMLOperator for this NumericOperator.");
    }
    final PMMLSimplePredicate simplePredicate = new PMMLSimplePredicate(getAttributeName(), pmmlOperator, Double.toString(m_splitValue));
    if (!acceptsMissings()) {
        // return simple predicate that rejects missing values
        return simplePredicate;
    }
    // create compound to allow for missing values
    compound.addPredicate(simplePredicate);
    final PMMLSimplePredicate missing = new PMMLSimplePredicate();
    missing.setSplitAttribute(getAttributeName());
    missing.setOperator(PMMLOperator.IS_MISSING);
    compound.addPredicate(missing);
    return compound;
}
Also used : PMMLSimplePredicate(org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate) PMMLOperator(org.knime.base.node.mine.decisiontree2.PMMLOperator) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate)

Example 5 with PMMLOperator

use of org.knime.base.node.mine.decisiontree2.PMMLOperator in project knime-core by knime.

the class ConditionExporter method setValuesFromPMMLSimplePredicate.

private void setValuesFromPMMLSimplePredicate(final SimplePredicate to, final PMMLSimplePredicate from) {
    to.setField(m_derivedFieldMapper.getDerivedFieldName(from.getSplitAttribute()));
    Operator.Enum operator;
    final PMMLOperator op = from.getOperator();
    switch(op) {
        case EQUAL:
            operator = Operator.EQUAL;
            to.setValue(from.getThreshold());
            break;
        case GREATER_OR_EQUAL:
            operator = Operator.GREATER_OR_EQUAL;
            to.setValue(from.getThreshold());
            break;
        case GREATER_THAN:
            operator = Operator.GREATER_THAN;
            to.setValue(from.getThreshold());
            break;
        case IS_MISSING:
            operator = Operator.IS_MISSING;
            break;
        case IS_NOT_MISSING:
            operator = Operator.IS_NOT_MISSING;
            break;
        case LESS_OR_EQUAL:
            operator = Operator.LESS_OR_EQUAL;
            to.setValue(from.getThreshold());
            break;
        case LESS_THAN:
            operator = Operator.LESS_THAN;
            to.setValue(from.getThreshold());
            break;
        case NOT_EQUAL:
            operator = Operator.NOT_EQUAL;
            to.setValue(from.getThreshold());
            break;
        default:
            throw new IllegalStateException("Unknown pmml operator \"" + op + "\".");
    }
    to.setOperator(operator);
}
Also used : PMMLOperator(org.knime.base.node.mine.decisiontree2.PMMLOperator) Operator(org.dmg.pmml.SimplePredicateDocument.SimplePredicate.Operator) PMMLBooleanOperator(org.knime.base.node.mine.decisiontree2.PMMLBooleanOperator) PMMLSetOperator(org.knime.base.node.mine.decisiontree2.PMMLSetOperator) Enum(org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate.BooleanOperator.Enum) PMMLOperator(org.knime.base.node.mine.decisiontree2.PMMLOperator)

Aggregations

PMMLOperator (org.knime.base.node.mine.decisiontree2.PMMLOperator)6 Operator (org.dmg.pmml.SimplePredicateDocument.SimplePredicate.Operator)2 Enum (org.dmg.pmml.SimplePredicateDocument.SimplePredicate.Operator.Enum)2 Enum (org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate.BooleanOperator.Enum)2 PMMLBooleanOperator (org.knime.base.node.mine.decisiontree2.PMMLBooleanOperator)2 PMMLSetOperator (org.knime.base.node.mine.decisiontree2.PMMLSetOperator)2 PMMLSimplePredicate (org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate)2 PMMLCompoundPredicate (org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate)1