示例#1
0
 /**
  * Runs the command line interface given some arguments.
  *
  * @param arguments the command line arguments
  * @return whether or not the command successfully executed
  * @throws Exception if something goes wrong
  */
 public boolean run(String... arguments) throws Exception {
   try {
     if (isFlag(HELP, arguments)) {
       parser.printHelp(stdOut);
     } else if (isFlag(VERSION, arguments)) {
       parser.printVersion(stdOut);
     } else {
       final Namespace namespace = parser.parseArgs(arguments);
       if (namespace.get("is-help") == null) {
         final Command command = commands.get(namespace.getString(COMMAND_NAME_ATTR));
         command.run(bootstrap, namespace);
       }
     }
     return true;
   } catch (ArgumentParserException e) {
     // TODO: 5/25/13 <coda> -- make ArgumentParser#handleError not depend on System.err
     stdErr.println(e.getMessage());
     e.getParser().printHelp(stdErr);
     return false;
   } catch (ConfigurationException e) {
     // TODO: 7/26/13 <ntelford> -- as above, this probably shouldn't depend on System.err
     stdErr.println(e.getMessage());
     return false;
   }
 }
 public LoggingConfig getLoggingConfig() {
   return new LoggingConfig(
       options.getInt(verboseArg.getDest()),
       options.getBoolean(syslogArg.getDest()),
       (File) options.get(logconfigArg.getDest()),
       options.getBoolean(noLogSetupArg.getDest()));
 }
示例#3
0
 Symbol getPrintChannel() {
   String name = options.get("print_channel");
   if (name == null) {
     return null;
   } else {
     return Symbol.of(name);
   }
 }
示例#4
0
  private static void loadEnvironment(String[] args) {
    final String defaultConfDir = getProperty("dash.application.conf.dir");
    final String defaultConfFile =
        (defaultConfDir != null ? defaultConfDir + File.separatorChar : "") + "conf.yml";

    ArgumentParser parser =
        ArgumentParsers.newArgumentParser("Dash", true)
            .description("Runs a performance test mix.")
            .version("${prog} " + Version.id())
            .epilog("Dash is a free software under Apache License Version 2.0");

    parser
        .addArgument("-c", "--conf")
        .help("the config file containing the test specification to run (default: ../conf/conf.yml")
        .required(false)
        .setDefault(new File(defaultConfFile))
        .type(File.class);

    parser
        .addArgument("-t", "--test")
        .help("the name of the test to run")
        .required(true)
        .type(String.class);

    parser
        .addArgument("-v", "--version")
        .help("print the version number")
        .action(Arguments.version());

    try {
      YamlEnv yamlEnv = new YamlEnv();
      Namespace namespace = parser.parseArgs(args);

      @SuppressWarnings("unchecked")
      HashMap<String, Object> env =
          (HashMap<String, Object>) yamlEnv.loadProperties((File) namespace.get("conf"));

      String test = namespace.getString("test");
      @SuppressWarnings("unchecked")
      HashMap<String, Object> testSpec = (HashMap<String, Object>) env.get(test);

      if (testSpec == null) {
        System.err.println("Test spec (" + test + ") does not exist in the config file.");
        throw new Error(); // todo: message or log or exit
      }

      for (Map.Entry<String, Object> entry : testSpec.entrySet()) {
        if (entry.getValue() != null) {
          System.setProperty(entry.getKey(), entry.getValue().toString());
        }
      }

    } catch (ArgumentParserException e) {
      parser.handleError(e);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
示例#5
0
  @Override
  @SuppressWarnings({"rawtypes", "unchecked"})
  public void execute() throws IOException, RecommenderBuildException {
    LenskitRecommenderEngine engine = loadEngine();

    long user = options.getLong("user");
    List<Long> items = options.get("items");

    LenskitRecommender rec = engine.createRecommender();
    RatingPredictor pred = rec.getRatingPredictor();
    if (pred == null) {
      logger.error("recommender has no rating predictor");
      throw new UnsupportedOperationException("no rating predictor");
    }

    logger.info("predicting {} items", items.size());
    Symbol pchan = getPrintChannel();
    Stopwatch timer = Stopwatch.createStarted();
    SparseVector preds = pred.predict(user, items);
    Long2ObjectMap channel = null;
    if (pchan != null) {
      for (TypedSymbol sym : preds.getChannelSymbols()) {
        if (sym.getRawSymbol().equals(pchan)) {
          channel = preds.getChannel(sym);
        }
      }
    }
    for (VectorEntry e : preds) {
      System.out.format("  %d: %.3f", e.getKey(), e.getValue());
      if (channel != null) {
        System.out.format(" (%s)", channel.get(e.getKey()));
      }
      System.out.println();
    }
    timer.stop();
    logger.info("predicted for {} items in {}", items.size(), timer);
  }
示例#6
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;
   }
 }
示例#7
0
 public File getOutputFile() {
   return options.get("output_file");
 }
示例#8
0
 public List<File> getConfigFiles() {
   return options.get("config");
 }
 public Path getServiceRegistrarPlugin() {
   final File plugin = options.get(serviceRegistrarPluginArg.getDest());
   return plugin != null ? plugin.toPath() : null;
 }