Search in sources :

Example 16 with ModelContentWO

use of org.knime.core.node.ModelContentWO in project knime-core by knime.

the class LinReg2LearnerNodeModel method saveInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void saveInternals(final File internDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    ModelContent content = new ModelContent(CFG_SETTINGS);
    ModelContentWO specContent = content.addModelContent(CFG_SPEC);
    m_content.getSpec().getDataTableSpec().save(specContent);
    ModelContentWO parContent = content.addModelContent(CFG_LinReg2_CONTENT);
    m_content.save(parContent);
    File outFile = new File(internDir, FILE_SAVE);
    content.saveToXML(new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(outFile))));
    File dataFile = new File(internDir, FILE_DATA);
    DataContainer.writeToZip(m_rowContainer, dataFile, exec);
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) ModelContent(org.knime.core.node.ModelContent) ModelContentWO(org.knime.core.node.ModelContentWO) FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 17 with ModelContentWO

use of org.knime.core.node.ModelContentWO in project knime-core by knime.

the class AssociationRuleModel method saveToModelContent.

/**
 * @param model the model the association rules are saved to
 */
public void saveToModelContent(final ModelContentWO model) {
    ModelContentWO associationRulesModel = model.addModelContent(ASSOCIATION_RULES);
    associationRulesModel.addString(TYPE, ASSOCIATION_RULES);
    if (m_nameMapping != null) {
        String[] mappingArray = new String[m_nameMapping.size()];
        m_nameMapping.toArray(mappingArray);
        associationRulesModel.addStringArray(NAME_MAPPING, mappingArray);
    }
    int counter = 0;
    associationRulesModel.addInt(NR_RULES, m_rules.size());
    for (AssociationRule rule : m_rules) {
        ModelContentWO ruleModel = associationRulesModel.addModelContent(ASSOCIATION_RULE + counter++);
        ruleModel.addDouble(SUPPORT, rule.getSupport());
        ruleModel.addDouble(CONFIDENCE, rule.getConfidence());
        ruleModel.addDouble(LIFT, rule.getLift());
        String name;
        /*
            if (m_nameMapping != null 
                    && m_nameMapping.size() > rule.getConsequent()) {
                name = m_nameMapping.get(rule.getConsequent());
            } else {
                name = "item" + rule.getConsequent();
            }
            */
        // ruleModel.addString(CONSEQUENT, name);
        // int antecedentSize = rule.getAntecedent().size();
        ModelContentWO antecedentModel = ruleModel.addModelContent(ANTECEDENT);
        // antecedentModel.addInt(ANTECEDENT_SIZE, antecedentSize);
        int itemCounter = 0;
        for (Integer item : rule.getAntecedent()) {
            if (m_nameMapping != null && m_nameMapping.size() > item) {
                name = m_nameMapping.get(item);
            } else {
                name = "item" + item;
            }
            antecedentModel.addString(ITEM + itemCounter++, name);
        }
    }
}
Also used : ModelContentWO(org.knime.core.node.ModelContentWO)

Example 18 with ModelContentWO

use of org.knime.core.node.ModelContentWO in project knime-core by knime.

the class DecisionTree method saveToPredictorParams.

// ///////////////////
// Save & Load
// ///////////////////
/**
 * Save decision tree to a ModelContent object.
 *
 * @param pConf configuration object to attach decision tree to
 * @param saveKeysAndPatterns whether to save the keys and patterns
 */
public void saveToPredictorParams(final ModelContentWO pConf, final boolean saveKeysAndPatterns) {
    pConf.addString("type", "DecisionTree");
    pConf.addString("version", "0.0");
    pConf.addString("color_column", m_colorColumn);
    ModelContentWO newNodeConf = pConf.addModelContent("rootNode");
    m_rootNode.saveToPredictorParams(newNodeConf, saveKeysAndPatterns);
}
Also used : ModelContentWO(org.knime.core.node.ModelContentWO)

Example 19 with ModelContentWO

use of org.knime.core.node.ModelContentWO in project knime-core by knime.

the class DecisionTreeNodeSplit method saveNodeInternalsToPredParams.

/**
 *  {@inheritDoc}
 */
@Override
public final void saveNodeInternalsToPredParams(final ModelContentWO pConf, final boolean saveKeysAndPatterns) {
    saveNodeSplitInternalsToPredParams(pConf);
    pConf.addString("splitAttribute", m_splitAttr);
    pConf.addInt("nrChildren", m_child.length);
    for (int i = 0; i < m_child.length; i++) {
        ModelContentWO newChildConf = pConf.addModelContent("child" + i);
        newChildConf.addInt("index", m_childIndex[i]);
        m_child[i].saveToPredictorParams(newChildConf, saveKeysAndPatterns);
    }
}
Also used : ModelContentWO(org.knime.core.node.ModelContentWO)

Example 20 with ModelContentWO

use of org.knime.core.node.ModelContentWO in project knime-core by knime.

the class BasisFunctionModelContent method save.

/**
 * Save the given rule model and model spec into this model content object.
 * @param modelCont save spec and rule to
 */
public void save(final ModelContentWO modelCont) {
    // save rules
    ModelContentWO ruleSpec = modelCont.addModelContent("rules");
    for (DataCell key : m_bfs.keySet()) {
        for (BasisFunctionPredictorRow bf : m_bfs.get(key)) {
            ModelContentWO bfParam = ruleSpec.addModelContent(bf.getId().toString());
            bf.save(bfParam);
        }
    }
    // save spec
    ModelContentWO modelSpec = modelCont.addModelContent("model_spec");
    for (int i = 0; i < m_spec.getNumColumns(); i++) {
        DataColumnSpec cspec = m_spec.getColumnSpec(i);
        cspec.save(modelSpec.addConfig(cspec.getName()));
    }
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) ModelContentWO(org.knime.core.node.ModelContentWO) DataCell(org.knime.core.data.DataCell)

Aggregations

ModelContentWO (org.knime.core.node.ModelContentWO)23 BufferedOutputStream (java.io.BufferedOutputStream)7 File (java.io.File)7 FileOutputStream (java.io.FileOutputStream)7 ModelContent (org.knime.core.node.ModelContent)7 GZIPOutputStream (java.util.zip.GZIPOutputStream)6 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 GroupKey (org.knime.base.node.preproc.groupby.GroupKey)2 DataCell (org.knime.core.data.DataCell)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 DataTableSpec (org.knime.core.data.DataTableSpec)1 RowKey (org.knime.core.data.RowKey)1 FileStore (org.knime.core.data.filestore.FileStore)1 FileStoreKey (org.knime.core.data.filestore.FileStoreKey)1