Search in sources :

Example 6 with SimpleSetPredicate

use of org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate in project knime-core by knime.

the class LiteralConditionParser method parseOrCompound.

private TreeNodeColumnCondition parseOrCompound(final CompoundPredicate compound) {
    CheckUtils.checkArgument(compound.getCompoundPredicateList().isEmpty(), "Currently only simple or-compounds are supported that consist of exactly one" + " SimpleSetPredicate or SimplePredicate followed by a SimplePredicate with operator isMissing.");
    List<SimplePredicate> simplePredicates = compound.getSimplePredicateList();
    CheckUtils.checkArgument(simplePredicates.size() <= OR_COMPOUND_SIMPLEPREDICATE_LIMIT, "Currently at most two SimplePredicates are supported in an or-compound.");
    List<SimpleSetPredicate> simpleSetPredicates = compound.getSimpleSetPredicateList();
    CheckUtils.checkArgument(simpleSetPredicates.size() <= OR_COMPOUND_SIMPLESETPREDICATE_LIMIT, "Currently at most one SimpleSetPredicate is supported in an or-compound.");
    boolean acceptsMissings = false;
    for (SimplePredicate simplePred : simplePredicates) {
        if (simplePred.getOperator() == SimplePredicate.Operator.IS_MISSING) {
            acceptsMissings = true;
            // we may not try to parse a simple predicate with operator is_missing
            simplePredicates.remove(simplePred);
            break;
        }
    }
    if (!simplePredicates.isEmpty()) {
        return handleSimplePredicate(simplePredicates.get(0), acceptsMissings);
    } else if (!simpleSetPredicates.isEmpty()) {
        return handleSimpleSetPredicate(simpleSetPredicates.get(0), acceptsMissings);
    }
    throw new IllegalArgumentException("There was only a is_missing predicate contained in the or-compound \"" + compound + "\" (or at least no more SimplePredicates or SimpleSetPredicates).");
}
Also used : SimplePredicate(org.dmg.pmml.SimplePredicateDocument.SimplePredicate) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate)

Example 7 with SimpleSetPredicate

use of org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate 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 8 with SimpleSetPredicate

use of org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate 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

SimplePredicate (org.dmg.pmml.SimplePredicateDocument.SimplePredicate)8 SimpleSetPredicate (org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate)8 CompoundPredicate (org.dmg.pmml.CompoundPredicateDocument.CompoundPredicate)6 XmlCursor (org.apache.xmlbeans.XmlCursor)2 PMMLCompoundPredicate (org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate)2 PMMLFalsePredicate (org.knime.base.node.mine.decisiontree2.PMMLFalsePredicate)2 PMMLSimplePredicate (org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate)2 PMMLSimpleSetPredicate (org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate)2 PMMLTruePredicate (org.knime.base.node.mine.decisiontree2.PMMLTruePredicate)2 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Entry (java.util.Map.Entry)1 XmlObject (org.apache.xmlbeans.XmlObject)1 ArrayType (org.dmg.pmml.ArrayType)1 False (org.dmg.pmml.FalseDocument.False)1 ScoreDistribution (org.dmg.pmml.ScoreDistributionDocument.ScoreDistribution)1 TrueDocument (org.dmg.pmml.TrueDocument)1 True (org.dmg.pmml.TrueDocument.True)1 DecisionTreeNode (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode)1