Example usage for org.apache.commons.cli CommandLine getOptions

List of usage examples for org.apache.commons.cli CommandLine getOptions

Introduction

In this page you can find the example usage for org.apache.commons.cli CommandLine getOptions.

Prototype

public Option[] getOptions() 

Source Link

Document

Returns an array of the processed Option s.

Usage

From source file:ml.shifu.shifu.ShifuCLI.java

public static void main(String[] args) {
    String[] cleanedArgs = cleanArgs(args);
    // invalid input and help options
    if (cleanedArgs.length < 1 || (isHelpOption(cleanedArgs[0]))) {
        printUsage();/*from  w  w w  . j  av a 2s .c  om*/
        System.exit(cleanedArgs.length < 1 ? -1 : 0);
    }

    // process -v and -version conditions manually
    if (isVersionOption(cleanedArgs[0])) {
        printLogoAndVersion();
        System.exit(0);
    }

    CommandLineParser parser = new GnuParser();
    Options opts = buildModelSetOptions();
    CommandLine cmd = null;

    try {
        cmd = parser.parse(opts, cleanedArgs);
    } catch (ParseException e) {
        log.error("Invalid command options. Please check help message.");
        printUsage();
        System.exit(1);
    }

    int status = 0;

    try {
        if (cleanedArgs[0].equals(NEW) && cleanedArgs.length >= 2 && StringUtils.isNotEmpty(cleanedArgs[1])) {
            // modelset step
            String modelName = cleanedArgs[1];
            status = createNewModel(modelName, cmd.getOptionValue(MODELSET_CMD_TYPE),
                    cmd.getOptionValue(MODELSET_CMD_M));
            if (status == 0) {
                printModelSetCreatedSuccessfulLog(modelName);
            } else {
                log.warn("Error in create new model set, please check your shifu config or report issue");
            }
            System.exit(status);
            // copyModel(manager, cmd.getOptionValues(MODELSET_CMD_CP));
        } else {
            if (cleanedArgs[0].equals(MODELSET_CMD_CP) && cleanedArgs.length >= 3
                    && StringUtils.isNotEmpty(cleanedArgs[1]) && StringUtils.isNotEmpty(cleanedArgs[2])) {
                String newModelSetName = cleanedArgs[2];
                // modelset step
                copyModel(new String[] { cleanedArgs[1], newModelSetName });
                printModelSetCopiedSuccessfulLog(newModelSetName);
            } else if (cleanedArgs[0].equals(INIT_CMD)) {
                // init step
                if (cmd.getOptions() == null || cmd.getOptions().length == 0) {
                    status = initializeModel();
                    if (status == 0) {
                        log.info(
                                "ModelSet initialization is successful. Please continue next step by using 'shifu stats'.");
                    } else {
                        log.warn(
                                "Error in ModelSet initialization, please check your shifu config or report issue");
                    }
                } else if (cmd.hasOption(INIT_CMD_MODEL)) {
                    initializeModelParam();
                } else {
                    log.error("Invalid command, please check help message.");
                    printUsage();
                }
            } else if (cleanedArgs[0].equals(STATS_CMD)) {
                Map<String, Object> params = new HashMap<String, Object>();
                params.put(Constants.IS_COMPUTE_CORR,
                        cmd.hasOption(CORRELATION) || cmd.hasOption(SHORT_CORRELATION));
                params.put(Constants.IS_REBIN, cmd.hasOption(REBIN));
                params.put(Constants.REQUEST_VARS, cmd.getOptionValue(VARS));
                params.put(Constants.EXPECTED_BIN_NUM, cmd.getOptionValue(N));
                params.put(Constants.IV_KEEP_RATIO, cmd.getOptionValue(IVR));
                params.put(Constants.MINIMUM_BIN_INST_CNT, cmd.getOptionValue(BIC));
                params.put(Constants.IS_COMPUTE_PSI, cmd.hasOption(PSI) || cmd.hasOption(SHORT_PSI));

                // stats step
                status = calModelStats(params);
                if (status == 0) {
                    if (cmd.hasOption(CORRELATION) || cmd.hasOption(SHORT_CORRELATION)) {
                        log.info(
                                "Do model set correlation computing successfully. Please continue next step by using 'shifu normalize or shifu norm'. For tree ensemble model, no need do norm, please continue next step by using 'shifu varsel'");
                    }
                    if (cmd.hasOption(PSI) || cmd.hasOption(SHORT_PSI)) {
                        log.info(
                                "Do model set psi computing successfully. Please continue next step by using 'shifu normalize or shifu norm'. For tree ensemble model, no need do norm, please continue next step by using 'shifu varsel'");
                    } else {
                        log.info(
                                "Do model set statistic successfully. Please continue next step by using 'shifu normalize or shifu norm or shifu transform'. For tree ensemble model, no need do norm, please continue next step by using 'shifu varsel'");
                    }
                } else {
                    log.warn(
                            "Error in model set stats computation, please report issue on http:/github.com/shifuml/shifu/issues.");
                }
            } else if (cleanedArgs[0].equals(NORMALIZE_CMD) || cleanedArgs[0].equals(NORM_CMD)
                    || cleanedArgs[0].equals(TRANSFORM_CMD)) {
                // normalize step
                Map<String, Object> params = new HashMap<String, Object>();
                params.put(Constants.IS_TO_SHUFFLE_DATA, cmd.hasOption(SHUFFLE));
                status = normalizeTrainData(params);
                if (status == 0) {
                    log.info(
                            "Do model set normalization successfully. Please continue next step by using 'shifu varselect or shifu varsel'.");
                } else {
                    log.warn(
                            "Error in model set stats computation, please report issue on http:/github.com/shifuml/shifu/issues.");
                }
            } else if (cleanedArgs[0].equals(VARSELECT_CMD) || cleanedArgs[0].equals(VARSEL_CMD)) {
                Map<String, Object> params = new HashMap<String, Object>();
                params.put(Constants.IS_TO_RESET, cmd.hasOption(RESET));
                params.put(Constants.IS_TO_LIST, cmd.hasOption(LIST));
                params.put(Constants.IS_TO_FILTER_AUTO, cmd.hasOption(FILTER_AUTO));
                params.put(Constants.IS_TO_RECOVER_AUTO, cmd.hasOption(RECOVER_AUTO));
                params.put(Constants.RECURSIVE_CNT, cmd.getOptionValue(RECURSIVE));

                // variable selected step
                status = selectModelVar(params);
                if (status == 0) {
                    log.info(
                            "Do model set variables selection successfully. Please continue next step by using 'shifu train'.");
                } else {
                    log.info("Do variable selection with error, please check error message or report issue.");
                }
            } else if (cleanedArgs[0].equals(TRAIN_CMD)) {
                // train step
                status = trainModel(cmd.hasOption(TRAIN_CMD_DRY), cmd.hasOption(TRAIN_CMD_DEBUG),
                        cmd.hasOption(SHUFFLE));
                if (status == 0) {
                    log.info(
                            "Do model set training successfully. Please continue next step by using 'shifu posttrain' or if no need posttrain you can go through with 'shifu eval'.");
                } else {
                    log.info("Do model training with error, please check error message or report issue.");
                }
            } else if (cleanedArgs[0].equals(CMD_ENCODE)) {
                Map<String, Object> params = new HashMap<String, Object>();
                params.put(ModelDataEncodeProcessor.ENCODE_DATA_SET, cmd.getOptionValue(EVAL_CMD_RUN));
                params.put(ModelDataEncodeProcessor.ENCODE_REF_MODEL, cmd.getOptionValue(REF));
                status = runEncode(params);
            } else if (cleanedArgs[0].equals(CMD_COMBO)) {
                if (cmd.hasOption(MODELSET_CMD_NEW)) {
                    log.info("Create new commbo models");
                    status = createNewCombo(cmd.getOptionValue(MODELSET_CMD_NEW));
                } else if (cmd.hasOption(INIT_CMD)) {
                    log.info("Init commbo models");
                    status = initComboModels();
                } else if (cmd.hasOption(EVAL_CMD_RUN)) {
                    log.info("Run combo model - with toShuffle: {}, with toResume: {}", opts.hasOption(SHUFFLE),
                            opts.hasOption(RESUME));
                    status = runComboModels(cmd.hasOption(SHUFFLE), cmd.hasOption(RESUME));
                    // train combo models
                } else if (cmd.hasOption(EVAL_CMD)) {
                    log.info("Eval combo model.");
                    // eval combo model performance
                    status = evalComboModels(cmd.hasOption(RESUME));
                } else {
                    log.error("Invalid command usage.");
                    printUsage();
                }
            } else if (cleanedArgs[0].equals(POSTTRAIN_CMD)) {
                // post train step
                status = postTrainModel();
                if (status == 0) {
                    log.info(
                            "Do model set post-training successfully. Please configure your eval set in ModelConfig.json and continue next step by using 'shifu eval' or 'shifu eval -new <eval set>' to create a new eval set.");
                } else {
                    log.info("Do model post training with error, please check error message or report issue.");
                }
            } else if (cleanedArgs[0].equals(SAVE)) {
                String newModelSetName = cleanedArgs.length >= 2 ? cleanedArgs[1] : null;
                saveCurrentModel(newModelSetName);
            } else if (cleanedArgs[0].equals(SWITCH)) {
                String newModelSetName = cleanedArgs[1];
                switchCurrentModel(newModelSetName);
            } else if (cleanedArgs[0].equals(SHOW)) {
                ManageModelProcessor p = new ManageModelProcessor(ModelAction.SHOW, null);
                p.run();
            } else if (cleanedArgs[0].equals(EVAL_CMD)) {
                Map<String, Object> params = new HashMap<String, Object>();

                // eval step
                if (cleanedArgs.length == 1) {
                    // run everything
                    status = runEvalSet(cmd.hasOption(TRAIN_CMD_DRY));
                    if (status == 0) {
                        log.info("Run eval performance with all eval sets successfully.");
                    } else {
                        log.info("Do evaluation with error, please check error message or report issue.");
                    }
                } else if (cmd.getOptionValue(MODELSET_CMD_NEW) != null) {
                    // create new eval
                    createNewEvalSet(cmd.getOptionValue(MODELSET_CMD_NEW));
                    log.info(
                            "Create eval set successfully. You can configure EvalConfig.json or directly run 'shifu eval -run <evalSetName>' to get performance info.");
                } else if (cmd.hasOption(EVAL_CMD_RUN)) {
                    runEvalSet(cmd.getOptionValue(EVAL_CMD_RUN), cmd.hasOption(TRAIN_CMD_DRY));
                    log.info("Finish run eval performance with eval set {}.", cmd.getOptionValue(EVAL_CMD_RUN));
                } else if (cmd.hasOption(SCORE)) {
                    params.put(EvalModelProcessor.NOSORT, cmd.hasOption(NOSORT));
                    // run score
                    runEvalScore(cmd.getOptionValue(SCORE), params);
                    log.info("Finish run score with eval set {}.", cmd.getOptionValue(SCORE));
                } else if (cmd.hasOption(CONFMAT)) {
                    // run confusion matrix
                    runEvalConfMat(cmd.getOptionValue(CONFMAT));
                    log.info("Finish run confusion matrix with eval set {}.", cmd.getOptionValue(CONFMAT));
                } else if (cmd.hasOption(PERF)) {
                    // run perfermance
                    runEvalPerf(cmd.getOptionValue(PERF));
                    log.info("Finish run performance maxtrix with eval set {}.", cmd.getOptionValue(PERF));
                } else if (cmd.hasOption(LIST)) {
                    // list all evaluation sets
                    listEvalSet();
                } else if (cmd.hasOption(DELETE)) {
                    // delete some evaluation set
                    deleteEvalSet(cmd.getOptionValue(DELETE));
                } else if (cmd.hasOption(NORM)) {
                    runEvalNorm(cmd.getOptionValue(NORM), cmd.hasOption(STRICT));
                } else {
                    log.error("Invalid command, please check help message.");
                    printUsage();
                }
            } else if (cleanedArgs[0].equals(CMD_EXPORT)) {
                Map<String, Object> params = new HashMap<String, Object>();
                params.put(ExportModelProcessor.IS_CONCISE, cmd.hasOption(EXPORT_CONCISE));
                params.put(ExportModelProcessor.REQUEST_VARS, cmd.getOptionValue(VARS));
                params.put(ExportModelProcessor.EXPECTED_BIN_NUM, cmd.getOptionValue(N));
                params.put(ExportModelProcessor.IV_KEEP_RATIO, cmd.getOptionValue(IVR));
                params.put(ExportModelProcessor.MINIMUM_BIN_INST_CNT, cmd.getOptionValue(BIC));
                status = exportModel(cmd.getOptionValue(MODELSET_CMD_TYPE), params);
                if (status == 0) {
                    log.info("Export models/columnstats/corr successfully.");
                } else {
                    log.warn("Fail to export models/columnstats/corr, please check or report issue.");
                }
            } else if (cleanedArgs[0].equals(CMD_TEST)) {
                Map<String, Object> params = new HashMap<String, Object>();
                params.put(ShifuTestProcessor.IS_TO_TEST_FILTER, cmd.hasOption(FILTER));
                params.put(ShifuTestProcessor.TEST_TARGET, cmd.getOptionValue(FILTER));
                params.put(ShifuTestProcessor.TEST_RECORD_CNT, cmd.getOptionValue(N));
                status = runShifuTest(params);
                if (status == 0) {
                    log.info("Run test for Shifu Successfully.");
                } else {
                    log.warn("Fail to run Shifu test.");
                }
            } else if (cleanedArgs[0].equals(CMD_CONVERT)) {
                int optType = -1;
                if (cmd.hasOption(TO_ZIPB)) {
                    optType = 1;
                } else if (cmd.hasOption(TO_TREEB)) {
                    optType = 2;
                }

                String[] convertArgs = new String[2];
                int j = 0;
                for (int i = 1; i < cleanedArgs.length; i++) {
                    if (!cleanedArgs[i].startsWith("-")) {
                        convertArgs[j++] = cleanedArgs[i];
                    }
                }

                if (optType < 0 || StringUtils.isBlank(convertArgs[0]) || StringUtils.isBlank(convertArgs[1])) {
                    printUsage();
                } else {
                    status = runShifuConvert(optType, convertArgs[0], convertArgs[1]);
                }
            } else if (cleanedArgs[0].equals(CMD_ANALYSIS)) {
                if (cmd.hasOption(FI)) {
                    String modelPath = cmd.getOptionValue(FI);
                    analysisModelFi(modelPath);
                }
            } else {
                log.error("Invalid command, please check help message.");
                printUsage();
            }
        }
        // for some case jvm cannot stop
        System.exit(status);
    } catch (ShifuException e) {
        // need define error code in each step.
        log.error(e.getError().toString() + "; msg: " + e.getMessage(), e.getCause());
        exceptionExit(e);
    } catch (Exception e) {
        exceptionExit(e);
    }
}

From source file:edu.ehu.galan.lite.Lite.java

/**
 * Main entry point for LiTe from the command Line use -h option for help
 *
 * @param args//from  w  w w. ja  va2  s  .  c o  m
 */
public static void main(String[] args) {

    // create Options object
    Options options = new Options();
    Option corpus = new Option("c", true,
            "the location (directory) of the corpus to process, containing only one document at the moment");
    Option language = new Option("l", true,
            "the language of the corpus (lowercase ISO format, for example 'en'");
    Option algorithms = new Option("a", true, "the algorithms you want to process separated by commas: \n"
            + "see the documentation for see the available algorithms for each language");
    Option help = new Option("h", false, "print this message");
    Option resources = new Option("r", true, "the location of the lite resources folder");
    Option output = new Option("o", true,
            "The directory where the results will be stored, by default the one where the vm has been launched");
    Option listAlgs = new Option("listAlgs", false,
            " Algorithm list names with the supported languages (remember that the cvalue will be processed chosen or not):\n"
                    + "===================================================\n"
                    + "tfidf => processes the TFIDF algorithm, process terms of the input document using the Wikipedia corpus as IDF (en,es)\n"
                    + "cvalue => processes the CValue altorithm for the inputdocument, CValue is processed whether is chosed or not! (en, es)\n"
                    + "shallow => processes the shallow parsing grammar algorithm (en)\n"
                    + "rake => processes the rake algorithm (language agnostig)\n"
                    + "kpminer => processes the KPMiner algorithm (en)\n"
                    + "chisquare => processes the ChiSquare using the NLTK toolkit (language agnostic)\n"
                    + "pmi=> processes the Point Mutual Information using the NLTK toolkit (language agnostic)\n"
                    + "likehood=> processes the Likehood Ratio using the NLTK toolkit (language agnostic)\n"
                    + "tstudent=> processes the T-Student using the NLTK toolkit (language agnostic)\n"
                    + "rawfreq=> processes the raw frequency algorithm using the NLTK toolkit (language agnostic)\n"
                    + "freelingner=> processes the FreeLing ner algorithm via external call(es, en)\n");
    options.addOption(resources);
    options.addOption(corpus);
    options.addOption(language);
    options.addOption(algorithms);
    options.addOption(listAlgs);
    options.addOption(output);
    // automatically generate the help statement
    HelpFormatter formatter = new HelpFormatter();
    String[] s = new String[] {};
    // create the parser
    CommandLineParser parser = new org.apache.commons.cli.GnuParser();
    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);
        if (line.hasOption('c') && line.hasOption('l') && line.hasOption('a') && line.hasOption('r')) {
            if (!line.getOptionValue('l').equals("en") && !line.getOptionValue("l").equals("es")) {
                System.out.println(
                        "Supported languages \"en\" or \"es\", however you may use the statistical algorithms via the API");
            } else {
                String outputDir = "";
                if (line.hasOption('o')) {
                    outputDir = line.getOptionValue('o');
                }
                String lang = line.getOptionValue('l');
                Corpus cor = new Corpus(line.getOptionValue('l'));
                cor.loadCorpus(line.getOptionValue('c'), Document.SourceType.wikipedia);
                String res = line.getOptionValue('r');
                List<String> algs = Arrays.asList(line.getOptionValue('a').split(","));
                System.out.println("Processing.... (it may take a while...)");
                runner(lang, res + File.separator, algs, cor, outputDir);
            }
        }
        if (line.hasOption('c') && line.hasOption('l') && line.hasOption('r')) {
            if (!line.getOptionValue('l').equals("en") && !line.getOptionValue("l").equals("es")) {
                System.out.println(
                        "Supported languages \"en\" or \"es\", however you may use the statistical algorithms via the API");
            } else {
                String outputDir = "";
                if (line.hasOption('o')) {
                    outputDir = line.getOptionValue('o');
                }
                System.out.println(
                        "Processing with default algorithms (TFIDF/CValue).... (it may take a while...)");
                Corpus cor = new Corpus(line.getOptionValue('l'));
                String res = line.getOptionValue('r');
                cor.loadCorpus(line.getOptionValue('c'), Document.SourceType.wikipedia);
                String lang = line.getOptionValue('l');
                List<String> algos = null;
                switch (lang) {
                case "es": {
                    String[] algs = { "cvalue", "tfidf", "rake" };
                    algos = Arrays.asList(algs);
                    break;
                }
                case "en": {
                    String[] algs = { "cvalue", "tfidf", "rake" };
                    algos = Arrays.asList(algs);
                    break;
                }
                }
                runner(lang, res + File.separator, algos, cor, outputDir);
            }
        } else if (line.hasOption("h")) {
            formatter.printHelp("LiTe: a language indepent term extractor", options);
        } else if (line.getOptions().length == 0) {
            formatter.printHelp("LiTe: a language indepent term extractor", options);
        } else {
            System.err.println("The 'c', 'l' and 'r' arguments are required \n");
            formatter.printHelp("LiTe: a language indepent term extractor", options);
        }
    } catch (ParseException exp) {
        // oops, something went wrong
        System.err.println("Parsing failed.  Reason: " + exp.getMessage() + "\n");
        formatter.printHelp("LiTe: a language indepent term extractor", options);

    }

}

From source file:com.cronutils.cli.CronUtilsCLI.java

private static void cronValidation(String[] args) throws ParseException {
    Options options = new Options();
    options.addOption("v", "validate", false, "Action of validation (default)");
    options.addOption("f", "format", true,
            "Cron expression format to validate. Possible values are: CRON4J, QUARTZ, UNIX");
    options.addOption("e", "expression", true, "Cron expression to validate. Example: '* 1 * * *'");
    options.addOption("h", HELP, false, "Help");

    String header = "Cron expressions validation by cron-utils\n\n";
    String footer = "\nPlease report issues at https://github.com/jmrozanec/cron-utils/issues";

    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = parser.parse(options, args);
    if (cmd.hasOption(HELP) || cmd.getOptions().length == 0) {
        showHelp(options, header, footer);
        return;//from  www  . jav  a2s.c  o  m
    }
    if (!cmd.hasOption("validate")) {
        showHelp(options, header, footer);
        return;
    }
    if (cmd.hasOption('v')) {
        String format = cmd.getOptionValue("f");
        String expression = cmd.getOptionValue("e");

        CronType cronType = CronType.valueOf(format);
        CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(cronType);
        CronParser cronParser = new CronParser(cronDefinition);
        Cron quartzCron = cronParser.parse(expression);
        quartzCron.validate();
    }
}

From source file:edu.indiana.d2i.htrc.test.TestSuite.java

public static void testCommandLineParser(String[] args) throws IOException {
    GenericOptionsParser parser = new GenericOptionsParser(new Configuration(), args);

    CommandLine commandLine = parser.getCommandLine();

    Option[] options = commandLine.getOptions();

    for (Option op : options) {
        System.out.println(String.format("optName=%s, optValue=%s", op.getOpt(), op.getValue()));
    }/*from  w ww . ja  v  a2s  . c  o m*/

    // second application argument is the output folder prefix
    String[] appArgs = parser.getRemainingArgs();

    for (String appArg : appArgs) {
        System.out.println(String.format("appArg=%s", appArg));
    }

    int iterationNum = 0;

    String[] arguments = LDAAnalysisDriver.generateArgs(options, new String[0], appArgs[0],
            appArgs[1] + "-iter-" + iterationNum);

    System.out.println("Passed in arguments in the first iteration");
    for (String arg : arguments) {
        System.out.println(String.format("argument=%s", arg));
    }

    String[] otherOps = { "-D", "user.args.lda.state.filepath=" + appArgs[1] + "-iter-" + iterationNum
            + File.separator + "part-r-00000" };

    arguments = LDAAnalysisDriver.generateArgs(options, otherOps, appArgs[0],
            appArgs[1] + "-iter-" + ++iterationNum);

    System.out.println("Passed in arguments in the second iteration");
    for (String arg : arguments) {
        System.out.println(String.format("argument=%s", arg));
    }
}

From source file:com.teradata.benchto.driver.DriverApp.java

private static void exposeArgumentsAsPropertiesForSpring(CommandLine commandLine) {
    for (Option option : commandLine.getOptions()) {
        System.setProperty(option.getLongOpt(), option.getValue());
    }/*from w  w w.  ja  va  2s  .c o m*/
}

From source file:com.zimbra.common.util.CliUtil.java

/**
 * Looks up an <tt>Option</tt> by its short or long name.  This workaround is necessary
 * because <tt>CommandLine.hasOption()</tt> doesn't support long option names.
 *///from  w  w  w.  j a v a2s . c o  m
public static Option getOption(CommandLine cl, String name) {
    for (Option opt : cl.getOptions()) {
        if (StringUtil.equal(opt.getOpt(), name) || StringUtil.equal(opt.getLongOpt(), name)) {
            return opt;
        }
    }
    return null;
}

From source file:fall2015.b565.wisBreastCancer.Assignment2.java

public static void parseArguments(String[] args) throws Exception {
    try {/*from   w w w. ja va 2s  .co m*/
        Options options = new Options();

        options.addOption("c", false, "To find correlation between the attributes");
        options.addOption("ppv", true,
                "Find ppv when considering all the attributes. You should provide which cleaning method to be used - removing (rm), replace (rp)");
        options.addOption("powPPV", true,
                "Find ppv of the power set of the attributes.  You should provide which cleaning method to be used - removing (rm), replace (rp)");
        options.addOption("vfold", true,
                "V Fold cross validation.  You should provide which cleaning method to be used - removing (rm), replace (rp)");

        CommandLineParser parser = new PosixParser();
        CommandLine cmd = parser.parse(options, args);
        if (cmd.getOptions() == null || cmd.getOptions().length == 0) {
            System.out.println(
                    "You have not specified any options. Please provide one of the options : c, ppv, powPPV or vfold");
            throw new Exception(
                    "You have not specified any options. Please provide one of the options : c, ppv, powPPV or vfold");
        }
        if (cmd.hasOption("c")) {
            logger.info("Finding correlation between attributes...");
            correlation = true;
        } else if (cmd.hasOption("ppv")) {
            String optionValue = cmd.getOptionValue("ppv");
            if (optionValue == null) {
                System.out.println(
                        "User forget to give which data cleaning method to use. Hence we assume, we use replace data set");
            } else
                useReplaceDataSet = !optionValue.equals("rm");

            System.out.println("Finding PPV considering all the attributes with data clean method : "
                    + optionValue + "...");
            ppv = true;
        } else if (cmd.hasOption("powPPV")) {
            String optionValue = cmd.getOptionValue("powPPV");
            if (optionValue == null) {
                System.out.println(
                        "User forget to give which data cleaning method to use. Hence we assume, we use replace data set");
            } else
                useReplaceDataSet = !optionValue.equals("rm");
            System.out.println("Finding PPV for the power set of the attributes with data clean method : "
                    + optionValue + "...");
            powerSetPPV = true;
        } else if (cmd.hasOption("vfold")) {
            String optionValue = cmd.getOptionValue("vfold");
            if (optionValue == null) {
                System.out.println(
                        "User forget to give which data cleaning method to use. Hence we assume, we use replace data set");
            } else
                useReplaceDataSet = !optionValue.equals("rm");
            System.out.println(
                    "Finding VFold cross validation considering all the attributes with data clean method : "
                            + optionValue + "...");
            vfoldCrossValidation = true;
        }
    } catch (ParseException e) {
        logger.error("Error while reading command line parameters", e);
        throw new Exception("Error while reading command line parameters", e);
    }
}

From source file:de.huberlin.german.korpling.laudatioteitool.App.java

private static void fillPropertiesFromCommandLine(Properties props, CommandLine cmd) {
    for (Object o : cmd.getOptions()) {
        Option opt = (Option) o;
        String name = opt.getOpt();
        if (cmd.hasOption(opt.getOpt())) {
            String value = cmd.getOptionValue(name);
            props.put(name, value);/*from w  ww . j  a va 2  s .co m*/
            log.debug(messages.getString("SETTING OPTION FROM CMD"), name, value);
        }
    }
}

From source file:com.ztesoft.zsmart.remoting.util.ServerUtil.java

/**
 * Description:commandLine -> properties <br>
 * //from   w  w  w  .ja va 2 s  . c  o m
 * @author wang.jun<br>
 * @taskId <br>
 * @param commandLine
 * @return <br>
 */
public static Properties commandLine2Properties(final CommandLine commandLine) {
    Properties properties = new Properties();
    Option[] opts = commandLine.getOptions();

    if (opts != null) {
        for (Option opt : opts) {
            String name = opt.getLongOpt();
            String value = commandLine.getOptionValue(name);
            if (value != null) {
                properties.setProperty(name, value);
            }
        }
    }
    return properties;
}

From source file:hivemall.optimizer.OptimizerOptions.java

public static void processOptions(@Nullable CommandLine cl, @Nonnull Map<String, String> options) {
    if (cl == null) {
        return;//  w w w .  j a  v  a  2 s.  c o  m
    }
    for (Option opt : cl.getOptions()) {
        String optName = opt.getLongOpt();
        if (optName == null) {
            optName = opt.getOpt();
        }
        options.put(optName, opt.getValue());
    }
}