Search in sources :

Example 1 with SimplePredicate

use of org.dmg.pmml.SimplePredicateDocument.SimplePredicate in project knime-core by knime.

the class FromDecisionTreeNodeModel method addRules.

/**
 * Adds the rules to {@code rs} (recursively on each leaf).
 *
 * @param rs The output {@link RuleSet}.
 * @param parents The parent stack.
 * @param node The actual node.
 */
private void addRules(final RuleSet rs, final List<DecisionTreeNode> parents, final DecisionTreeNode node) {
    if (node.isLeaf()) {
        SimpleRule rule = rs.addNewSimpleRule();
        if (m_rulesToTable.getScorePmmlRecordCount().getBooleanValue()) {
            // This increases the PMML quite significantly
            BigDecimal sum = BigDecimal.ZERO;
            final MathContext mc = new MathContext(7, RoundingMode.HALF_EVEN);
            final boolean computeProbability = m_rulesToTable.getScorePmmlProbability().getBooleanValue();
            if (computeProbability) {
                sum = new BigDecimal(node.getClassCounts().entrySet().stream().mapToDouble(e -> e.getValue().doubleValue()).sum(), mc);
            }
            for (final Entry<DataCell, Double> entry : node.getClassCounts().entrySet()) {
                final ScoreDistribution scoreDistrib = rule.addNewScoreDistribution();
                scoreDistrib.setValue(entry.getKey().toString());
                scoreDistrib.setRecordCount(entry.getValue());
                if (computeProbability) {
                    if (Double.compare(entry.getValue().doubleValue(), 0.0) == 0) {
                        scoreDistrib.setProbability(new BigDecimal(0.0));
                    } else {
                        scoreDistrib.setProbability(new BigDecimal(entry.getValue().doubleValue(), mc).divide(sum, mc));
                    }
                }
            }
        }
        CompoundPredicate and = rule.addNewCompoundPredicate();
        and.setBooleanOperator(BooleanOperator.AND);
        DecisionTreeNode n = node;
        do {
            PMMLPredicate pmmlPredicate = ((DecisionTreeNodeSplitPMML) n.getParent()).getSplitPred()[n.getParent().getIndex(n)];
            if (pmmlPredicate instanceof PMMLSimplePredicate) {
                PMMLSimplePredicate simple = (PMMLSimplePredicate) pmmlPredicate;
                SimplePredicate predicate = and.addNewSimplePredicate();
                copy(predicate, simple);
            } else if (pmmlPredicate instanceof PMMLCompoundPredicate) {
                PMMLCompoundPredicate compound = (PMMLCompoundPredicate) pmmlPredicate;
                CompoundPredicate predicate = and.addNewCompoundPredicate();
                copy(predicate, compound);
            } else if (pmmlPredicate instanceof PMMLSimpleSetPredicate) {
                PMMLSimpleSetPredicate simpleSet = (PMMLSimpleSetPredicate) pmmlPredicate;
                copy(and.addNewSimpleSetPredicate(), simpleSet);
            } else if (pmmlPredicate instanceof PMMLTruePredicate) {
                and.addNewTrue();
            } else if (pmmlPredicate instanceof PMMLFalsePredicate) {
                and.addNewFalse();
            }
            n = n.getParent();
        } while (n.getParent() != null);
        // Simple fix for the case when a single condition was used.
        while (and.getFalseList().size() + and.getCompoundPredicateList().size() + and.getSimplePredicateList().size() + and.getSimpleSetPredicateList().size() + and.getTrueList().size() < 2) {
            and.addNewTrue();
        }
        if (m_rulesToTable.getProvideStatistics().getBooleanValue()) {
            rule.setNbCorrect(node.getOwnClassCount());
            rule.setRecordCount(node.getEntireClassCount());
        }
        rule.setScore(node.getMajorityClass().toString());
    } else {
        parents.add(node);
        for (int i = 0; i < node.getChildCount(); ++i) {
            addRules(rs, parents, node.getChildAt(i));
        }
        parents.remove(node);
    }
}
Also used : PMMLDocument(org.dmg.pmml.PMMLDocument) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) BooleanOperator(org.dmg.pmml.CompoundPredicateDocument.CompoundPredicate.BooleanOperator) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) PMMLMiningSchemaTranslator(org.knime.core.node.port.pmml.PMMLMiningSchemaTranslator) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate) PMMLSimplePredicate(org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate) BigDecimal(java.math.BigDecimal) PMML(org.dmg.pmml.PMMLDocument.PMML) PMMLFalsePredicate(org.knime.base.node.mine.decisiontree2.PMMLFalsePredicate) RuleSetToTable(org.knime.base.node.rules.engine.totable.RuleSetToTable) PMMLSimpleSetPredicate(org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate) RoundingMode(java.math.RoundingMode) PortType(org.knime.core.node.port.PortType) SimplePredicate(org.dmg.pmml.SimplePredicateDocument.SimplePredicate) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) SimpleRule(org.dmg.pmml.SimpleRuleDocument.SimpleRule) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate) CompoundPredicate(org.dmg.pmml.CompoundPredicateDocument.CompoundPredicate) MathContext(java.math.MathContext) NodeModel(org.knime.core.node.NodeModel) DecisionTreeNode(org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode) List(java.util.List) BufferedDataTable(org.knime.core.node.BufferedDataTable) PMMLTruePredicate(org.knime.base.node.mine.decisiontree2.PMMLTruePredicate) PMMLDataDictionaryTranslator(org.knime.core.node.port.pmml.PMMLDataDictionaryTranslator) Entry(java.util.Map.Entry) PortObject(org.knime.core.node.port.PortObject) DecisionTreeNodeSplitPMML(org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeSplitPMML) MININGFUNCTION(org.dmg.pmml.MININGFUNCTION) RuleSetModel(org.dmg.pmml.RuleSetModelDocument.RuleSetModel) PMMLOperator(org.knime.base.node.mine.decisiontree2.PMMLOperator) Criterion(org.dmg.pmml.RuleSelectionMethodDocument.RuleSelectionMethod.Criterion) RuleSet(org.dmg.pmml.RuleSetDocument.RuleSet) PMMLDecisionTreeTranslator(org.knime.base.node.mine.decisiontree2.PMMLDecisionTreeTranslator) Enum(org.dmg.pmml.SimplePredicateDocument.SimplePredicate.Operator.Enum) ArrayList(java.util.ArrayList) ExecutionContext(org.knime.core.node.ExecutionContext) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PMMLPredicate(org.knime.base.node.mine.decisiontree2.PMMLPredicate) DataCell(org.knime.core.data.DataCell) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator) PMMLPredicateTranslator(org.knime.base.node.mine.decisiontree2.PMMLPredicateTranslator) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) IOException(java.io.IOException) File(java.io.File) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) DecisionTree(org.knime.base.node.mine.decisiontree2.model.DecisionTree) ScoreDistribution(org.dmg.pmml.ScoreDistributionDocument.ScoreDistribution) PMMLPredicate(org.knime.base.node.mine.decisiontree2.PMMLPredicate) PMMLFalsePredicate(org.knime.base.node.mine.decisiontree2.PMMLFalsePredicate) BigDecimal(java.math.BigDecimal) MathContext(java.math.MathContext) PMMLSimplePredicate(org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate) SimplePredicate(org.dmg.pmml.SimplePredicateDocument.SimplePredicate) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate) PMMLTruePredicate(org.knime.base.node.mine.decisiontree2.PMMLTruePredicate) ScoreDistribution(org.dmg.pmml.ScoreDistributionDocument.ScoreDistribution) SimpleRule(org.dmg.pmml.SimpleRuleDocument.SimpleRule) PMMLSimpleSetPredicate(org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate) DataCell(org.knime.core.data.DataCell) PMMLSimplePredicate(org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate) CompoundPredicate(org.dmg.pmml.CompoundPredicateDocument.CompoundPredicate) DecisionTreeNode(org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode)

Example 2 with SimplePredicate

use of org.dmg.pmml.SimplePredicateDocument.SimplePredicate in project knime-core by knime.

the class LiteralConditionParser method parseCondition.

/**
 * {@inheritDoc}
 */
@Override
public TreeNodeCondition parseCondition(final Node node) {
    CompoundPredicate compound = node.getCompoundPredicate();
    if (compound != null) {
        return handleCompoundPredicate(compound);
    }
    SimplePredicate simplePred = node.getSimplePredicate();
    if (simplePred != null) {
        return handleSimplePredicate(simplePred, false);
    }
    SimpleSetPredicate simpleSetPred = node.getSimpleSetPredicate();
    if (simpleSetPred != null) {
        return handleSimpleSetPredicate(simpleSetPred, false);
    }
    True truePred = node.getTrue();
    if (truePred != null) {
        return TreeNodeTrueCondition.INSTANCE;
    }
    False falsePred = node.getFalse();
    if (falsePred != null) {
        throw new IllegalArgumentException("There is no False condition in KNIME.");
    }
    throw new IllegalStateException("The pmmlNode contains no valid Predicate.");
}
Also used : True(org.dmg.pmml.TrueDocument.True) CompoundPredicate(org.dmg.pmml.CompoundPredicateDocument.CompoundPredicate) False(org.dmg.pmml.FalseDocument.False) SimplePredicate(org.dmg.pmml.SimplePredicateDocument.SimplePredicate) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate)

Example 3 with SimplePredicate

use of org.dmg.pmml.SimplePredicateDocument.SimplePredicate in project knime-core by knime.

the class PMMLConditionTranslator method parseCompoundPredicate.

/**
 * Create a KNIME compound predicate from a PMML compound predicate. Note that the "order" of the sub-predicates is
 * important (because of surrogate predicate). Therefore, we need to use xmlCursor to retrieve the order of the
 * predicates
 *
 * @param xmlCompoundPredicate the PMML Compound Predicate element
 * @return the KNIME Compound Predicate
 */
protected PMMLCompoundPredicate parseCompoundPredicate(final CompoundPredicate xmlCompoundPredicate) {
    List<PMMLPredicate> tempPredicateList = new ArrayList<PMMLPredicate>();
    if (xmlCompoundPredicate.sizeOfSimplePredicateArray() != 0) {
        for (SimplePredicate xmlSubSimplePredicate : xmlCompoundPredicate.getSimplePredicateList()) {
            tempPredicateList.add(parseSimplePredicate(xmlSubSimplePredicate));
        }
    }
    if (xmlCompoundPredicate.sizeOfCompoundPredicateArray() != 0) {
        for (CompoundPredicate xmlSubCompoundPredicate : xmlCompoundPredicate.getCompoundPredicateList()) {
            tempPredicateList.add(parseCompoundPredicate(xmlSubCompoundPredicate));
        }
    }
    if (xmlCompoundPredicate.sizeOfSimpleSetPredicateArray() != 0) {
        for (SimpleSetPredicate xmlSubSimpleSetPredicate : xmlCompoundPredicate.getSimpleSetPredicateList()) {
            tempPredicateList.add(parseSimpleSetPredicate(xmlSubSimpleSetPredicate));
        }
    }
    if (xmlCompoundPredicate.sizeOfTrueArray() != 0) {
        for (int i = 0; i < xmlCompoundPredicate.sizeOfTrueArray(); i++) {
            tempPredicateList.add(new PMMLTruePredicate());
        }
    }
    if (xmlCompoundPredicate.sizeOfFalseArray() != 0) {
        for (int i = 0; i < xmlCompoundPredicate.sizeOfFalseArray(); i++) {
            tempPredicateList.add(new PMMLFalsePredicate());
        }
    }
    List<String> predicateNames = new ArrayList<String>();
    XmlCursor xmlCursor = xmlCompoundPredicate.newCursor();
    if (xmlCursor.toFirstChild()) {
        do {
            XmlObject xmlElement = xmlCursor.getObject();
            XmlCursor elementCursor = xmlElement.newCursor();
            if (xmlElement instanceof CompoundPredicateDocument.CompoundPredicate) {
                predicateNames.add(COMPOUND);
            } else if (xmlElement instanceof TrueDocument.True) {
                predicateNames.add(TRUE);
            } else if (xmlElement instanceof FalseDocument.False) {
                predicateNames.add(FALSE);
            } else {
                elementCursor.toFirstAttribute();
                do {
                    if ("field".equals(elementCursor.getName().getLocalPart())) {
                        predicateNames.add(m_nameMapper.getColumnName(elementCursor.getTextValue()));
                        break;
                    }
                } while (elementCursor.toNextAttribute());
            }
        } while (xmlCursor.toNextSibling());
    }
    // ------------------------------------------------------
    // sort the predicate list
    List<PMMLPredicate> predicateList = new ArrayList<PMMLPredicate>();
    List<PMMLPredicate> compoundList = new ArrayList<PMMLPredicate>();
    for (PMMLPredicate tempPredicate : tempPredicateList) {
        if (tempPredicate instanceof PMMLCompoundPredicate) {
            compoundList.add(tempPredicate);
        }
    }
    for (String name : predicateNames) {
        if (name.equals(COMPOUND)) {
            predicateList.add(compoundList.get(0));
            compoundList.remove(0);
        } else if (name.equals(TRUE)) {
            predicateList.add(new PMMLTruePredicate());
        } else if (name.equals(FALSE)) {
            predicateList.add(new PMMLFalsePredicate());
        } else {
            int foundIndex = -1, i = 0;
            for (PMMLPredicate tempPredicate : tempPredicateList) {
                if (tempPredicate instanceof PMMLSimplePredicate) {
                    if (name.equals(((PMMLSimplePredicate) tempPredicate).getSplitAttribute())) {
                        predicateList.add(tempPredicate);
                        foundIndex = i;
                        break;
                    }
                } else if (tempPredicate instanceof PMMLSimpleSetPredicate) {
                    if (name.equals(((PMMLSimpleSetPredicate) tempPredicate).getSplitAttribute())) {
                        predicateList.add(tempPredicate);
                        foundIndex = i;
                        break;
                    }
                }
                ++i;
            }
            assert foundIndex >= 0 : tempPredicateList + "\n" + name;
            tempPredicateList.remove(foundIndex);
        }
    }
    LinkedList<PMMLPredicate> subPredicates = new LinkedList<PMMLPredicate>(predicateList);
    String operator = xmlCompoundPredicate.getBooleanOperator().toString();
    PMMLCompoundPredicate compoundPredicate = newCompoundPredicate(operator);
    compoundPredicate.setPredicates(subPredicates);
    return compoundPredicate;
}
Also used : TrueDocument(org.dmg.pmml.TrueDocument) ArrayList(java.util.ArrayList) SimplePredicate(org.dmg.pmml.SimplePredicateDocument.SimplePredicate) LinkedList(java.util.LinkedList) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate) XmlCursor(org.apache.xmlbeans.XmlCursor) CompoundPredicate(org.dmg.pmml.CompoundPredicateDocument.CompoundPredicate) XmlObject(org.apache.xmlbeans.XmlObject)

Example 4 with SimplePredicate

use of org.dmg.pmml.SimplePredicateDocument.SimplePredicate in project knime-core by knime.

the class PMMLDecisionTreeTranslator method addTreeNode.

/**
 * A recursive function which converts each KNIME Tree node to a
 * corresponding PMML element.
 *
 * @param pmmlNode the desired PMML element
 * @param node A KNIME DecisionTree node
 */
private static void addTreeNode(final NodeDocument.Node pmmlNode, final DecisionTreeNode node, final DerivedFieldMapper mapper) {
    pmmlNode.setId(String.valueOf(node.getOwnIndex()));
    pmmlNode.setScore(node.getMajorityClass().toString());
    // read in and then exported again
    if (node.getEntireClassCount() > 0) {
        pmmlNode.setRecordCount(node.getEntireClassCount());
    }
    if (node instanceof DecisionTreeNodeSplitPMML) {
        int defaultChild = ((DecisionTreeNodeSplitPMML) node).getDefaultChildIndex();
        if (defaultChild > -1) {
            pmmlNode.setDefaultChild(String.valueOf(defaultChild));
        }
    }
    // adding score and stuff from parent
    DecisionTreeNode parent = node.getParent();
    if (parent == null) {
        // When the parent is null, it is the root Node.
        // For root node, the predicate is always True.
        pmmlNode.addNewTrue();
    } else if (parent instanceof DecisionTreeNodeSplitContinuous) {
        // SimplePredicate case
        DecisionTreeNodeSplitContinuous splitNode = (DecisionTreeNodeSplitContinuous) parent;
        if (splitNode.getIndex(node) == 0) {
            SimplePredicate pmmlSimplePredicate = pmmlNode.addNewSimplePredicate();
            pmmlSimplePredicate.setField(mapper.getDerivedFieldName(splitNode.getSplitAttr()));
            pmmlSimplePredicate.setOperator(Operator.LESS_OR_EQUAL);
            pmmlSimplePredicate.setValue(String.valueOf(splitNode.getThreshold()));
        } else if (splitNode.getIndex(node) == 1) {
            pmmlNode.addNewTrue();
        }
    } else if (parent instanceof DecisionTreeNodeSplitNominalBinary) {
        // SimpleSetPredicate case
        DecisionTreeNodeSplitNominalBinary splitNode = (DecisionTreeNodeSplitNominalBinary) parent;
        SimpleSetPredicate pmmlSimpleSetPredicate = pmmlNode.addNewSimpleSetPredicate();
        pmmlSimpleSetPredicate.setField(mapper.getDerivedFieldName(splitNode.getSplitAttr()));
        pmmlSimpleSetPredicate.setBooleanOperator(SimpleSetPredicate.BooleanOperator.IS_IN);
        ArrayType pmmlArray = pmmlSimpleSetPredicate.addNewArray();
        pmmlArray.setType(ArrayType.Type.STRING);
        DataCell[] splitValues = splitNode.getSplitValues();
        List<Integer> indices = null;
        if (splitNode.getIndex(node) == SplitNominalBinary.LEFT_PARTITION) {
            indices = splitNode.getLeftChildIndices();
        } else if (splitNode.getIndex(node) == SplitNominalBinary.RIGHT_PARTITION) {
            indices = splitNode.getRightChildIndices();
        } else {
            throw new IllegalArgumentException("Split node is neither " + "contained in the right nor in the left partition.");
        }
        StringBuilder classSet = new StringBuilder();
        for (Integer i : indices) {
            if (classSet.length() > 0) {
                classSet.append(" ");
            }
            classSet.append(splitValues[i].toString());
        }
        pmmlArray.setN(BigInteger.valueOf(indices.size()));
        XmlCursor xmlCursor = pmmlArray.newCursor();
        xmlCursor.setTextValue(classSet.toString());
        xmlCursor.dispose();
    } else if (parent instanceof DecisionTreeNodeSplitNominal) {
        DecisionTreeNodeSplitNominal splitNode = (DecisionTreeNodeSplitNominal) parent;
        SimplePredicate pmmlSimplePredicate = pmmlNode.addNewSimplePredicate();
        pmmlSimplePredicate.setField(mapper.getDerivedFieldName(splitNode.getSplitAttr()));
        pmmlSimplePredicate.setOperator(Operator.EQUAL);
        int nodeIndex = parent.getIndex(node);
        pmmlSimplePredicate.setValue(String.valueOf(splitNode.getSplitValues()[nodeIndex].toString()));
    } else if (parent instanceof DecisionTreeNodeSplitPMML) {
        DecisionTreeNodeSplitPMML splitNode = (DecisionTreeNodeSplitPMML) parent;
        int nodeIndex = parent.getIndex(node);
        // get the PMML predicate of the current node from its parent
        PMMLPredicate predicate = splitNode.getSplitPred()[nodeIndex];
        if (predicate instanceof PMMLCompoundPredicate) {
            // surrogates as used in GBT
            exportCompoundPredicate(pmmlNode, (PMMLCompoundPredicate) predicate, mapper);
        } else {
            predicate.setSplitAttribute(mapper.getDerivedFieldName(predicate.getSplitAttribute()));
            // delegate the writing to the predicate translator
            PMMLPredicateTranslator.exportTo(predicate, pmmlNode);
        }
    } else {
        throw new IllegalArgumentException("Node Type " + parent.getClass() + " is not supported!");
    }
    // adding score distribution (class counts)
    Set<Entry<DataCell, Double>> classCounts = node.getClassCounts().entrySet();
    Iterator<Entry<DataCell, Double>> iterator = classCounts.iterator();
    while (iterator.hasNext()) {
        Entry<DataCell, Double> entry = iterator.next();
        DataCell cell = entry.getKey();
        Double freq = entry.getValue();
        ScoreDistribution pmmlScoreDist = pmmlNode.addNewScoreDistribution();
        pmmlScoreDist.setValue(cell.toString());
        pmmlScoreDist.setRecordCount(freq);
    }
    // adding children
    if (!(node instanceof DecisionTreeNodeLeaf)) {
        for (int i = 0; i < node.getChildCount(); i++) {
            addTreeNode(pmmlNode.addNewNode(), node.getChildAt(i), mapper);
        }
    }
}
Also used : DecisionTreeNodeSplitNominal(org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeSplitNominal) ArrayType(org.dmg.pmml.ArrayType) Entry(java.util.Map.Entry) DecisionTreeNodeSplitPMML(org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeSplitPMML) SimplePredicate(org.dmg.pmml.SimplePredicateDocument.SimplePredicate) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate) XmlCursor(org.apache.xmlbeans.XmlCursor) BigInteger(java.math.BigInteger) ScoreDistribution(org.dmg.pmml.ScoreDistributionDocument.ScoreDistribution) DecisionTreeNodeLeaf(org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeLeaf) DecisionTreeNodeSplitNominalBinary(org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeSplitNominalBinary) DataCell(org.knime.core.data.DataCell) DecisionTreeNodeSplitContinuous(org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeSplitContinuous) DecisionTreeNode(org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode)

Example 5 with SimplePredicate

use of org.dmg.pmml.SimplePredicateDocument.SimplePredicate in project knime-core by knime.

the class PMMLPredicateTranslator method exportTo.

/**
 * @param predicate the predicate to export
 * @param compound the CompundPredicate element to add the predicate to
 */
public static void exportTo(final PMMLPredicate predicate, final CompoundPredicate compound) {
    /**
     * Is basically a duplicate of the other export methods but there is no common parent class and therefore the
     * code is not really reusable.
     */
    if (predicate instanceof PMMLFalsePredicate) {
        compound.addNewFalse();
    } else if (predicate instanceof PMMLTruePredicate) {
        compound.addNewTrue();
    } else if (predicate instanceof PMMLFalsePredicate) {
        compound.addNewFalse();
    } else if (predicate instanceof PMMLSimplePredicate) {
        PMMLSimplePredicate sp = (PMMLSimplePredicate) predicate;
        SimplePredicate simplePred = compound.addNewSimplePredicate();
        initSimplePredicate(sp, simplePred);
    } else if (predicate instanceof PMMLSimpleSetPredicate) {
        PMMLSimpleSetPredicate sp = (PMMLSimpleSetPredicate) predicate;
        SimpleSetPredicate setPred = compound.addNewSimpleSetPredicate();
        initSimpleSetPred(sp, setPred);
    } else if (predicate instanceof PMMLCompoundPredicate) {
        PMMLCompoundPredicate compPred = (PMMLCompoundPredicate) predicate;
        CompoundPredicate cp = CompoundPredicate.Factory.newInstance();
        cp.setBooleanOperator(getOperator(compPred.getBooleanOperator()));
        for (PMMLPredicate pred : compPred.getPredicates()) {
            exportTo(pred, cp);
        }
    }
}
Also used : CompoundPredicate(org.dmg.pmml.CompoundPredicateDocument.CompoundPredicate) SimplePredicate(org.dmg.pmml.SimplePredicateDocument.SimplePredicate) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate)

Aggregations

SimplePredicate (org.dmg.pmml.SimplePredicateDocument.SimplePredicate)11 SimpleSetPredicate (org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate)9 CompoundPredicate (org.dmg.pmml.CompoundPredicateDocument.CompoundPredicate)8 PMMLCompoundPredicate (org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate)4 PMMLSimplePredicate (org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate)4 ArrayList (java.util.ArrayList)3 XmlCursor (org.apache.xmlbeans.XmlCursor)3 ScoreDistribution (org.dmg.pmml.ScoreDistributionDocument.ScoreDistribution)3 PMMLFalsePredicate (org.knime.base.node.mine.decisiontree2.PMMLFalsePredicate)3 PMMLSimpleSetPredicate (org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate)3 Entry (java.util.Map.Entry)2 XmlObject (org.apache.xmlbeans.XmlObject)2 SimpleRule (org.dmg.pmml.SimpleRuleDocument.SimpleRule)2 PMMLPredicate (org.knime.base.node.mine.decisiontree2.PMMLPredicate)2 PMMLTruePredicate (org.knime.base.node.mine.decisiontree2.PMMLTruePredicate)2 DecisionTreeNode (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode)2 DecisionTreeNodeSplitPMML (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeSplitPMML)2 DataCell (org.knime.core.data.DataCell)2 File (java.io.File)1 IOException (java.io.IOException)1