Search in sources :

Example 6 with ModelContentWO

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

the class LogRegLearnerNodeModel 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_LOGREG_CONTENT);
    m_content.save(parContent);
    File outFile = new File(internDir, FILE_SAVE);
    content.saveToXML(new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(outFile))));
}
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 7 with ModelContentWO

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

the class URIPortObject method save.

/**
 * {@inheritDoc}
 */
@Override
protected void save(final ModelContentWO model, final ExecutionMonitor exec) throws CanceledExecutionException {
    int i = 0;
    for (URIContent uri : m_uriContents) {
        ModelContentWO child = model.addModelContent("child-" + i);
        uri.save(child);
        i++;
    }
}
Also used : ModelContentWO(org.knime.core.node.ModelContentWO)

Example 8 with ModelContentWO

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

the class FrequentItemSetModel method saveToModelContent.

/**
 * Saves the itemsets to the model.
 *
 * @param model the model the itemsets are saved to
 */
public void saveToModelContent(final ModelContentWO model) {
    ModelContentWO itemSetsModel = model.addModelContent(ITEMSET_MODEL);
    model.addString(TYPE, ITEMSET_MODEL);
    String[] mappingArray = new String[0];
    if (m_nameMapping != null) {
        mappingArray = new String[m_nameMapping.size()];
        m_nameMapping.toArray(mappingArray);
    }
    itemSetsModel.addStringArray(NAME_MAPPING, mappingArray);
    m_itemSetCounter = 0;
    for (FrequentItemSet set : m_itemSets) {
        if (set.getSupport() == 1.0) {
            m_alwaysFrequent.add(set);
        } else {
            ModelContentWO itemSetModel = itemSetsModel.addModelContent(ITEMSET + m_itemSetCounter++);
            m_itemCounter = 0;
            saveItemSetTo(itemSetModel, set);
        }
    }
    if (m_alwaysFrequent.size() > 0) {
        ModelContentWO alwaysFrequentModel = itemSetsModel.addModelContent(ITEMSET + m_itemSetCounter++);
        m_itemCounter = 0;
        for (FrequentItemSet set : m_alwaysFrequent) {
            saveItemSetTo(alwaysFrequentModel, set);
        }
        alwaysFrequentModel.addInt(ITEMSET_SIZE, m_alwaysFrequent.size());
    }
    itemSetsModel.addInt(NUMBER_OF_ITEMSETS, m_itemSetCounter);
}
Also used : ModelContentWO(org.knime.core.node.ModelContentWO)

Example 9 with ModelContentWO

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

the class SotaPortObjectSpec method save.

/**
 * {@inheritDoc}
 */
@Override
protected void save(final ModelContentWO model) {
    if (m_spec != null) {
        ModelContentWO subContent = model.addModelContent(SotaPortObject.CFG_KEY_SPEC);
        m_spec.save(subContent);
        model.addInt(SotaPortObject.CFG_KEY_CLASSCOL_INDEX, m_indexOfClassCol);
    }
}
Also used : ModelContentWO(org.knime.core.node.ModelContentWO)

Example 10 with ModelContentWO

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

the class SotaTreeCell method saveTo.

/**
 * Saves the value of the <code>SotaTreeCell</code> to the given
 * <code>ModelContentWO</code>.
 *
 * @param modelContent The <code>ModelContentWO</code> to save the cells
 * to.
 * @param index The index of the cell to save.
 */
public final void saveTo(final ModelContentWO modelContent, final int index) {
    int ind = index;
    ind++;
    // save resource ect.
    modelContent.addBoolean(CFG_KEY_IS_CELL, m_isCell);
    modelContent.addDouble(CFG_KEY_RESOURCE, m_resource);
    modelContent.addDouble(CFG_KEY_MAX_DISTANCE, m_maxDistance);
    // save level information
    modelContent.addInt(CFG_KEY_LEVEL, m_level);
    modelContent.addInt(CFG_KEY_H_LEVEL, m_hierarchyLevel);
    modelContent.addInt(CFG_KEY_LEVEL_IN_H, m_levelInHierarchy);
    // save data ids
    int dataIdCount = 0;
    modelContent.addInt(CFG_KEY_DATA_ID + "SIZE", m_dataIds.size());
    for (Integer i : m_dataIds) {
        modelContent.addInt(CFG_KEY_DATA_ID + dataIdCount, i);
        dataIdCount++;
    }
    // save row keys
    modelContent.addInt(CFG_KEY_ROW_KEY + "SIZE", m_rowKeys.size());
    int rowKeyCount = 0;
    for (RowKey r : m_rowKeys) {
        modelContent.addString(CFG_KEY_ROW_KEY + rowKeyCount, r.toString());
        rowKeyCount++;
    }
    // save cell data
    modelContent.addInt(CFG_KEY_DATA + "SIZE", m_data.length);
    if (m_data.length > 0) {
        modelContent.addString(CFG_KEY_DATA + "TYPE", m_data[0].getType());
    }
    for (int i = 0; i < m_data.length; i++) {
        ModelContentWO subContent = modelContent.addModelContent(CFG_KEY_DATA + i);
        m_data[i].saveTo(subContent);
    }
    // save data
    modelContent.addString(CFG_KEY_CLASS, m_classCounter.getMostFrequentClass());
    // save left and right
    if (m_left != null) {
        modelContent.addBoolean("HAS" + CFG_KEY_LEFT, true);
        ModelContentWO subContent = modelContent.addModelContent(CFG_KEY_LEFT + ind);
        m_left.saveTo(subContent, ind);
    } else {
        modelContent.addBoolean("HAS" + CFG_KEY_LEFT, false);
    }
    if (m_right != null) {
        modelContent.addBoolean("HAS" + CFG_KEY_RIGHT, true);
        ModelContentWO subContent = modelContent.addModelContent(CFG_KEY_RIGHT + ind);
        m_right.saveTo(subContent, ind);
    } else {
        modelContent.addBoolean("HAS" + CFG_KEY_RIGHT, false);
    }
}
Also used : RowKey(org.knime.core.data.RowKey) ModelContentWO(org.knime.core.node.ModelContentWO)

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