use of org.knime.core.node.ModelContent in project knime-core by knime.
the class DecTreePredictorNodeModel method saveInternals.
/**
* Save internals.
*
* @param nodeInternDir The intern node directory to save table to.
* @param exec Used to report progress or cancel saving.
* @throws IOException Always, since this method has not been implemented
* yet.
* @see org.knime.core.node.NodeModel
* #saveInternals(java.io.File,ExecutionMonitor)
*/
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException {
// write the tree as pred params
ModelContent model = new ModelContent(INTERNALS_FILE_NAME);
m_decTree.saveToPredictorParams(model, true);
File internalsFile = new File(nodeInternDir, INTERNALS_FILE_NAME);
BufferedOutputStream out2 = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(internalsFile)));
model.saveToXML(out2);
out2.close();
}
use of org.knime.core.node.ModelContent in project knime-core by knime.
the class LinRegLearnerNodeModel method saveInternals.
/**
* {@inheritDoc}
*/
@Override
protected void saveInternals(final File internDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
ModelContent content = new ModelContent(CFG_SETTINGS);
content.addInt(CFG_NR_ROWS, m_nrRows);
content.addInt(CFG_NR_ROWS_SKIPPED, m_nrRowsSkipped);
content.addDouble(CFG_ERROR, m_error);
ModelContentWO specContent = content.addModelContent(CFG_SPEC);
m_params.getSpec().save(specContent);
specContent.addStringArray(CFG_USED_COLUMNS, m_actualUsedColumns);
ModelContentWO parContent = content.addModelContent(CFG_PARAMS);
m_params.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);
}
use of org.knime.core.node.ModelContent 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))));
}
use of org.knime.core.node.ModelContent 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))));
}
use of org.knime.core.node.ModelContent in project knime-core by knime.
the class PortUtil method writeObjectToStream.
/**
* Write the given port object into the given output stream. The output stream does not need to be buffered and is
* not closed after calling this method.
*
* @param po any port object
* @param output any output stream, does not need to be buffered
* @param exec execution context for reporting progress and checking for cancelation
* @throws IOException if an I/O error occurs while serializing the port object
* @throws CanceledExecutionException if the user canceled the operation
*/
public static void writeObjectToStream(final PortObject po, final OutputStream output, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
final boolean originalOutputIsBuffered = ((output instanceof BufferedOutputStream) || (output instanceof ByteArrayOutputStream));
OutputStream os = originalOutputIsBuffered ? output : new BufferedOutputStream(output);
final ZipOutputStream zipOut = new ZipOutputStream(os);
PortObjectSpec spec = po.getSpec();
zipOut.putNextEntry(new ZipEntry("content.xml"));
ModelContent toc = new ModelContent("content");
toc.addInt("version", 1);
toc.addString("port_spec_class", spec.getClass().getName());
toc.addString("port_object_class", po.getClass().getName());
NotInWorkflowWriteFileStoreHandler fileStoreHandler = null;
if (po instanceof FileStorePortObject) {
fileStoreHandler = NotInWorkflowWriteFileStoreHandler.create();
ModelContentWO fileStoreModelContent = toc.addModelContent("filestores");
fileStoreModelContent.addString("handlerUUID", fileStoreHandler.getStoreUUID().toString());
final FileStorePortObject fileStorePO = (FileStorePortObject) po;
FileStoreUtil.invokeFlush(fileStorePO);
List<FileStore> fileStores = FileStoreUtil.getFileStores(fileStorePO);
ModelContentWO fileStoreKeysModel = fileStoreModelContent.addModelContent("port_file_store_keys");
for (int i = 0; i < fileStores.size(); i++) {
FileStoreKey key = fileStoreHandler.translateToLocal(fileStores.get(i), fileStorePO);
key.save(fileStoreKeysModel.addModelContent("filestore_key_" + i));
}
}
toc.saveToXML(new NonClosableOutputStream.Zip(zipOut));
zipOut.putNextEntry(new ZipEntry("objectSpec.file"));
try (PortObjectSpecZipOutputStream specOut = getPortObjectSpecZipOutputStream(new NonClosableOutputStream.Zip(zipOut))) {
PortObjectSpecSerializer specSer = PortTypeRegistry.getInstance().getSpecSerializer(spec.getClass()).get();
specSer.savePortObjectSpec(spec, specOut);
}
// 'close' will propagate as closeEntry
zipOut.putNextEntry(new ZipEntry("object.file"));
try (PortObjectZipOutputStream objOut = getPortObjectZipOutputStream(new NonClosableOutputStream.Zip(zipOut))) {
PortObjectSerializer objSer = PortTypeRegistry.getInstance().getObjectSerializer(po.getClass()).get();
objSer.savePortObject(po, objOut, exec);
}
if (fileStoreHandler != null && fileStoreHandler.hasCopiedFileStores()) {
zipOut.putNextEntry(new ZipEntry("filestores/"));
zipOut.closeEntry();
File baseDir = fileStoreHandler.getBaseDir();
FileUtil.zipDir(zipOut, Arrays.asList(baseDir.listFiles()), "filestores/", FileUtil.ZIP_INCLUDEALL_FILTER, exec.createSubProgress(0.5));
}
zipOut.finish();
if (!originalOutputIsBuffered) {
os.flush();
}
}
Aggregations