示例#1
0
 private LenskitRecommenderEngine loadEngine() throws RecommenderBuildException, IOException {
   File modelFile = options.get("model_file");
   if (modelFile == null) {
     logger.info("creating fresh recommender");
     LenskitRecommenderEngineBuilder builder = LenskitRecommenderEngine.newBuilder();
     for (LenskitConfiguration config : environment.loadConfigurations(getConfigFiles())) {
       builder.addConfiguration(config);
     }
     builder.addConfiguration(input.getConfiguration());
     Stopwatch timer = Stopwatch.createStarted();
     LenskitRecommenderEngine engine = builder.build();
     timer.stop();
     logger.info("built recommender in {}", timer);
     return engine;
   } else {
     logger.info("loading recommender from {}", modelFile);
     LenskitRecommenderEngineLoader loader = LenskitRecommenderEngine.newLoader();
     for (LenskitConfiguration config : environment.loadConfigurations(getConfigFiles())) {
       loader.addConfiguration(config);
     }
     loader.addConfiguration(input.getConfiguration());
     Stopwatch timer = Stopwatch.createStarted();
     LenskitRecommenderEngine engine;
     CompressionMode comp = CompressionMode.autodetect(modelFile);
     InputStream input = new FileInputStream(modelFile);
     try {
       input = comp.wrapInput(input);
       engine = loader.load(input);
     } finally {
       input.close();
     }
     timer.stop();
     logger.info("loaded recommender in {}", timer);
     return engine;
   }
 }
示例#2
0
 public static void configureArguments(ArgumentParser parser) {
   InputData.configureArguments(parser);
   ScriptEnvironment.configureArguments(parser);
   parser
       .addArgument("-c", "--config-file")
       .type(File.class)
       .action(Arguments.append())
       .metavar("FILE")
       .help("use configuration from FILE");
   parser
       .addArgument("-m", "--model-file")
       .type(File.class)
       .metavar("FILE")
       .help("load model from FILE");
   parser.addArgument("--print-channel").metavar("CHAN").help("also print value from CHAN");
   parser.addArgument("user").type(Long.class).metavar("USER").help("predict for USER");
   parser
       .addArgument("items")
       .type(Long.class)
       .metavar("ITEM")
       .nargs("+")
       .help("predict for ITEMs");
 }