Search in sources :

Example 51 with Option

use of org.apache.commons.cli.Option in project ProPPR by TeamCohen.

the class GradientFinder method main.

public static void main(String[] args) {
    try {
        int inputFiles = Configuration.USE_GROUNDED | Configuration.USE_INIT_PARAMS;
        int outputFiles = Configuration.USE_GRADIENT | Configuration.USE_PARAMS;
        int modules = Configuration.USE_TRAINER | Configuration.USE_SRW | Configuration.USE_SQUASHFUNCTION;
        int constants = Configuration.USE_THREADS | Configuration.USE_EPOCHS | Configuration.USE_FORCE | Configuration.USE_FIXEDWEIGHTS;
        CustomConfiguration c = new CustomConfiguration(args, inputFiles, outputFiles, constants, modules) {

            boolean relax;

            @Override
            protected Option checkOption(Option o) {
                if (PARAMS_FILE_OPTION.equals(o.getLongOpt()) || INIT_PARAMS_FILE_OPTION.equals(o.getLongOpt()))
                    o.setRequired(false);
                return o;
            }

            @Override
            protected void addCustomOptions(Options options, int[] flags) {
                options.addOption(Option.builder().longOpt("relaxFW").desc("Relax fixedWeight rules for gradient computation (used in ProngHorn)").optionalArg(true).build());
            }

            @Override
            protected void retrieveCustomSettings(CommandLine line, int[] flags, Options options) {
                if (groundedFile == null || !groundedFile.exists())
                    usageOptions(options, flags, "Must specify grounded file using --" + Configuration.GROUNDED_FILE_OPTION);
                if (gradientFile == null)
                    usageOptions(options, flags, "Must specify gradient using --" + Configuration.GRADIENT_FILE_OPTION);
                // default to 0 epochs
                if (!options.hasOption("epochs"))
                    this.epochs = 0;
                this.relax = false;
                if (options.hasOption("relaxFW"))
                    this.relax = true;
            }

            @Override
            public Object getCustomSetting(String name) {
                if ("relaxFW".equals(name))
                    return this.relax;
                return null;
            }
        };
        System.out.println(c.toString());
        ParamVector<String, ?> params = null;
        SymbolTable<String> masterFeatures = new SimpleSymbolTable<String>();
        File featureIndex = new File(c.groundedFile.getParent(), c.groundedFile.getName() + Grounder.FEATURE_INDEX_EXTENSION);
        if (featureIndex.exists()) {
            log.info("Reading feature index from " + featureIndex.getName() + "...");
            for (String line : new ParsedFile(featureIndex)) {
                masterFeatures.insert(line.trim());
            }
        }
        if (c.epochs > 0) {
            // train first
            log.info("Training for " + c.epochs + " epochs...");
            params = c.trainer.train(masterFeatures, new ParsedFile(c.groundedFile), new ArrayLearningGraphBuilder(), // create a parameter vector
            c.initParamsFile, c.epochs);
            if (c.paramsFile != null)
                ParamsFile.save(params, c.paramsFile, c);
        } else if (c.initParamsFile != null) {
            params = new SimpleParamVector<String>(Dictionary.load(new ParsedFile(c.initParamsFile)));
        } else if (c.paramsFile != null) {
            params = new SimpleParamVector<String>(Dictionary.load(new ParsedFile(c.paramsFile)));
        } else {
            params = new SimpleParamVector<String>();
        }
        // this lets prongHorn hold external features fixed for training, but still compute their gradient
        if (((Boolean) c.getCustomSetting("relaxFW"))) {
            log.info("Turning off fixedWeight rules");
            c.trainer.setFixedWeightRules(new FixedWeightRules());
        }
        ParamVector<String, ?> batchGradient = c.trainer.findGradient(masterFeatures, new ParsedFile(c.groundedFile), new ArrayLearningGraphBuilder(), params);
        ParamsFile.save(batchGradient, c.gradientFile, c);
    } catch (Throwable t) {
        t.printStackTrace();
        System.exit(-1);
    }
}
Also used : Options(org.apache.commons.cli.Options) CustomConfiguration(edu.cmu.ml.proppr.util.CustomConfiguration) SimpleParamVector(edu.cmu.ml.proppr.util.math.SimpleParamVector) CommandLine(org.apache.commons.cli.CommandLine) SimpleSymbolTable(edu.cmu.ml.proppr.util.SimpleSymbolTable) FixedWeightRules(edu.cmu.ml.proppr.learn.tools.FixedWeightRules) Option(org.apache.commons.cli.Option) ParsedFile(edu.cmu.ml.proppr.util.ParsedFile) File(java.io.File) ParamsFile(edu.cmu.ml.proppr.util.ParamsFile) ParsedFile(edu.cmu.ml.proppr.util.ParsedFile) ArrayLearningGraphBuilder(edu.cmu.ml.proppr.graph.ArrayLearningGraphBuilder)

Example 52 with Option

use of org.apache.commons.cli.Option in project zm-mailbox by Zimbra.

the class LocalConfigUpgrade method getAllOptions.

private static Options getAllOptions() {
    Options options = new Options();
    options.addOption(O_HELP, "help", false, "print usage");
    options.addOption(O_CONFIG, "config", true, "path to localconfig.xml");
    options.addOption(O_TAG, "tag", true, "backup and tag with this suffix");
    Option bugOpt = new Option(O_BUG, "bug", true, "bug number this upgrade is for (multiple allowed)");
    bugOpt.setArgs(Option.UNLIMITED_VALUES);
    options.addOption(bugOpt);
    return options;
}
Also used : Options(org.apache.commons.cli.Options) Option(org.apache.commons.cli.Option)

Example 53 with Option

use of org.apache.commons.cli.Option in project zm-mailbox by Zimbra.

the class ChartUtil method getOptions.

private static Options getOptions() {
    Options opts = new Options();
    opts.addOption("h", OPT_HELP, false, "prints this usage screen");
    Option confOption = new Option("c", OPT_CONF, true, "chart configuration xml files");
    confOption.setArgs(Option.UNLIMITED_VALUES);
    confOption.setRequired(true);
    opts.addOption(confOption);
    Option srcDirOption = new Option("s", OPT_SRCDIR, true, "one or more directories where the csv files are located");
    srcDirOption.setArgs(Option.UNLIMITED_VALUES);
    opts.addOption(srcDirOption);
    Option destDirOption = new Option("d", OPT_DESTDIR, true, "directory where the generated chart files are saved");
    opts.addOption(destDirOption);
    opts.addOption(null, OPT_TITLE, true, "chart title; defaults to last directory name of --" + OPT_SRCDIR + " value");
    opts.addOption(null, OPT_START_AT, true, "if specified, ignore all samples before this timestamp (MM/dd/yyyy HH:mm:ss)");
    opts.addOption(null, OPT_END_AT, true, "if specified, ignore all samples after this timestamp (MM/dd/yyyy HH:mm:ss)");
    opts.addOption(null, OPT_AGGREGATE_START_AT, true, "if specified, aggregate computation starts at this timestamp (MM/dd/yyyy HH:mm:ss)");
    opts.addOption(null, OPT_AGGREGATE_END_AT, true, "if specified, aggregate computation ends at this timestamp (MM/dd/yyyy HH:mm:ss)");
    opts.addOption(null, OPT_NO_SUMMARY, false, "skip summary data generation");
    return opts;
}
Also used : Options(org.apache.commons.cli.Options) Option(org.apache.commons.cli.Option)

Example 54 with Option

use of org.apache.commons.cli.Option in project zm-mailbox by Zimbra.

the class SoapApiChangeLog method main.

/**
     * Main
     */
public static void main(String[] args) throws Exception {
    CommandLineParser parser = new PosixParser();
    Options options = new Options();
    Option opt;
    opt = new Option("d", ARG_OUTPUT_DIR, true, "Output directory for changelog information");
    opt.setRequired(true);
    options.addOption(opt);
    opt = new Option("t", ARG_TEMPLATES_DIR, true, "Directory containing Freemarker templates");
    opt.setRequired(true);
    options.addOption(opt);
    opt = new Option("b", ARG_APIDESC_BASELINE_JSON, true, "JSON file - description of baseline SOAP API");
    opt.setRequired(true);
    options.addOption(opt);
    opt = new Option("c", ARG_APIDESC_CURRENT_JSON, true, "JSON file - description of current SOAP API");
    opt.setRequired(true);
    options.addOption(opt);
    CommandLine cl = null;
    try {
        cl = parser.parse(options, args, true);
    } catch (ParseException pe) {
        System.err.println("error: " + pe.getMessage());
        System.exit(2);
    }
    String baselineApiDescriptionJson = cl.getOptionValue('b');
    String currentApiDescriptionJson = cl.getOptionValue('c');
    SoapApiChangeLog clog = new SoapApiChangeLog(cl.getOptionValue('d'), cl.getOptionValue('t'));
    clog.setBaselineDesc(SoapApiDescription.deserializeFromJson(new File(baselineApiDescriptionJson)));
    clog.setCurrentDesc(SoapApiDescription.deserializeFromJson(new File(currentApiDescriptionJson)));
    clog.makeChangeLogDataModel();
    clog.writeChangelog();
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) JsonParseException(org.codehaus.jackson.JsonParseException) ParseException(org.apache.commons.cli.ParseException) File(java.io.File)

Example 55 with Option

use of org.apache.commons.cli.Option in project alluxio by Alluxio.

the class AlluxioFuse method parseOptions.

/**
   * Parses CLI options.
   *
   * @param args CLI args
   * @return Alluxio-FUSE configuration options
   */
private static AlluxioFuseOptions parseOptions(String[] args) {
    final Options opts = new Options();
    final Option mntPoint = Option.builder("m").hasArg().required(false).longOpt("mount-point").desc("Desired local mount point for alluxio-fuse.").build();
    final Option alluxioRoot = Option.builder("r").hasArg().required(false).longOpt("alluxio-root").desc("Path within alluxio that will be used as the root of the FUSE mount " + "(e.g., /users/foo; defaults to /)").build();
    final Option help = Option.builder("h").required(false).desc("Print this help").build();
    final Option fuseOption = Option.builder("o").valueSeparator(',').required(false).hasArgs().desc("FUSE mount options").build();
    opts.addOption(mntPoint);
    opts.addOption(alluxioRoot);
    opts.addOption(help);
    opts.addOption(fuseOption);
    final CommandLineParser parser = new DefaultParser();
    try {
        CommandLine cli = parser.parse(opts, args);
        if (cli.hasOption("h")) {
            final HelpFormatter fmt = new HelpFormatter();
            fmt.printHelp(AlluxioFuse.class.getName(), opts);
            return null;
        }
        String mntPointValue = cli.getOptionValue("m");
        String alluxioRootValue = cli.getOptionValue("r");
        List<String> fuseOpts = new ArrayList<>();
        boolean noUserMaxWrite = true;
        if (cli.hasOption("o")) {
            String[] fopts = cli.getOptionValues("o");
            // keep the -o
            for (final String fopt : fopts) {
                fuseOpts.add("-o" + fopt);
                if (noUserMaxWrite && fopt.startsWith("max_write")) {
                    noUserMaxWrite = false;
                }
            }
        }
        // from conf
        if (noUserMaxWrite) {
            final long maxWrite = Configuration.getLong(PropertyKey.FUSE_MAXWRITE_BYTES);
            fuseOpts.add(String.format("-omax_write=%d", maxWrite));
        }
        if (mntPointValue == null) {
            mntPointValue = Configuration.get(PropertyKey.FUSE_MOUNT_DEFAULT);
            LOG.info("Mounting on default {}", mntPointValue);
        }
        if (alluxioRootValue == null) {
            alluxioRootValue = Configuration.get(PropertyKey.FUSE_FS_ROOT);
            LOG.info("Using default alluxio root {}", alluxioRootValue);
        }
        final boolean fuseDebug = Configuration.getBoolean(PropertyKey.FUSE_DEBUG_ENABLED);
        return new AlluxioFuseOptions(mntPointValue, alluxioRootValue, fuseDebug, fuseOpts);
    } catch (ParseException e) {
        System.err.println("Error while parsing CLI: " + e.getMessage());
        final HelpFormatter fmt = new HelpFormatter();
        fmt.printHelp(AlluxioFuse.class.getName(), opts);
        return null;
    }
}
Also used : Options(org.apache.commons.cli.Options) ArrayList(java.util.ArrayList) HelpFormatter(org.apache.commons.cli.HelpFormatter) CommandLine(org.apache.commons.cli.CommandLine) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) DefaultParser(org.apache.commons.cli.DefaultParser)

Aggregations

Option (org.apache.commons.cli.Option)152 Options (org.apache.commons.cli.Options)105 CommandLine (org.apache.commons.cli.CommandLine)53 CommandLineParser (org.apache.commons.cli.CommandLineParser)52 ParseException (org.apache.commons.cli.ParseException)41 GnuParser (org.apache.commons.cli.GnuParser)39 HelpFormatter (org.apache.commons.cli.HelpFormatter)30 File (java.io.File)13 OptionGroup (org.apache.commons.cli.OptionGroup)13 FileInputStream (java.io.FileInputStream)10 IOException (java.io.IOException)10 HashMap (java.util.HashMap)9 DefaultParser (org.apache.commons.cli.DefaultParser)9 Properties (java.util.Properties)8 BasicParser (org.apache.commons.cli.BasicParser)6 ConsoleAppender (org.apache.log4j.ConsoleAppender)6 PatternLayout (org.apache.log4j.PatternLayout)6 ArrayList (java.util.ArrayList)5 PosixParser (org.apache.commons.cli.PosixParser)5 List (java.util.List)3