Search in sources :

Example 6 with PMMLTruePredicate

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

the class ConditionExporter method setValuesFromPMMLCompoundPredicate.

private void setValuesFromPMMLCompoundPredicate(final CompoundPredicate to, final PMMLCompoundPredicate from) {
    final PMMLBooleanOperator boolOp = from.getBooleanOperator();
    switch(boolOp) {
        case AND:
            to.setBooleanOperator(CompoundPredicate.BooleanOperator.AND);
            break;
        case OR:
            to.setBooleanOperator(CompoundPredicate.BooleanOperator.OR);
            break;
        case SURROGATE:
            to.setBooleanOperator(CompoundPredicate.BooleanOperator.SURROGATE);
            break;
        case XOR:
            to.setBooleanOperator(CompoundPredicate.BooleanOperator.XOR);
            break;
        default:
            throw new IllegalStateException("Unknown boolean predicate \"" + boolOp + "\".");
    }
    final List<PMMLPredicate> predicates = from.getPredicates();
    for (final PMMLPredicate predicate : predicates) {
        if (predicate instanceof PMMLSimplePredicate) {
            setValuesFromPMMLSimplePredicate(to.addNewSimplePredicate(), (PMMLSimplePredicate) predicate);
        } else if (predicate instanceof PMMLSimpleSetPredicate) {
            setValuesFromPMMLSimpleSetPredicate(to.addNewSimpleSetPredicate(), (PMMLSimpleSetPredicate) predicate);
        } else if (predicate instanceof PMMLTruePredicate) {
            to.addNewTrue();
        } else if (predicate instanceof PMMLFalsePredicate) {
            to.addNewFalse();
        } else if (predicate instanceof PMMLCompoundPredicate) {
            final CompoundPredicate compound = to.addNewCompoundPredicate();
            final PMMLCompoundPredicate knimeCompound = (PMMLCompoundPredicate) predicate;
            setValuesFromPMMLCompoundPredicate(compound, knimeCompound);
        } else {
            throw new IllegalStateException("Unknown predicate type \"" + predicate + "\".");
        }
    }
}
Also used : PMMLTruePredicate(org.knime.base.node.mine.decisiontree2.PMMLTruePredicate) PMMLSimpleSetPredicate(org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate) PMMLSimplePredicate(org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate) CompoundPredicate(org.dmg.pmml.CompoundPredicateDocument.CompoundPredicate) PMMLPredicate(org.knime.base.node.mine.decisiontree2.PMMLPredicate) PMMLFalsePredicate(org.knime.base.node.mine.decisiontree2.PMMLFalsePredicate) PMMLBooleanOperator(org.knime.base.node.mine.decisiontree2.PMMLBooleanOperator) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate)

Example 7 with PMMLTruePredicate

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

the class TreeModelPMMLTranslator method setValuesFromPMMLCompoundPredicate.

private static void setValuesFromPMMLCompoundPredicate(final CompoundPredicate to, final PMMLCompoundPredicate from) {
    final PMMLBooleanOperator boolOp = from.getBooleanOperator();
    switch(boolOp) {
        case AND:
            to.setBooleanOperator(CompoundPredicate.BooleanOperator.AND);
            break;
        case OR:
            to.setBooleanOperator(CompoundPredicate.BooleanOperator.OR);
            break;
        case SURROGATE:
            to.setBooleanOperator(CompoundPredicate.BooleanOperator.SURROGATE);
            break;
        case XOR:
            to.setBooleanOperator(CompoundPredicate.BooleanOperator.XOR);
            break;
        default:
            throw new IllegalStateException("Unknown boolean predicate \"" + boolOp + "\".");
    }
    final List<PMMLPredicate> predicates = from.getPredicates();
    for (final PMMLPredicate predicate : predicates) {
        if (predicate instanceof PMMLSimplePredicate) {
            setValuesFromPMMLSimplePredicate(to.addNewSimplePredicate(), (PMMLSimplePredicate) predicate);
        } else if (predicate instanceof PMMLSimpleSetPredicate) {
            setValuesFromPMMLSimpleSetPredicate(to.addNewSimpleSetPredicate(), (PMMLSimpleSetPredicate) predicate);
        } else if (predicate instanceof PMMLTruePredicate) {
            to.addNewTrue();
        } else if (predicate instanceof PMMLFalsePredicate) {
            to.addNewFalse();
        } else if (predicate instanceof PMMLCompoundPredicate) {
            final CompoundPredicate compound = to.addNewCompoundPredicate();
            final PMMLCompoundPredicate knimeCompound = (PMMLCompoundPredicate) predicate;
            setValuesFromPMMLCompoundPredicate(compound, knimeCompound);
        } else {
            throw new IllegalStateException("Unknown predicate type \"" + predicate + "\".");
        }
    }
}
Also used : PMMLTruePredicate(org.knime.base.node.mine.decisiontree2.PMMLTruePredicate) PMMLSimpleSetPredicate(org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate) PMMLSimplePredicate(org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate) CompoundPredicate(org.dmg.pmml.CompoundPredicateDocument.CompoundPredicate) PMMLPredicate(org.knime.base.node.mine.decisiontree2.PMMLPredicate) PMMLFalsePredicate(org.knime.base.node.mine.decisiontree2.PMMLFalsePredicate) PMMLBooleanOperator(org.knime.base.node.mine.decisiontree2.PMMLBooleanOperator) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate)

Example 8 with PMMLTruePredicate

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

the class AbstractTreeNodeSurrogateCondition method toPMMLPredicate.

/**
 * {@inheritDoc}
 */
@Override
public PMMLCompoundPredicate toPMMLPredicate() {
    PMMLCompoundPredicate compound = new PMMLCompoundPredicate("surrogate");
    PMMLCompoundPredicate cc = compound;
    cc.addPredicate(getFirstCondition().toPMMLPredicate());
    for (int i = 0; i < getNumSurrogates(); i++) {
        TreeNodeCondition condition = getColumnCondition(i + 1);
        PMMLCompoundPredicate nc = new PMMLCompoundPredicate("surrogate");
        nc.addPredicate(condition.toPMMLPredicate());
        cc.addPredicate(nc);
        cc = nc;
    }
    if (m_defaultResponse) {
        cc.addPredicate(new PMMLTruePredicate());
    } else {
        cc.addPredicate(new PMMLFalsePredicate());
    }
    return compound;
}
Also used : PMMLTruePredicate(org.knime.base.node.mine.decisiontree2.PMMLTruePredicate) PMMLFalsePredicate(org.knime.base.node.mine.decisiontree2.PMMLFalsePredicate) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate)

Example 9 with PMMLTruePredicate

use of org.knime.base.node.mine.decisiontree2.PMMLTruePredicate 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);
    }
}
Also used : PMMLTruePredicate(org.knime.base.node.mine.decisiontree2.PMMLTruePredicate) PMMLSimpleSetPredicate(org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate) PMMLSimplePredicate(org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate) CompoundPredicate(org.dmg.pmml.CompoundPredicateDocument.CompoundPredicate) PMMLFalsePredicate(org.knime.base.node.mine.decisiontree2.PMMLFalsePredicate) PMMLSimplePredicate(org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate) SimplePredicate(org.dmg.pmml.SimplePredicateDocument.SimplePredicate) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate) PMMLSimpleSetPredicate(org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate)

Example 10 with PMMLTruePredicate

use of org.knime.base.node.mine.decisiontree2.PMMLTruePredicate 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);
    }
}
Also used : PMMLTruePredicate(org.knime.base.node.mine.decisiontree2.PMMLTruePredicate) PMMLSimpleSetPredicate(org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate) PMMLSimplePredicate(org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate) CompoundPredicate(org.dmg.pmml.CompoundPredicateDocument.CompoundPredicate) PMMLFalsePredicate(org.knime.base.node.mine.decisiontree2.PMMLFalsePredicate) PMMLSimplePredicate(org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate) SimplePredicate(org.dmg.pmml.SimplePredicateDocument.SimplePredicate) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate) PMMLSimpleSetPredicate(org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate)

Aggregations

PMMLFalsePredicate (org.knime.base.node.mine.decisiontree2.PMMLFalsePredicate)11 PMMLTruePredicate (org.knime.base.node.mine.decisiontree2.PMMLTruePredicate)11 PMMLCompoundPredicate (org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate)9 PMMLSimplePredicate (org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate)9 PMMLSimpleSetPredicate (org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate)9 PMMLPredicate (org.knime.base.node.mine.decisiontree2.PMMLPredicate)8 CompoundPredicate (org.dmg.pmml.CompoundPredicateDocument.CompoundPredicate)6 SimplePredicate (org.dmg.pmml.SimplePredicateDocument.SimplePredicate)4 SimpleSetPredicate (org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate)4 PMMLBooleanOperator (org.knime.base.node.mine.decisiontree2.PMMLBooleanOperator)3 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 MININGFUNCTION (org.dmg.pmml.MININGFUNCTION)2 PMMLDocument (org.dmg.pmml.PMMLDocument)2 PMML (org.dmg.pmml.PMMLDocument.PMML)2 Criterion (org.dmg.pmml.RuleSelectionMethodDocument.RuleSelectionMethod.Criterion)2 RuleSet (org.dmg.pmml.RuleSetDocument.RuleSet)2 RuleSetModel (org.dmg.pmml.RuleSetModelDocument.RuleSetModel)2