/** * Load a recommender from a file. * * @param file The recommender model file to load. * @return The recommender engine. * @throws IOException if there is an error reading the input data. * @throws RecommenderConfigurationException * if there is a configuration error with the deserialized recommender or * the configurations applied to it. */ public LenskitRecommenderEngine load(File file) throws IOException, RecommenderConfigurationException { logger.info("Loading recommender engine from {}", file); try (FileInputStream input = new FileInputStream(file)) { CompressionMode effComp = compressionMode.getEffectiveCompressionMode(file.getName()); logger.info("using {} compression", effComp); return loadInternal(effComp.wrapInput(input)); } }
/** * Load a recommender engine from an input stream. * <p> * <strong>Note:</strong> this method is only capable of auto-detecting gzip-compressed data. * If the {@linkplain #setCompressionMode(CompressionMode) compression mode} is {@link CompressionMode#AUTO}, * only gzip-compressed streams are supported. Set the compression mode manually if you are * using XZ compression. * </p> * * @param stream The input stream. * @return The deserialized recommender. * @throws IOException if there is an error reading the input data. * @throws RecommenderConfigurationException * if there is a configuration error with the deserialized recommender or * the configurations applied to it. */ public LenskitRecommenderEngine load(@WillClose InputStream stream) throws IOException, RecommenderConfigurationException { InputStream decomp; if (compressionMode == CompressionMode.AUTO) { decomp = LKFileUtils.transparentlyDecompress(stream); } else { decomp = compressionMode.wrapInput(stream); } return loadInternal(decomp); }
/** * Load a recommender from a file. * * @param file The recommender model file to load. * @return The recommender engine. * @throws IOException if there is an error reading the input data. * @throws RecommenderConfigurationException * if there is a configuration error with the deserialized recommender or * the configurations applied to it. */ public LenskitRecommenderEngine load(File file) throws IOException, RecommenderConfigurationException { logger.info("Loading recommender engine from {}", file); try (FileInputStream input = new FileInputStream(file)) { CompressionMode effComp = compressionMode.getEffectiveCompressionMode(file.getName()); logger.info("using {} compression", effComp); return loadInternal(effComp.wrapInput(input)); } }
/** * Load a recommender engine from an input stream. * <p> * <strong>Note:</strong> this method is only capable of auto-detecting gzip-compressed data. * If the {@linkplain #setCompressionMode(CompressionMode) compression mode} is {@link CompressionMode#AUTO}, * only gzip-compressed streams are supported. Set the compression mode manually if you are * using XZ compression. * </p> * * @param stream The input stream. * @return The deserialized recommender. * @throws IOException if there is an error reading the input data. * @throws RecommenderConfigurationException * if there is a configuration error with the deserialized recommender or * the configurations applied to it. */ public LenskitRecommenderEngine load(@WillClose InputStream stream) throws IOException, RecommenderConfigurationException { InputStream decomp; if (compressionMode == CompressionMode.AUTO) { decomp = LKFileUtils.transparentlyDecompress(stream); } else { decomp = compressionMode.wrapInput(stream); } return loadInternal(decomp); }