/** * Write the state of this recommender engine to the given file so * that it can be recreated later using another DAOFactory. This uses * default object serialization so if the factory has a PicoContainer or * session bindings containing non-serializable types, this will fail. * * @param file The file to write the rec engine to. * @throws IOException if there is an error serializing the engine. * @see #write(OutputStream) */ public void write(@Nonnull File file) throws IOException { write(file, CompressionMode.NONE); }
/** * Write the state of this recommender engine to the given file so * that it can be recreated later using another DAOFactory. This uses * default object serialization so if the factory has a PicoContainer or * session bindings containing non-serializable types, this will fail. * * @param file The file to write the rec engine to. * @param compressed Whether to compress the output file. * @throws IOException if there is an error serializing the engine. * @see #write(OutputStream) */ public void write(@Nonnull File file, CompressionMode compressed) throws IOException { try (OutputStream out = new FileOutputStream(file); OutputStream zout = compressed.getEffectiveCompressionMode(file.getName()).wrapOutput(out)) { write(zout); } }
@Override public void execute(Namespace opts) throws LenskitCommandException { Context ctx = new Context(opts); LenskitConfiguration dataConfig = ctx.input.getConfiguration(); LenskitRecommenderEngineBuilder builder = LenskitRecommenderEngine.newBuilder(); try { for (LenskitConfiguration config: ctx.environment.loadConfigurations(ctx.getConfigFiles())) { builder.addConfiguration(config); } } catch (IOException e) { throw new LenskitCommandException("error loading LensKit configuration", e); } builder.addConfiguration(dataConfig, ModelDisposition.EXCLUDED); Stopwatch timer = Stopwatch.createStarted(); LenskitRecommenderEngine engine = builder.build(ctx.input.getDAO()); timer.stop(); logger.info("built model in {}", timer); File output = ctx.getOutputFile(); CompressionMode comp = CompressionMode.autodetect(output); logger.info("writing model to {}", output); try (OutputStream raw = new FileOutputStream(output); OutputStream stream = comp.wrapOutput(raw)) { engine.write(stream); } catch (IOException e) { throw new LenskitCommandException("could not write output file", e); } }
/** * Write the state of this recommender engine to the given file so * that it can be recreated later using another DAOFactory. This uses * default object serialization so if the factory has a PicoContainer or * session bindings containing non-serializable types, this will fail. * * @param file The file to write the rec engine to. * @throws IOException if there is an error serializing the engine. * @see #write(OutputStream) */ public void write(@Nonnull File file) throws IOException { write(file, CompressionMode.NONE); }
/** * Write the state of this recommender engine to the given file so * that it can be recreated later using another DAOFactory. This uses * default object serialization so if the factory has a PicoContainer or * session bindings containing non-serializable types, this will fail. * * @param file The file to write the rec engine to. * @param compressed Whether to compress the output file. * @throws IOException if there is an error serializing the engine. * @see #write(OutputStream) */ public void write(@Nonnull File file, CompressionMode compressed) throws IOException { try (OutputStream out = new FileOutputStream(file); OutputStream zout = compressed.getEffectiveCompressionMode(file.getName()).wrapOutput(out)) { write(zout); } }