Example usage for org.apache.commons.cli ParseException getMessage

List of usage examples for org.apache.commons.cli ParseException getMessage

Introduction

In this page you can find the example usage for org.apache.commons.cli ParseException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.booktrack.vader.Main.java

/**
 * main entry point and demo case for Vader
 * @param args the arguments - explained below in the code
 * @throws Exception anything goes wrong - except
 *//*w w w . ja  v a 2 s.  c  o  m*/
public static void main(String[] args) throws Exception {

    // create Options object for command line parsing
    Options options = new Options();
    options.addOption("file", true, "input text-file (-file) to read and analyse using Vader");

    CommandLineParser cmdParser = new DefaultParser();
    CommandLine line = null;
    try {
        // parse the command line arguments
        line = cmdParser.parse(options, args);
    } catch (ParseException exp) {
        // oops, something went wrong
        logger.error("invalid command line: " + exp.getMessage());
        System.exit(0);
    }

    // get the command line argument -file
    String inputFile = line.getOptionValue("file");
    if (inputFile == null) {
        help(options);
        System.exit(0);
    }
    if (!new File(inputFile).exists()) {
        logger.error("file does not exist: " + inputFile);
        System.exit(0);
    }

    // example use of the classes
    // read the entire input file
    String fileText = new String(Files.readAllBytes(Paths.get(inputFile)));

    // setup Vader
    Vader vader = new Vader();
    vader.init(); // load vader

    // setup nlp processor
    VaderNLP vaderNLP = new VaderNLP();
    vaderNLP.init(); // load open-nlp

    // parse the text into a set of sentences
    List<List<Token>> sentenceList = vaderNLP.parse(fileText);

    // apply vader analysis to each sentence
    for (List<Token> sentence : sentenceList) {
        VScore vaderScore = vader.analyseSentence(sentence);
        logger.info("sentence:" + Token.tokenListToString(sentence));
        logger.info("Vader score:" + vaderScore.toString());
    }

}

From source file:me.cavar.pg2tei.Gutenberg2TEI.java

/**
 * @param args/*from  ww  w .  ja va 2 s  .  c  om*/
 */
public static void main(String[] args) {
    // Process command line
    Options options = new Options();

    options.addOption("c", true, "Catalogue URL");
    options.addOption("o", true, "Output folder");
    // options.addOption("f", true, "Resulting output catalogue file name");
    options.addOption("h", false, "Help");

    // the individual RDF-files are at this URL:
    // The RDF-file name is this.idN + ".rdf"
    String ebookURLStr = "http://www.gutenberg.org/ebooks/";

    // the URL to the catalog.rdf
    String catalogURLStr = "http://www.gutenberg.org/feeds/catalog.rdf.zip";
    String outputFolder = ".";
    String catalogOutFN = "catalog.rdf";

    CommandLineParser parser;
    parser = new PosixParser();
    try {
        CommandLine cmd = parser.parse(options, args);
        if (cmd.hasOption("h")) {
            System.out.println("Project Gutenberg fetch RDF catalog, HTML-files and generate TEI XML");
            System.out.println("");
            return;
        }
        if (cmd.hasOption("c")) {
            catalogURLStr = cmd.getOptionValue("c");
        }
        if (cmd.hasOption("o")) {
            outputFolder = cmd.getOptionValue("o");
        }
        //if (cmd.hasOption("f")) {
        //    catalogOutFN = cmd.getOptionValue("f");
        //}

    } catch (ParseException ex) {
        System.out.println("Command line argument error:" + ex.getMessage());
    }

    // Do the fetching of the RDF catalog
    fetchRDF(catalogURLStr, outputFolder, catalogOutFN);

    // process the RDF file
    processRDF(outputFolder, catalogOutFN, ebookURLStr);
}

From source file:com.runwaysdk.system.metadata.MetadataPatcher.java

@SuppressWarnings("static-access")
public static void main(String[] args) {
    Options options = new Options();
    options.addOption(OptionBuilder.withArgName("vendor").hasArg()
            .withDescription("Database vendor [" + POSTGRESQL + "]").isRequired().create("d"));
    options.addOption(OptionBuilder.withArgName("username").hasArg().withDescription("Database username")
            .isRequired().create("u"));
    options.addOption(OptionBuilder.withArgName("password").hasArg().withDescription("Database password")
            .isRequired().create("p"));
    options.addOption(//from ww  w.  j a  va2  s .  co m
            OptionBuilder.withArgName("url").hasArg().withDescription("Database URL").isRequired().create("l"));

    CommandLineParser parser = new BasicParser();

    try {
        CommandLine cmd = parser.parse(options, args);

        MetadataPatcher patcher = new MetadataPatcher();
        patcher.setDbms(cmd.getOptionValue("d"));
        patcher.setUserid(cmd.getOptionValue("u"));
        patcher.setPassword(cmd.getOptionValue("p"));
        patcher.setUrl(cmd.getOptionValue("l"));
        patcher.run();
    } catch (ParseException exp) {
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());
    } catch (RuntimeException exp) {
        System.err.println("Patching failed. Reason: " + exp.getMessage());
    }
}

From source file:co.turnus.analysis.pipelining.SimplePipeliningCliLauncher.java

public static void main(String[] args) {
    try {/*from   w w w .  j  ava2 s .c o  m*/
        CommandLineParser parser = new GnuParser();
        CommandLine cmd = parser.parse(cliOptions, args);
        Configuration config = parseCommandLine(cmd);

        // init models
        AnalysisActivator.init();

        // set logger verbosity
        if (config.getBoolean(VERBOSE, false)) {
            TurnusLogger.setLevel(TurnusLevel.ALL);
        }

        // load trace project
        File tDir = new File(config.getString(TRACE_PROJECT));
        TraceProject project = TraceProject.load(tDir);

        SimplePipelining sp = new SimplePipelining(project);
        sp.setConfiguration(config);

        SimplePipelingData data = sp.run();

        TurnusLogger.info("Storing results...");
        File outPath = new File(config.getString(OUTPUT_PATH));

        // store the analysis report
        String uuid = UUID.randomUUID().toString();
        File rFile = new File(outPath, uuid + "." + TurnusExtension.REPORT);
        Report report = DataFactory.eINSTANCE.createReport();
        report.setDate(new Date());
        report.setComment("Report with only Simple Pipeling results analysis");
        report.getDataSet().add(data);
        EcoreHelper.storeEObject(report, new ResourceSetImpl(), rFile);
        TurnusLogger.info("TURNUS report stored in " + rFile);

        // store formatted reports
        String xlsName = config.getString(XLS, "");
        if (!xlsName.isEmpty()) {
            File xlsFile = new File(outPath, xlsName + ".xls");
            new XlsSimplePipeliningDataWriter().write(data, xlsFile);
            TurnusLogger.info("XLS report stored in " + xlsFile);
        }

        TurnusLogger.info("Analysis Done!");

    } catch (ParseException e) {
        TurnusLogger.error(e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(SimplePipeliningCliLauncher.class.getSimpleName(), cliOptions);
    } catch (Exception e) {
        TurnusLogger.error(e.getMessage());
    }

}

From source file:is.merkor.statistics.cli.Main.java

public static void main(String[] args) throws Exception {

    CommandLineParser parser = new GnuParser();
    try {//from w w  w .j  a v a2s . c o m
        MerkorCommandLineOptions.createOptions();
        processCommandLine(parser.parse(MerkorCommandLineOptions.options, args));
    } catch (ParseException e) {
        System.err.println("Parsing failed.  Reason: " + e.getMessage());
    }
}

From source file:com.redhat.akashche.wixgen.cli.Launcher.java

public static void main(String[] args) throws Exception {
    try {/* w  w w.  j a v a 2s  .  co m*/
        CommandLine cline = new GnuParser().parse(OPTIONS, args);
        if (cline.hasOption(VERSION_OPTION)) {
            out.println(VERSION);
        } else if (cline.hasOption(HELP_OPTION)) {
            throw new ParseException("Printing help page:");
        } else if (1 == cline.getArgs().length && cline.hasOption(CONFIG_OPTION)
                && cline.hasOption(OUTPUT_OPTION) && !cline.hasOption(XSL_OPTION)) {
            WixConfig conf = parseConf(cline.getOptionValue(CONFIG_OPTION));
            Wix wix = new DirectoryGenerator().createFromDir(new File(cline.getArgs()[0]), conf);
            Marshaller marshaller = createMarshaller();
            writeXml(marshaller, wix, cline.getOptionValue(OUTPUT_OPTION), false);
            if (cline.hasOption(DIRECTORY_OPTION)) {
                Directory dir = findWixDirectory(wix);
                writeXml(marshaller, dir, cline.getOptionValue(DIRECTORY_OPTION), true);
            }
            if (cline.hasOption(FEATURE_OPTION)) {
                Feature feature = findWixFeature(wix);
                writeXml(marshaller, feature, cline.getOptionValue(FEATURE_OPTION), true);
            }
        } else if (1 == cline.getArgs().length && cline.hasOption(XSL_OPTION)
                && cline.hasOption(OUTPUT_OPTION)) {
            transformWithXsl(cline.getArgs()[0], cline.getOptionValue(XSL_OPTION),
                    cline.getOptionValue(OUTPUT_OPTION));
        } else {
            throw new ParseException("Incorrect arguments received!");
        }
    } catch (ParseException e) {
        HelpFormatter formatter = new HelpFormatter();
        out.println(e.getMessage());
        out.println(VERSION);
        formatter.printHelp("java -jar wixgen.jar input_dir -c config.json -o output.wxs", OPTIONS);
    }
}

From source file:de.burlov.amazon.s3.S3Utils.java

public static void main(String[] args) {
    Options opts = new Options();
    OptionGroup gr = new OptionGroup();
    gr.setRequired(true);/*from ww  w  . j a  v a2s  .  co m*/
    gr.addOption(new Option(LIST, false, ""));
    gr.addOption(new Option(DELETE, false, ""));

    opts.addOptionGroup(gr);

    opts.addOption(new Option("k", true, "Access key for AWS account"));
    opts.addOption(new Option("s", true, "Secret key for AWS account"));
    opts.addOption(new Option("b", true, "Bucket"));
    CommandLine cmd = null;
    try {
        cmd = new PosixParser().parse(opts, args);

        String accessKey = cmd.getOptionValue("k");
        if (StringUtils.isBlank(accessKey)) {
            System.out.println("Missing amazon access key");
            return;
        }
        String secretKey = cmd.getOptionValue("s");
        if (StringUtils.isBlank(secretKey)) {
            System.out.println("Missing secret key");
            return;
        }
        String bucket = cmd.getOptionValue("b");
        if (cmd.hasOption(LIST)) {
            if (StringUtils.isBlank(bucket)) {
                printBuckets(accessKey, secretKey);
            } else {
                printBucket(accessKey, secretKey, bucket);
            }
        } else if (cmd.hasOption(DELETE)) {
            if (StringUtils.isBlank(bucket)) {
                System.out.println("Bucket name required");
                return;
            }
            int count = deleteBucket(accessKey, secretKey, bucket);
            System.out.println("Deleted objects in bucket: " + count);
        }
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        printUsage(opts);
        return;
    } catch (Exception e) {
        e.printStackTrace(System.err);
    }
}

From source file:it.tizianofagni.sparkboost.AdaBoostMHLearnerExe.java

public static void main(String[] args) {
    Options options = new Options();
    options.addOption("b", "binaryProblem", false,
            "Indicate if the input dataset contains a binary problem and not a multilabel one");
    options.addOption("z", "labels0based", false,
            "Indicate if the labels IDs in the dataset to classifyLibSvmWithResults are already assigned in the range [0, numLabels-1] included");
    options.addOption("l", "enableSparkLogging", false, "Enable logging messages of Spark");
    options.addOption("w", "windowsLocalModeFix", true,
            "Set the directory containing the winutils.exe command");
    options.addOption("dp", "documentPartitions", true, "The number of document partitions");
    options.addOption("fp", "featurePartitions", true, "The number of feature partitions");
    options.addOption("lp", "labelPartitions", true, "The number of label partitions");

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = null;// ww  w .  j ava  2 s .c om
    String[] remainingArgs = null;
    try {
        cmd = parser.parse(options, args);
        remainingArgs = cmd.getArgs();
        if (remainingArgs.length != 5)
            throw new ParseException("You need to specify all mandatory parameters");
    } catch (ParseException e) {
        System.out.println("Parsing failed.  Reason: " + e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(AdaBoostMHLearnerExe.class.getSimpleName()
                + " [OPTIONS] <inputFile> <outputFile> <numIterations> <sparkMaster> <parallelismDegree>",
                options);
        System.exit(-1);
    }

    boolean binaryProblem = false;
    if (cmd.hasOption("b"))
        binaryProblem = true;
    boolean labels0Based = false;
    if (cmd.hasOption("z"))
        labels0Based = true;
    boolean enablingSparkLogging = false;
    if (cmd.hasOption("l"))
        enablingSparkLogging = true;

    if (cmd.hasOption("w")) {
        System.setProperty("hadoop.home.dir", cmd.getOptionValue("w"));
    }

    String inputFile = remainingArgs[0];
    String outputFile = remainingArgs[1];
    int numIterations = Integer.parseInt(remainingArgs[2]);
    String sparkMaster = remainingArgs[3];
    int parallelismDegree = Integer.parseInt(remainingArgs[4]);

    long startTime = System.currentTimeMillis();

    // Disable Spark logging.
    if (!enablingSparkLogging) {
        Logger.getLogger("org").setLevel(Level.OFF);
        Logger.getLogger("akka").setLevel(Level.OFF);
    }

    // Create and configure Spark context.
    SparkConf conf = new SparkConf().setAppName("Spark AdaBoost.MH learner");
    JavaSparkContext sc = new JavaSparkContext(conf);

    // Create and configure learner.
    AdaBoostMHLearner learner = new AdaBoostMHLearner(sc);
    learner.setNumIterations(numIterations);

    if (cmd.hasOption("dp")) {
        learner.setNumDocumentsPartitions(Integer.parseInt(cmd.getOptionValue("dp")));
    }
    if (cmd.hasOption("fp")) {
        learner.setNumFeaturesPartitions(Integer.parseInt(cmd.getOptionValue("fp")));
    }
    if (cmd.hasOption("lp")) {
        learner.setNumLabelsPartitions(Integer.parseInt(cmd.getOptionValue("lp")));
    }

    // Build classifier with MPBoost learner.
    BoostClassifier classifier = learner.buildModel(inputFile, labels0Based, binaryProblem);

    // Save classifier to disk.
    DataUtils.saveModel(sc, classifier, outputFile);

    long endTime = System.currentTimeMillis();
    System.out.println("Execution time: " + (endTime - startTime) + " milliseconds.");
}

From source file:jlite.cli.ProxyInit.java

public static void main(String[] args) {
    CommandLineParser parser = new GnuParser();
    Options options = setupOptions();/*from  ww w . ja v  a  2 s  .com*/
    HelpFormatter helpFormatter = new HelpFormatter();
    helpFormatter.setSyntaxPrefix("Usage: ");
    CommandLine line = null;
    try {
        line = parser.parse(options, args);
        if (line.hasOption("help")) {
            System.out.println(); // extra line
            helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER + "\n", false);
            System.out.println(); // extra line
            System.exit(0);
        } else {
            if (line.hasOption("xml")) {
                System.out.println("<output>");
            }
            String[] remArgs = line.getArgs();
            if (remArgs.length > 0) {
                run(remArgs, line);
            } else {
                throw new MissingArgumentException("Missing required argument: <voms>[:<command>]");
            }
        }
    } catch (ParseException e) {
        System.err.println("\n" + e.getMessage() + "\n");
        helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER + "\n", false);
        System.out.println(); // extra line
        System.exit(-1);
    } catch (Exception e) {
        if ((line != null) && (line.hasOption("xml"))) {
            System.out.println("<error>" + e.getMessage() + "</error>");
        } else {
            System.err.println(e.getMessage());
        }
    } finally {
        if (line.hasOption("xml")) {
            System.out.println("</output>");
        }
    }
    System.out.println(); // extra line
}

From source file:com.baystep.jukeberry.JukeBerry.java

/**
 * @param args the command line arguments
 *//*  w ww  . j  a  va 2 s .c  o m*/
public static void main(String[] args) {
    System.out.println("Berry Music\n");

    JukeBerry bm = new JukeBerry();

    buildOptions();
    CommandLineParser cmdParser = new DefaultParser();
    try {
        CommandLine cmd = cmdParser.parse(cmdOptions, args);

        if (cmd.hasOption("h")) {
            cmdHelp.printHelp("BerryMusic", help_Header, cmdOptions, help_Footer, true);
            System.exit(0);
        }

        if (cmd.hasOption("pw"))
            bm.config.httpPort = Integer.parseInt(cmd.getOptionValue("pw"));

        if (cmd.hasOption("ps"))
            bm.config.websocketPort = Integer.parseInt(cmd.getOptionValue("ps"));

        if (cmd.hasOption("d")) {
            String dOpt = cmd.getOptionValue("d");
            bm.config.setDisableOption(dOpt);
        }

        if (cmd.hasOption("ss"))
            bm.config.mpStartService = cmd.getOptionValue("ss");

        if (cmd.hasOption("sc")) {
            BerryLogger.supressConsole();
        }

    } catch (ParseException pe) {
        System.err.println("Command line parsing failed, reason: " + pe.getMessage());
    }

    bm.init();
}