Search in sources :

Example 1 with PMMLDataDictionaryTranslator

use of org.knime.core.node.port.pmml.PMMLDataDictionaryTranslator in project knime-core by knime.

the class FromDecisionTreeNodeModel method execute.

/**
 * {@inheritDoc}
 * @throws CanceledExecutionException Execution cancelled.
 * @throws InvalidSettingsException No or more than one RuleSet model is in the PMML input.
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, InvalidSettingsException {
    PMMLPortObject decTreeModel = (PMMLPortObject) inData[0];
    PMMLDecisionTreeTranslator treeTranslator = new PMMLDecisionTreeTranslator();
    decTreeModel.initializeModelTranslator(treeTranslator);
    DecisionTree decisionTree = treeTranslator.getDecisionTree();
    decisionTree.getRootNode();
    PMMLPortObject ruleSetModel = new PMMLPortObject(decTreeModel.getSpec());
    PMMLDocument document = PMMLDocument.Factory.newInstance();
    PMML pmml = document.addNewPMML();
    PMMLPortObjectSpec.writeHeader(pmml);
    pmml.setVersion(PMMLPortObject.PMML_V4_2);
    new PMMLDataDictionaryTranslator().exportTo(document, decTreeModel.getSpec());
    RuleSetModel newRuleSetModel = pmml.addNewRuleSetModel();
    PMMLMiningSchemaTranslator.writeMiningSchema(decTreeModel.getSpec(), newRuleSetModel);
    newRuleSetModel.setFunctionName(MININGFUNCTION.CLASSIFICATION);
    newRuleSetModel.setAlgorithmName("RuleSet");
    RuleSet ruleSet = newRuleSetModel.addNewRuleSet();
    ruleSet.addNewRuleSelectionMethod().setCriterion(Criterion.FIRST_HIT);
    addRules(ruleSet, new ArrayList<DecisionTreeNode>(), decisionTree.getRootNode());
    // TODO: Return a BufferedDataTable for each output port
    PMMLPortObject pmmlPortObject = new PMMLPortObject(ruleSetModel.getSpec(), document);
    return new PortObject[] { pmmlPortObject, new RuleSetToTable(m_rulesToTable).execute(exec, pmmlPortObject) };
}
Also used : RuleSetModel(org.dmg.pmml.RuleSetModelDocument.RuleSetModel) RuleSet(org.dmg.pmml.RuleSetDocument.RuleSet) DecisionTree(org.knime.base.node.mine.decisiontree2.model.DecisionTree) PMMLDecisionTreeTranslator(org.knime.base.node.mine.decisiontree2.PMMLDecisionTreeTranslator) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PMML(org.dmg.pmml.PMMLDocument.PMML) DecisionTreeNodeSplitPMML(org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeSplitPMML) PMMLDocument(org.dmg.pmml.PMMLDocument) PMMLDataDictionaryTranslator(org.knime.core.node.port.pmml.PMMLDataDictionaryTranslator) PortObject(org.knime.core.node.port.PortObject) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) RuleSetToTable(org.knime.base.node.rules.engine.totable.RuleSetToTable) DecisionTreeNode(org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode)

Example 2 with PMMLDataDictionaryTranslator

use of org.knime.core.node.port.pmml.PMMLDataDictionaryTranslator in project knime-core by knime.

the class AbstractMetaDataMapper method extractTableSpecFromPMMLDoc.

private static DataTableSpec extractTableSpecFromPMMLDoc(final PMMLDocument pmmlDoc) {
    PMMLDataDictionaryTranslator dataDictTrans = new PMMLDataDictionaryTranslator();
    dataDictTrans.initializeFrom(pmmlDoc);
    return dataDictTrans.getDataTableSpec();
}
Also used : PMMLDataDictionaryTranslator(org.knime.core.node.port.pmml.PMMLDataDictionaryTranslator)

Example 3 with PMMLDataDictionaryTranslator

use of org.knime.core.node.port.pmml.PMMLDataDictionaryTranslator in project knime-core by knime.

the class PMMLImport method init.

/**
 * @param pmmlDoc
 */
private void init(final PMMLDocument pmmlDoc) {
    PMMLDataDictionaryTranslator dictTrans = new PMMLDataDictionaryTranslator();
    dictTrans.initializeFrom(pmmlDoc);
    DataTableSpec tableSpec = dictTrans.getDataTableSpec();
    List<String> activeDerivedFields = dictTrans.getActiveDerivedFields();
    PMMLPortObjectSpecCreator specCreator = new PMMLPortObjectSpecCreator(tableSpec);
    PMMLMiningSchemaTranslator miningTrans = new PMMLMiningSchemaTranslator();
    miningTrans.initializeFrom(pmmlDoc);
    Set<String> activeFields = new LinkedHashSet<String>();
    List<String> miningFields = miningTrans.getActiveFields();
    /* If we have a model all active fields of the data dictionary
         * are passed through the mining schema. */
    activeFields.addAll(miningFields);
    activeFields.addAll(activeDerivedFields);
    specCreator.setLearningColsNames(new LinkedList<String>(activeFields));
    specCreator.addPreprocColNames(activeDerivedFields);
    specCreator.setTargetColsNames(miningTrans.getTargetFields());
    PMMLPortObjectSpec portObjectSpec = specCreator.createSpec();
    m_portObject = new PMMLPortObject(portObjectSpec, pmmlDoc);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PMMLMiningSchemaTranslator(org.knime.core.node.port.pmml.PMMLMiningSchemaTranslator) DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PMMLDataDictionaryTranslator(org.knime.core.node.port.pmml.PMMLDataDictionaryTranslator) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 4 with PMMLDataDictionaryTranslator

use of org.knime.core.node.port.pmml.PMMLDataDictionaryTranslator in project knime-core by knime.

the class RuleEngine2PortsNodeModel method fillUsingDoc.

/**
 * Fills the results obtained from {@code doc}.
 *
 * @param doc A {@link PMMLDocument}.
 * @param ruleSetModel The {@link RuleSetModel}.
 * @param pmml The {@link PMMLPortObject}.
 */
private void fillUsingDoc(final PMMLDocument doc, final RuleSetModel ruleSetModel, final PMMLPortObject pmml) {
    PMMLRuleTranslator modelTranslator = new PMMLRuleTranslator(m_settings.isProvideStatistics());
    PMMLMiningSchemaTranslator.writeMiningSchema(pmml.getSpec(), ruleSetModel);
    PMMLDataDictionaryTranslator ddTranslator = new PMMLDataDictionaryTranslator();
    ddTranslator.exportTo(doc, pmml.getSpec());
    modelTranslator.initializeFrom(doc);
    pmml.addModelTranslater(modelTranslator);
    pmml.validate();
}
Also used : PMMLRuleTranslator(org.knime.base.node.rules.engine.pmml.PMMLRuleTranslator) PMMLDataDictionaryTranslator(org.knime.core.node.port.pmml.PMMLDataDictionaryTranslator)

Example 5 with PMMLDataDictionaryTranslator

use of org.knime.core.node.port.pmml.PMMLDataDictionaryTranslator in project knime-core by knime.

the class PMMLRuleEditorNodeModel method createRearrangerAndPMMLModel.

private RearrangerAndPMMLModel createRearrangerAndPMMLModel(final DataTableSpec spec) throws ParseException, InvalidSettingsException {
    final PMMLDocument doc = PMMLDocument.Factory.newInstance();
    final PMML pmml = doc.addNewPMML();
    RuleSetModel ruleSetModel = pmml.addNewRuleSetModel();
    RuleSet ruleSet = ruleSetModel.addNewRuleSet();
    PMMLRuleParser parser = new PMMLRuleParser(spec, getAvailableInputFlowVariables());
    ColumnRearranger rearranger = createRearranger(spec, ruleSet, parser);
    PMMLPortObject ret = new PMMLPortObject(createPMMLPortObjectSpec(rearranger.createSpec(), parser.getUsedColumns()));
    // if (inData[1] != null) {
    // PMMLPortObject po = (PMMLPortObject)inData[1];
    // TransformationDictionary dict = TransformationDictionary.Factory.newInstance();
    // dict.setDerivedFieldArray(po.getDerivedFields());
    // ret.addGlobalTransformations(dict);
    // }
    PMMLRuleTranslator modelTranslator = new PMMLRuleTranslator();
    ruleSetModel.setFunctionName(MININGFUNCTION.CLASSIFICATION);
    ruleSet.setDefaultConfidence(defaultConfidenceValue());
    PMMLMiningSchemaTranslator.writeMiningSchema(ret.getSpec(), ruleSetModel);
    PMMLDataDictionaryTranslator ddTranslator = new PMMLDataDictionaryTranslator();
    ddTranslator.exportTo(doc, ret.getSpec());
    modelTranslator.initializeFrom(doc);
    ret.addModelTranslater(modelTranslator);
    ret.validate();
    return new RearrangerAndPMMLModel(rearranger, ret);
}
Also used : RuleSetModel(org.dmg.pmml.RuleSetModelDocument.RuleSetModel) RuleSet(org.dmg.pmml.RuleSetDocument.RuleSet) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PMML(org.dmg.pmml.PMMLDocument.PMML) PMMLDocument(org.dmg.pmml.PMMLDocument) PMMLDataDictionaryTranslator(org.knime.core.node.port.pmml.PMMLDataDictionaryTranslator)

Aggregations

PMMLDataDictionaryTranslator (org.knime.core.node.port.pmml.PMMLDataDictionaryTranslator)5 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)3 PMMLDocument (org.dmg.pmml.PMMLDocument)2 PMML (org.dmg.pmml.PMMLDocument.PMML)2 RuleSet (org.dmg.pmml.RuleSetDocument.RuleSet)2 RuleSetModel (org.dmg.pmml.RuleSetModelDocument.RuleSetModel)2 LinkedHashSet (java.util.LinkedHashSet)1 PMMLDecisionTreeTranslator (org.knime.base.node.mine.decisiontree2.PMMLDecisionTreeTranslator)1 DecisionTree (org.knime.base.node.mine.decisiontree2.model.DecisionTree)1 DecisionTreeNode (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode)1 DecisionTreeNodeSplitPMML (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeSplitPMML)1 PMMLRuleTranslator (org.knime.base.node.rules.engine.pmml.PMMLRuleTranslator)1 RuleSetToTable (org.knime.base.node.rules.engine.totable.RuleSetToTable)1 DataTableSpec (org.knime.core.data.DataTableSpec)1 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)1 PortObject (org.knime.core.node.port.PortObject)1 PMMLMiningSchemaTranslator (org.knime.core.node.port.pmml.PMMLMiningSchemaTranslator)1 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)1 PMMLPortObjectSpecCreator (org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)1