Example usage for org.apache.commons.cli Options addOption

List of usage examples for org.apache.commons.cli Options addOption

Introduction

In this page you can find the example usage for org.apache.commons.cli Options addOption.

Prototype

public Options addOption(Option opt) 

Source Link

Document

Adds an option instance

Usage

From source file:com.ligadata.EncryptUtils.GenerateKeys.java

public static void main(String[] args) {
    CommandLine commandLine;//  ww w . j  a  v  a  2  s . c  om
    if (args.length == 0) {
        PrintUsage();
        System.exit(-1);
    }

    Option o_help = new Option("help", "The help option");
    Option o_generateSampleKeys = new Option("generateSampleKeys", "a flag to generate sample keys");
    Option o_algorithm = OptionBuilder.withArgName("algorithm").hasArg()
            .withDescription("The encryption algorithm").create("algorithm");
    Option o_password = OptionBuilder.withArgName("password").hasArg().withDescription("ascii password")
            .create("password");
    Option o_publicKeyFile = OptionBuilder.withArgName("publicKeyFile").hasArg()
            .withDescription("File containing public key").create("publicKeyFile");
    Option o_privateKeyFile = OptionBuilder.withArgName("privateKeyFile").hasArg()
            .withDescription("File containing private key").create("privateKeyFile");
    Options options = new Options();
    CommandLineParser parser = new GnuParser();

    options.addOption(o_help);
    options.addOption(o_generateSampleKeys);
    options.addOption(o_algorithm);
    options.addOption(o_password);
    options.addOption(o_publicKeyFile);
    options.addOption(o_privateKeyFile);

    try {
        commandLine = parser.parse(options, args);
        if (commandLine.hasOption("algorithm")) {
            logger.info("Option algorithm is present.  The value is: ");
            algorithm = commandLine.getOptionValue("algorithm");
            logger.info(algorithm);
        }
        if (commandLine.hasOption("password")) {
            logger.info("Option password is present.  The value is: ");
            password = commandLine.getOptionValue("password");
            logger.info(password);
        }
        if (commandLine.hasOption("publicKeyFile")) {
            logger.info("Option publicKeyFile is present.  The value is: ");
            publicKeyFile = commandLine.getOptionValue("publicKeyFile");
            logger.info(publicKeyFile);
        }
        if (commandLine.hasOption("privateKeyFile")) {
            logger.info("Option privateKeyFile is present.  The value is: ");
            privateKeyFile = commandLine.getOptionValue("privateKeyFile");
            logger.info(privateKeyFile);

        }
        if (commandLine.hasOption("help")) {
            logger.info("Option help is present.  This is a flag option.");
            help = true;
        }
        if (commandLine.hasOption("generateSampleKeys")) {
            logger.info("Option generateSampleKeys is present.  This is a flag option.");
            generateSampleKeys = true;
        }
        String[] remainder = commandLine.getArgs();
        for (String argument : remainder) {
            logger.info(argument);
            logger.info(" ");
        }
        int rc = generateKeys();
        System.exit(rc);
    } catch (ParseException exception) {
        System.out.print("Parse error: ");
        System.out.println(exception.getMessage());
        System.exit(-2);
    }
}

From source file:edu.uiowa.javatm.JavaTM.java

/**
 * @param args First one indicates which topic model to use
 *///from  w w  w. j av  a  2s .c  om
public static void main(String[] args) {
    TMGibbsSampler tmGibbsSampler = null;

    Option modelType = Option.builder("model").longOpt("model-type").desc("Type of topic models to use")
            .hasArg().required().build();

    Option dataName = Option.builder("name").longOpt("data-name").desc("Data name: used for saving outputs")
            .hasArg().required().build();

    Option alpha = Option.builder("a").longOpt("alpha")
            .desc("Dirichlet prior for document (author) over topic multinomial").hasArg().required().build();

    Option beta = Option.builder("b").longOpt("beta").desc("Dirichlet prior for topic over word multinomial")
            .hasArg().required().build();

    Option pi = Option.builder("p").longOpt("pi").desc("Dirichlet prior for topic over time multinomial")
            .hasArg().build();

    Option K = Option.builder("K").longOpt("K").desc("The number of timestamp indices").hasArg().build();

    /*Option tau = Option.builder("tau").longOpt("tau")
    .desc("Smoothing constant for topic time")
    .hasArg().build();*/

    Option doc = Option.builder("doc").longOpt("document-file").desc("WD matrix to use").hasArg().required()
            .build();

    Option voc = Option.builder("voc").longOpt("vocabulary-file")
            .desc("Vocabulary file of the corpus of interest").hasArg().required().build();

    Option auth = Option.builder("auth").longOpt("auth-file").desc("Author indices for each token").hasArg()
            .build();

    Option authArray = Option.builder("authArray").longOpt("author-list-file").desc("Author list").hasArg()
            .build();

    Option dkArray = Option.builder("dk").longOpt("document-time-file").desc("Document timestamp file").hasArg()
            .build();

    Option citationMat = Option.builder("cm").longOpt("citation-matrix")
            .desc("Citation overtime for the corpus").hasArg().build();

    Option numTopics = Option.builder("topic").longOpt("num-topics").desc("The total number of topics").hasArg()
            .required().build();

    Option numIters = Option.builder("iter").longOpt("num-iters").desc("The total number of iterations")
            .hasArg().required().build();

    Option outputDir = Option.builder("odir").longOpt("output-dir").desc("Output directory").hasArg().required()
            .build();

    Options options = new Options();
    options.addOption(modelType).addOption(alpha).addOption(beta).addOption(numTopics).addOption(K)
            .addOption(pi).addOption(citationMat).addOption(numIters).addOption(doc).addOption(voc)
            .addOption(dkArray).addOption(outputDir).addOption(auth).addOption(authArray).addOption(dataName);

    CommandLineParser parser = new DefaultParser();
    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);
        String model = line.getOptionValue("model");
        String name = line.getOptionValue("name");
        String docFile = line.getOptionValue("doc");
        String vocFile = line.getOptionValue("voc");
        int topics = Integer.parseInt(line.getOptionValue("topic"));
        int iters = Integer.parseInt(line.getOptionValue("iter"));
        double a = Double.parseDouble(line.getOptionValue("a"));
        double b = Double.parseDouble(line.getOptionValue("b"));

        String modelLower = model.toLowerCase();
        if (modelLower.equals("lda")) {
            tmGibbsSampler = new LDAGibbsSampler(topics, iters, a, b, docFile, vocFile);
        } else if (modelLower.equals("at")) {
            String authFile = line.getOptionValue("auth");
            String authArrayFile = line.getOptionValue("authArray");
            //double tau_val = Double.parseDouble(line.getOptionValue("tau"));
            tmGibbsSampler = new ATGibbsSampler(topics, iters, a, b, docFile, vocFile, authFile, authArrayFile);
        } else if (modelLower.equals("tot")) {
            String dkFile = line.getOptionValue("dk");
            //double tau_val = Double.parseDouble(line.getOptionValue("tau"));
            tmGibbsSampler = new ToTGibbsSampler(topics, iters, a, b, docFile, vocFile, dkFile);
        } else if (modelLower.equals("tiot")) {
            String timeFile = line.getOptionValue("dk");
            String citationFile = line.getOptionValue("cm");
            double p = Double.parseDouble(line.getOptionValue("p"));
            //int k = Integer.parseInt(line.getOptionValue("K"));
            tmGibbsSampler = new TIOTGibbsSampler(topics, iters, a, b, p, docFile, vocFile, timeFile,
                    citationFile);
        } else {
            System.err.println("Invalid model type selection. Must be lda, at, tot or atot.");
            System.exit(ExitStatus.ILLEGAL_ARGUMENT);
        }

        long startTime = System.nanoTime();
        tmGibbsSampler.fit();
        TMOutcome outcome = tmGibbsSampler.get_outcome();
        long endTime = System.nanoTime();
        long duration = (endTime - startTime);
        System.out.println("Overall elapsed time: " + duration / 1000000000. + " seconds");

        tmGibbsSampler.showTopics(10);
        outcome.showTopicDistribution();

        String oDir = line.getOptionValue("odir");
        if (!oDir.endsWith("/")) {
            oDir = oDir + "/";
        }
        // append name to `oDir`
        oDir = oDir + name + "-";

        if (modelLower.contains("tot")) {
            // topic over time (tot and atot) has beta distribution parameters to write
            Utils.write2DArray(((ToTOutcome) outcome).getPsi(), oDir + "psi-" + modelLower + ".csv");
        }

        if (modelLower.contains("tiot")) {
            // topic over time (tot and atot) has beta distribution parameters to write
            Utils.write2DArray(((TIOTOutcome) outcome).getPsi(), oDir + "psi-" + modelLower + ".csv");
            double[][][] ga = ((TIOTOutcome) outcome).getGa();
            for (int t = 0; t < ga.length; t++) {
                Utils.write2DArray(ga[t], oDir + "gamma-" + t + "-" + modelLower + ".csv");
            }
        }

        Utils.write2DArray(outcome.getPhi(), oDir + "phi-" + modelLower + ".csv");
        Utils.write2DArray(outcome.getTheta(), oDir + "theta-" + modelLower + ".csv");

        System.out.println("Output files saved to " + oDir);
    } catch (ParseException exp) {
        // oops, something went wrong
        System.err.println("Parsing failed. Reason: " + exp.getMessage());
    }

}

From source file:br.com.riselabs.cotonet.Main.java

/**
 * @param args//w  w w .jav a2s  .  c o m
 * @throws EmptyContentException
 * @throws IOException
 * @throws NullPointerException
 * @throws InvalidNumberOfTagsException
 */
public static void main(String[] args) {

    CommandLineParser parser = new DefaultParser();
    Options options = new Options();

    options.addOption(Option.builder("c").longOpt("chunkBased").desc(
            "c - build a conflict chunk-based network with the developers that in fact conflits with each other."
                    + " Additionally to the c argument the user should provide a path. This path should have"
                    + " a file containig the repository's URL of the target systems.")
            .hasArg().build());

    options.addOption(Option.builder("cf").longOpt("chunkBasedFullGraph")
            .desc("cf - like c, build a conflict chunk-based network adding all developers involved in "
                    + "identified chunk conflicts. Additionally to the cf argument the user should provide a path. "
                    + "This path should have a file containig the repository's URL of the target systems.")
            .hasArg().build());

    options.addOption(Option.builder("f").longOpt("fileBase").desc(
            " f - build a conflict file-based network. In other others all developers that contribute to some"
                    + " conflict at file level should be part of this network. This network is based on network provides "
                    + "by cf, adding edges between developers of different chunks. Additionally to the f argument the"
                    + " user should provide a path. This path should have afile containig the repository's URL of "
                    + "the target systems.")
            .hasArg().build());
    /*
     * options.addOption( Option.builder("rw").longOpt("rewrite-aux").
     * desc("Rewrite auxilary files (e.g., *.conf, *.sh) " + "_WITHOUT_ " +
     * "the recreation of the merge scenarios based tags.").hasArg(false).
     * build());
     * 
     * options.addOption( Option.builder("rwt").longOpt("rewrite-tagfile").
     * desc("Rewrite auxilary files (e.g., *.conf, *.sh) " + "_INCLUDING_ "
     * + "the recreation of the merge scenarios based tags.").hasArg(false).
     * build());
     */
    options.addOption("h", "help", false, "Print this help page");

    File reposListFile = null;
    Boolean skipCloneAndNetworks = false;
    try {
        CommandLine cmd = parser.parse(options, args);
        // user is looking for help
        if (cmd.hasOption("h")) {
            new HelpFormatter().printHelp("java ", options);
            System.exit(0);
        }

        /* "c", "cf", and "f" are the three available options
        * "c" builds the chunk-based network with developers that contribute to the conflict
        * "cf" builds the chunk-based network with developers that contribute to the conflict and developers
        * that are part of the chunk, but don't contribute to the conflict
        * "f" builds the file-based network with developers that contribute to the chunk into a target file
        */
        else if (cmd.hasOption("c") || cmd.hasOption("cf") || cmd.hasOption("f")) {

            String urlsFilePath = null;
            NetworkType type;
            if (cmd.hasOption("c")) {
                urlsFilePath = cmd.getOptionValue("c");
                type = NetworkType.CHUNK_BASED;
            } else if (cmd.hasOption("cf")) {
                urlsFilePath = cmd.getOptionValue("cf");
                type = NetworkType.CHUNK_BASED_FULL;
            } else {
                urlsFilePath = cmd.getOptionValue("f");
                type = NetworkType.FILE_BASED;
            }

            System.out.println(urlsFilePath);

            reposListFile = new File(urlsFilePath);

            // Ends execution if file not found.
            if (!reposListFile.exists()) {
                System.out.println("COTONET ended without retrive any repository.\n\n"
                        + "The file containig the repository's URL of the target systems was not found. "
                        + "Check wether the file \"" + urlsFilePath + "\" exists.");
                System.exit(1);
            }

            skipCloneAndNetworks = (cmd.hasOption("rw") || cmd.hasOption("rwt")) ? true : false;

            MainThread m = new MainThread(type, reposListFile, skipCloneAndNetworks);
            m.start();
            m.join();
            Logger.log("COTONET finished. Files rewritten.");

        } else {
            System.out.println("COTONET ended without retrive any repository.\n\n"
                    + "You should use 'h' if you are looking for help. Otherwise,"
                    + " the 'l' or 'fc' option is mandatory.");
            System.exit(1);

        }

    } catch (ParseException e) {
        new HelpFormatter().printHelp("java ", options);
    } catch (Exception e) {
        Logger.log(e.getMessage());
    }
}

From source file:com.aestel.chemistry.openEye.fp.apps.SDFFPSphereExclusion.java

public static void main(String... args) throws IOException { // create command line Options object
    Options options = new Options();
    Option opt = new Option("in", true, "input file [.sdf,...]");
    opt.setRequired(true);//from  www. j a  v  a2 s .com
    options.addOption(opt);

    opt = new Option("out", true, "output file oe-supported");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("ref", true, "refrence file to be loaded before starting");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("fpTag", true, "field containing fingerpPrint");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("maxTanimoto", false,
            "If given the modified maxTanimoto will be used = common/(2*Max(na,nb)-common).");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("radius", true, "radius of exclusion sphere, exclude anything with similarity >= radius.");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("printSphereMatchCount", false,
            "check and print membership of candidates not "
                    + " only to the first centroid which has sim >= radius but to all centroids"
                    + " found up to that input. This will output a candidate multiple times."
                    + " Implies checkSpheresInOrder.");
    options.addOption(opt);

    opt = new Option("checkSpheresInOrder", false,
            "For each candiate: compare to centroids from first to last (default is last to first)");
    options.addOption(opt);

    opt = new Option("printAll", false, "print all molecule, check includeIdx tag");
    options.addOption(opt);

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        System.err.println(e.getMessage());
        exitWithHelp(options);
    }
    args = cmd.getArgs();

    if (cmd.hasOption("d")) {
        System.err.println("Start debugger and press return:");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    }

    // the only reason not to match centroids in reverse order id if
    // a non-centroid is to be assigned to multiple centroids
    boolean printSphereMatchCount = cmd.hasOption("printSphereMatchCount");
    boolean reverseMatch = !cmd.hasOption("checkSpheresInOrder") && !printSphereMatchCount;
    boolean printAll = cmd.hasOption("printAll") || printSphereMatchCount;
    boolean doMaxTanimoto = cmd.hasOption("maxTanimoto");
    String fpTag = cmd.getOptionValue("fpTag");
    double radius = Double.parseDouble(cmd.getOptionValue("radius"));
    String inFile = cmd.getOptionValue("in");
    String outFile = cmd.getOptionValue("out");
    String refFile = cmd.getOptionValue("ref");

    SimComparatorFactory<OEMolBase, FPComparator, FPComparator> compFact = new FPComparatorFact(doMaxTanimoto,
            fpTag);
    SphereExclusion<FPComparator, FPComparator> alg = new SphereExclusion<FPComparator, FPComparator>(compFact,
            refFile, outFile, radius, reverseMatch, printSphereMatchCount, printAll);
    alg.run(inFile);
    alg.close();
}

From source file:com.hortonworks.registries.storage.tool.sql.TablesInitializer.java

public static void main(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(Option.builder("s").numberOfArgs(1).longOpt(OPTION_SCRIPT_ROOT_PATH)
            .desc("Root directory of script path").build());

    options.addOption(Option.builder("c").numberOfArgs(1).longOpt(OPTION_CONFIG_FILE_PATH)
            .desc("Config file path").build());

    options.addOption(Option.builder("m").numberOfArgs(1).longOpt(OPTION_MYSQL_JAR_URL_PATH)
            .desc("Mysql client jar url to download").build());

    options.addOption(Option.builder().hasArg(false).longOpt(SchemaMigrationOption.CREATE.toString())
            .desc("Run sql migrations from scatch").build());

    options.addOption(Option.builder().hasArg(false).longOpt(SchemaMigrationOption.DROP.toString())
            .desc("Drop all the tables in the target database").build());

    options.addOption(Option.builder().hasArg(false).longOpt(SchemaMigrationOption.CHECK_CONNECTION.toString())
            .desc("Check the connection for configured data source").build());

    options.addOption(Option.builder().hasArg(false).longOpt(SchemaMigrationOption.MIGRATE.toString())
            .desc("Execute schema migration from last check point").build());

    options.addOption(Option.builder().hasArg(false).longOpt(SchemaMigrationOption.INFO.toString())
            .desc("Show the status of the schema migration compared to the target database").build());

    options.addOption(Option.builder().hasArg(false).longOpt(SchemaMigrationOption.VALIDATE.toString())
            .desc("Validate the target database changes with the migration scripts").build());

    options.addOption(Option.builder().hasArg(false).longOpt(SchemaMigrationOption.REPAIR.toString()).desc(
            "Repairs the DATABASE_CHANGE_LOG by removing failed migrations and correcting checksum of existing migration script")
            .build());//from w ww .j  a v a  2 s .  com

    options.addOption(Option.builder().hasArg(false).longOpt(DISABLE_VALIDATE_ON_MIGRATE)
            .desc("Disable flyway validation checks while running migrate").build());

    CommandLineParser parser = new BasicParser();
    CommandLine commandLine = parser.parse(options, args);

    if (!commandLine.hasOption(OPTION_CONFIG_FILE_PATH) || !commandLine.hasOption(OPTION_SCRIPT_ROOT_PATH)) {
        usage(options);
        System.exit(1);
    }

    boolean isSchemaMigrationOptionSpecified = false;
    SchemaMigrationOption schemaMigrationOptionSpecified = null;
    for (SchemaMigrationOption schemaMigrationOption : SchemaMigrationOption.values()) {
        if (commandLine.hasOption(schemaMigrationOption.toString())) {
            if (isSchemaMigrationOptionSpecified) {
                System.out.println(
                        "Only one operation can be execute at once, please select one of 'create', ',migrate', 'validate', 'info', 'drop', 'repair', 'check-connection'.");
                System.exit(1);
            }
            isSchemaMigrationOptionSpecified = true;
            schemaMigrationOptionSpecified = schemaMigrationOption;
        }
    }

    if (!isSchemaMigrationOptionSpecified) {
        System.out.println(
                "One of the option 'create', ',migrate', 'validate', 'info', 'drop', 'repair', 'check-connection' must be specified to execute.");
        System.exit(1);
    }

    String confFilePath = commandLine.getOptionValue(OPTION_CONFIG_FILE_PATH);
    String scriptRootPath = commandLine.getOptionValue(OPTION_SCRIPT_ROOT_PATH);
    String mysqlJarUrl = commandLine.getOptionValue(OPTION_MYSQL_JAR_URL_PATH);

    StorageProviderConfiguration storageProperties;
    Map<String, Object> conf;
    try {
        conf = Utils.readConfig(confFilePath);

        StorageProviderConfigurationReader confReader = new StorageProviderConfigurationReader();
        storageProperties = confReader.readStorageConfig(conf);
    } catch (IOException e) {
        System.err.println("Error occurred while reading config file: " + confFilePath);
        System.exit(1);
        throw new IllegalStateException("Shouldn't reach here");
    }

    String bootstrapDirPath = null;
    try {
        bootstrapDirPath = System.getProperty("bootstrap.dir");
        Proxy proxy = Proxy.NO_PROXY;
        String httpProxyUrl = (String) conf.get(HTTP_PROXY_URL);
        String httpProxyUsername = (String) conf.get(HTTP_PROXY_USERNAME);
        String httpProxyPassword = (String) conf.get(HTTP_PROXY_PASSWORD);
        if ((httpProxyUrl != null) && !httpProxyUrl.isEmpty()) {
            URL url = new URL(httpProxyUrl);
            proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(url.getHost(), url.getPort()));
            if ((httpProxyUsername != null) && !httpProxyUsername.isEmpty()) {
                Authenticator.setDefault(getBasicAuthenticator(url.getHost(), url.getPort(), httpProxyUsername,
                        httpProxyPassword));
            }
        }
        MySqlDriverHelper.downloadMySQLJarIfNeeded(storageProperties, bootstrapDirPath, mysqlJarUrl, proxy);
    } catch (Exception e) {
        System.err.println("Error occurred while downloading MySQL jar. bootstrap dir: " + bootstrapDirPath);
        System.exit(1);
        throw new IllegalStateException("Shouldn't reach here");
    }

    boolean disableValidateOnMigrate = commandLine.hasOption(DISABLE_VALIDATE_ON_MIGRATE);
    if (disableValidateOnMigrate) {
        System.out.println("Disabling validation on schema migrate");
    }
    SchemaMigrationHelper schemaMigrationHelper = new SchemaMigrationHelper(
            SchemaFlywayFactory.get(storageProperties, scriptRootPath, !disableValidateOnMigrate));
    try {
        schemaMigrationHelper.execute(schemaMigrationOptionSpecified);
        System.out
                .println(String.format("\"%s\" option successful", schemaMigrationOptionSpecified.toString()));
    } catch (Exception e) {
        System.err.println(
                String.format("\"%s\" option failed : %s", schemaMigrationOptionSpecified.toString(), e));
        System.exit(1);
    }

}

From source file:com.genentech.struchk.OEMDLPercieveChecker.java

public static void main(String[] args) throws ParseException, JDOMException, IOException {
    // create command line Options object
    Options options = new Options();
    Option opt = new Option("i", true, "input file [.ism,.sdf,...]");
    opt.setRequired(true);/*from  w w w  .  ja  v a  2 s  .  c  o m*/
    options.addOption(opt);

    opt = new Option("o", true, "output file");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("d", false, "debug: wait for user to press key at startup.");
    opt.setRequired(false);
    options.addOption(opt);

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        System.err.println(e.getMessage());
        exitWithHelp(options);
    }
    args = cmd.getArgs();

    if (cmd.hasOption("d")) {
        System.err.println("Start debugger and press return:");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    }

    if (args.length != 0) {
        exitWithHelp(options);
    }

    String inFile = cmd.getOptionValue("i");
    String outFile = cmd.getOptionValue("o");

    OEMDLPercieveChecker checker = null;
    try {
        checker = new OEMDLPercieveChecker();

        oemolostream out = new oemolostream(outFile);
        oemolistream in = new oemolistream(inFile);

        OEGraphMol mol = new OEGraphMol();
        while (oechem.OEReadMolecule(in, mol)) {
            if (!checker.checkMol(mol))
                oechem.OEWriteMolecule(out, mol);
        }
        checker.delete();
        in.close();
        in.delete();

        out.close();
        out.delete();

    } catch (Exception e) {
        throw new Error(e);
    }
    System.err.println("Done:");
}

From source file:cc.wikitools.lucene.IndexWikipediaDump.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("bz2 Wikipedia XML dump file")
            .create(INPUT_OPTION));// ww  w.  java2s  .  c  o m
    options.addOption(
            OptionBuilder.withArgName("dir").hasArg().withDescription("index location").create(INDEX_OPTION));
    options.addOption(OptionBuilder.withArgName("num").hasArg()
            .withDescription("maximum number of documents to index").create(MAX_OPTION));
    options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of indexing threads")
            .create(THREADS_OPTION));

    options.addOption(new Option(OPTIMIZE_OPTION, "merge indexes into a single segment"));

    CommandLine cmdline = null;
    CommandLineParser parser = new GnuParser();
    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        System.exit(-1);
    }

    if (!cmdline.hasOption(INPUT_OPTION) || !cmdline.hasOption(INDEX_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(IndexWikipediaDump.class.getCanonicalName(), options);
        System.exit(-1);
    }

    String indexPath = cmdline.getOptionValue(INDEX_OPTION);
    int maxdocs = cmdline.hasOption(MAX_OPTION) ? Integer.parseInt(cmdline.getOptionValue(MAX_OPTION))
            : Integer.MAX_VALUE;
    int threads = cmdline.hasOption(THREADS_OPTION) ? Integer.parseInt(cmdline.getOptionValue(THREADS_OPTION))
            : DEFAULT_NUM_THREADS;

    long startTime = System.currentTimeMillis();

    String path = cmdline.getOptionValue(INPUT_OPTION);
    PrintStream out = new PrintStream(System.out, true, "UTF-8");
    WikiClean cleaner = new WikiCleanBuilder().withTitle(true).build();

    Directory dir = FSDirectory.open(new File(indexPath));
    IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_43, ANALYZER);
    config.setOpenMode(OpenMode.CREATE);

    IndexWriter writer = new IndexWriter(dir, config);
    LOG.info("Creating index at " + indexPath);
    LOG.info("Indexing with " + threads + " threads");

    try {
        WikipediaBz2DumpInputStream stream = new WikipediaBz2DumpInputStream(path);

        ExecutorService executor = Executors.newFixedThreadPool(threads);
        int cnt = 0;
        String page;
        while ((page = stream.readNext()) != null) {
            String title = cleaner.getTitle(page);

            // These are heuristic specifically for filtering out non-articles in enwiki-20120104.
            if (title.startsWith("Wikipedia:") || title.startsWith("Portal:") || title.startsWith("File:")) {
                continue;
            }

            if (page.contains("#REDIRECT") || page.contains("#redirect") || page.contains("#Redirect")) {
                continue;
            }

            Runnable worker = new AddDocumentRunnable(writer, cleaner, page);
            executor.execute(worker);

            cnt++;
            if (cnt % 10000 == 0) {
                LOG.info(cnt + " articles added");
            }
            if (cnt >= maxdocs) {
                break;
            }
        }

        executor.shutdown();
        // Wait until all threads are finish
        while (!executor.isTerminated()) {
        }

        LOG.info("Total of " + cnt + " articles indexed.");

        if (cmdline.hasOption(OPTIMIZE_OPTION)) {
            LOG.info("Merging segments...");
            writer.forceMerge(1);
            LOG.info("Done!");
        }

        LOG.info("Total elapsed time: " + (System.currentTimeMillis() - startTime) + "ms");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        writer.close();
        dir.close();
        out.close();
    }
}

From source file:com.alibaba.jstorm.flux.Flux.java

public static void main(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(option(0, "l", OPTION_LOCAL, "Run the topology in local mode."));

    options.addOption(option(0, "r", OPTION_REMOTE, "Deploy the topology to a remote cluster."));

    options.addOption(option(0, "R", OPTION_RESOURCE,
            "Treat the supplied path as a classpath resource instead of a file."));

    options.addOption(/*from   w  w w  . j  a  va2s .c  om*/
            option(1, "s", OPTION_SLEEP, "ms", "When running locally, the amount of time to sleep (in ms.) "
                    + "before killing the topology and shutting down the local cluster."));

    options.addOption(option(0, "d", OPTION_DRY_RUN, "Do not run or deploy the topology. Just build, validate, "
            + "and print information about the topology."));

    options.addOption(option(0, "q", OPTION_NO_DETAIL, "Suppress the printing of topology details."));

    options.addOption(option(0, "n", OPTION_NO_SPLASH, "Suppress the printing of the splash screen."));

    options.addOption(option(0, "i", OPTION_INACTIVE, "Deploy the topology, but do not activate it."));

    options.addOption(option(1, "z", OPTION_ZOOKEEPER, "host:port",
            "When running in local mode, use the ZooKeeper at the "
                    + "specified <host>:<port> instead of the in-process ZooKeeper. (requires Storm 0.9.3 or later)"));

    options.addOption(option(1, "f", OPTION_FILTER, "file",
            "Perform property substitution. Use the specified file "
                    + "as a source of properties, and replace keys identified with {$[property name]} with the value defined "
                    + "in the properties file."));

    options.addOption(
            option(0, "e", OPTION_ENV_FILTER, "Perform environment variable substitution. Replace keys"
                    + "identified with `${ENV-[NAME]}` will be replaced with the corresponding `NAME` environment value"));

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = parser.parse(options, args);

    if (cmd.getArgs().length != 1) {
        usage(options);
        System.exit(1);
    }
    runCli(cmd);
}

From source file:eu.stratosphere.sopremo.server.SopremoServer.java

/**
 * Entry point for the program/*from ww w .j av  a2s  . co m*/
 * 
 * @param args
 *        arguments from the command line
 */
@SuppressWarnings("static-access")
public static void main(final String[] args) {

    final Option configDirOpt = OptionBuilder.withArgName("config directory").hasArg()
            .withDescription("Specify configuration directory.").create("configDir");

    final Options options = new Options();
    options.addOption(configDirOpt);

    CommandLineParser parser = new GnuParser();
    CommandLine line = null;
    try {
        line = parser.parse(options, args);
        final String configDir = line.getOptionValue(configDirOpt.getOpt(), null);
        GlobalConfiguration.loadConfiguration(configDir);
    } catch (ParseException e) {
        LOG.error("CLI Parsing failed. Reason: " + e.getMessage());
        System.exit(1);
    }

    // start server
    SopremoServer sopremoServer = new SopremoServer();
    try {
        sopremoServer.start();
    } catch (IOException e) {
        LOG.error("Cannot start Sopremo server: " + StringUtils.stringifyException(e));
        sopremoServer.close();
        return;
    }

    // and wait for any shutdown signal
    while (!Thread.interrupted()) {
        // Sleep
        try {
            Thread.sleep(SLEEPINTERVAL);
        } catch (InterruptedException e) {
            break;
        }
        // Do nothing here
    }
}

From source file:com.aestel.chemistry.openEye.fp.FPDictionarySorter.java

public static void main(String... args) throws IOException {
    long start = System.currentTimeMillis();
    int iCounter = 0;
    int fpCounter = 0;

    // create command line Options object
    Options options = new Options();
    Option opt = new Option("i", true, "input file [.ism,.sdf,...]");
    opt.setRequired(true);/*from  w  w w .j  av a2s  .  co  m*/
    options.addOption(opt);

    opt = new Option("fpType", true, "fingerPrintType: maccs|linear7|linear7*4");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("sampleFract", true, "fraction of input molecules to use (Default=1)");
    opt.setRequired(false);
    options.addOption(opt);

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        System.err.println(e.getMessage());
        exitWithHelp(options);
    }
    args = cmd.getArgs();

    if (cmd.hasOption("d")) {
        System.err.println("Start debugger and press return:");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    }

    if (args.length != 0) {
        exitWithHelp(options);
    }

    String type = cmd.getOptionValue("fpType");
    boolean updateDictionaryFile = false;
    boolean hashUnknownFrag = false;
    Fingerprinter fprinter = Fingerprinter.createFingerprinter(type, updateDictionaryFile, hashUnknownFrag);
    OEMolBase mol = new OEGraphMol();

    String inFile = cmd.getOptionValue("i");
    oemolistream ifs = new oemolistream(inFile);

    double fract = 2D;
    String tmp = cmd.getOptionValue("sampleFract");
    if (tmp != null)
        fract = Double.parseDouble(tmp);

    Random rnd = new Random();

    LearningStrcutureCodeMapper mapper = (LearningStrcutureCodeMapper) fprinter.getMapper();
    int dictSize = mapper.getMaxIdx() + 1;
    int[] freq = new int[dictSize];

    while (oechem.OEReadMolecule(ifs, mol)) {
        iCounter++;
        if (rnd.nextDouble() < fract) {
            fpCounter++;

            Fingerprint fp = fprinter.getFingerprint(mol);
            for (int bit : fp.getBits())
                freq[bit]++;
        }

        if (iCounter % 100 == 0)
            System.err.print(".");
        if (iCounter % 4000 == 0) {
            System.err.printf(" %d %d %dsec\n", iCounter, fpCounter,
                    (System.currentTimeMillis() - start) / 1000);
        }
    }

    System.err.printf("FPDictionarySorter: Read %d structures calculated %d fprints in %d sec\n", iCounter,
            fpCounter, (System.currentTimeMillis() - start) / 1000);

    mapper.reSortDictionary(freq);
    mapper.writeDictionary();
    fprinter.close();
}