Package org.apache.commons.cli2.validation

Examples of org.apache.commons.cli2.validation.Validator


//    if (a == null) a = element.getLayoutFactory().getActivator();
    MActivator a = element.getLayoutFactory().getActivator();
   
    String[] va = string.split(",");
    for (String v : va) {
      Validator validator;
      try {
        validator = (Validator) a.getObject(Validator.class,v);
      } catch (Exception e) {
        e.printStackTrace();
        return false;
      }
      if (validator != null && !validator.validate(this,element,value))
        return false;
    }
    return true;
  }
View Full Code Here


    gBuilder.withOption(oBuilder.reset().withId(OPTION_QS).withShortName("qs").withLongName("querysilent").withDescription(
        "Silent Query the status of an NT service or Unix daemon").create());
    gBuilder.withOption(oBuilder.reset().withId(OPTION_QX).withShortName("qx").withLongName("queryposix").withDescription(
        "Query the status of a posix daemon. Return status as exit code").create());

    Argument pid = aBuilder.reset().withName(PID).withDescription("PID of process to reconnect to").withMinimum(1).withMaximum(1).withValidator(
        NumberValidator.getIntegerInstance()).create();

    gBuilder.withOption(oBuilder.reset().withId(OPTION_N).withShortName("n").withLongName("reconnect").withDescription(
        "recoNnect to existing application").withArgument(pid).create());

    Argument pid2 = aBuilder.reset().withName(PID).withDescription("PID of process to reconnect to").withMinimum(1).withMaximum(1).withValidator(
        NumberValidator.getIntegerInstance()).create();

    Argument defaultFile = aBuilder.reset().withName(DEFAULT_FILE).withDescription("Default Configuration File").withMinimum(0).withMaximum(1)
        .withValidator(VFSFileValidator.getExistingFileInstance().setBase(".")).create();
    /*
     * GroupBuilder childGbuilder = new GroupBuilder(); DefaultOptionBuilder
     * childoObuilder = new DefaultOptionBuilder("-", "--", true);
     *
 
View Full Code Here

    try {
      Parser parser = new Parser();
     
      parser.setGroup(group);
      parser.setHelpOption(helpOpt);
      CommandLine cmdLine = parser.parse(args);
      if (cmdLine.hasOption(helpOpt)) {
        CommandLineUtil.printHelp(group);
        return;
      }
     
      String inputPath  = (String) cmdLine.getValue(inputDirOpt);
      String outputPath = (String) cmdLine.getValue(outputOpt);
      TrainMaxent trainer = new TrainMaxent();
      trainer.train(inputPath, outputPath);
    }
    catch (OptionException e) {
      log.error("Error while parsing options", e);
View Full Code Here

    try {
      Parser parser = new Parser();
     
      parser.setGroup(group);
      parser.setHelpOption(helpOpt);
      CommandLine cmdLine = parser.parse(args);
      if (cmdLine.hasOption(helpOpt)) {
        CommandLineUtil.printHelp(group);
        return;
      }

      String inputPath  = (String) cmdLine.getValue(inputDirOpt);
      File f = new File(inputPath);
      if (!f.isDirectory()) {
        throw new IllegalArgumentException(f + " is not a directory or does not exit");
      }
      File[] inputFiles = FileUtil.buildFileList(f);
     
      File   modelDir  = new File((String) cmdLine.getValue(modelOpt));
      execute(inputFiles, modelDir);
    } catch (OptionException e) {
      log.error("Error while parsing options", e);
    }
   
View Full Code Here

    try {
      Parser parser = new Parser();
     
      parser.setGroup(group);
      parser.setHelpOption(helpOpt);
      CommandLine cmdLine = parser.parse(args);
      if (cmdLine.hasOption(helpOpt)) {
        CommandLineUtil.printHelp(group);
        return;
      }
     
      String classifierType = (String) cmdLine.getValue(typeOpt);

      int gramSize = 1;
      if (cmdLine.hasOption(gramSizeOpt)) {
        gramSize = Integer.parseInt((String) cmdLine.getValue(gramSizeOpt));
      }

      int maxResults = 10;
      if (cmdLine.hasOption(maxResultsOpt)) {
        maxResults = Integer.parseInt((String) cmdLine.getValue(maxResultsOpt));
      }
     
      String inputPath  = (String) cmdLine.getValue(inputDirOpt);
      String modelPath = (String) cmdLine.getValue(modelOpt);
      String categoryField = (String) cmdLine.getValue(categoryFieldOpt);
      String contentField = (String) cmdLine.getValue(contentFieldOpt);
     
      MatchMode mode;
     
      if ("knn".equalsIgnoreCase(classifierType)) {
        mode = MatchMode.KNN;
View Full Code Here

      .create();
   
    try {
      Parser parser = new Parser();
      parser.setGroup(group);
      CommandLine cmdLine = parser.parse(args);
     
      if (cmdLine.hasOption(helpOpt)) {
        CommandLineUtil.printHelp(group);
        return;
      }

      File inputDir = new File(cmdLine.getValue(inputOpt).toString());
     
      if (!inputDir.isDirectory()) {
        throw new IllegalArgumentException(inputDir + " does not exist or is not a directory");
      }
     
      File categoryFile = new File(cmdLine.getValue(categoryOpt).toString());
     
      if (!categoryFile.isFile()) {
        throw new IllegalArgumentException(categoryFile + " does not exist or is not a directory");
      }
     
      File outputDir = new File(cmdLine.getValue(outputOpt).toString());
     
      outputDir.mkdirs();
     
      if (!outputDir.isDirectory()) {
        throw new IllegalArgumentException(outputDir + " is not a directory or could not be created");
      }

      Collection<String> categoryFields = stringToList(cmdLine.getValue(categoryFieldsOpt).toString());
     
      if (categoryFields.size() < 1) {
        throw new IllegalArgumentException("At least one category field must be spcified.");
      }
     
      Collection<String> textFields = stringToList(cmdLine.getValue(textFieldsOpt).toString());

      if (categoryFields.size() < 1) {
        throw new IllegalArgumentException("At least one text field must be spcified.");
      }
     
      boolean useTermVectors = cmdLine.hasOption(useTermVectorsOpt);
     
      extractTraininingData(inputDir, categoryFile, categoryFields, textFields, outputDir, useTermVectors);
     
    } catch (OptionException e) {
      log.error("Exception", e);
View Full Code Here

         .withOption(testOutputOpt).withOption(trainingDataSizeOpt).withOption(testDataSizeOpt).create();
   
    try {
      Parser parser = new Parser();
      parser.setGroup(group);
      CommandLine cmdLine = parser.parse(args);
     
      if (cmdLine.hasOption(helpOpt)) {
        CommandLineUtil.printHelp(group);
        return false;
      }
     
      inputFile = new File((String) cmdLine.getValue(inputFileOpt));
      trainingOutputFile = new File((String) cmdLine.getValue(trainingOutputOpt));
      testOutputFile = new File((String) cmdLine.getValue(testOutputOpt));

      if (cmdLine.hasOption(trainingDataSizeOpt)) {
        trainingDataSize = Integer.parseInt((String) cmdLine.getValue(trainingDataSizeOpt));
      }
     
      if (cmdLine.hasOption(testDataSizeOpt)) {
        testDataSize = Integer.parseInt((String) cmdLine.getValue(testDataSizeOpt));
      }    
     
    } catch (OptionException e) {
      log.error("Command-line option Exception", e);
      CommandLineUtil.printHelp(group);
View Full Code Here

      .withOption(solrUrlOpt).create();
   
    try {
      Parser parser = new Parser();
      parser.setGroup(group);
      CommandLine cmdLine = parser.parse(args);
     
      if (cmdLine.hasOption(helpOpt)) {
        CommandLineUtil.printHelp(group);
        return false;
      }
     
      inputFile  = new File((String) cmdLine.getValue(inputFileOpt));
      countFile  = new File((String) cmdLine.getValue(countFileOpt));
      outputFile = new File((String) cmdLine.getValue(outputFileOpt));
      solrUrl    = (String) cmdLine.getValue(solrUrlOpt);
      client     = new TagRecommenderClient(solrUrl);
    } catch (OptionException e) {
      log.error("Command-line option Exception", e);
      CommandLineUtil.printHelp(group);
      return false;
View Full Code Here

   
    try {
      Parser parser = new Parser();
      parser.setGroup(group);
      CommandLine cmdLine = parser.parse(args);
     
      if (cmdLine.hasOption(helpOpt)) {
        CommandLineUtil.printHelp(group);
        return false;
      }
     
      inputFile = new File((String) cmdLine.getValue(inputFileOpt));
      countFile = new File((String) cmdLine.getValue(outputFileOpt));

      if (cmdLine.hasOption(limitOpt)) {
        limit = Integer.parseInt((String) cmdLine.getValue(limitOpt));
      }
     
      if (cmdLine.hasOption(cutoffOpt)) {
        cutoff = Integer.parseInt((String) cmdLine.getValue(cutoffOpt));
      }    
     
    } catch (OptionException e) {
      log.error("Command-line option Exception", e);
      CommandLineUtil.printHelp(group);
View Full Code Here

    .create();
   
    try {
      Parser parser = new Parser();
      parser.setGroup(group);
      CommandLine cmdLine = parser.parse(args);
     
      if (cmdLine.hasOption(helpOpt)) {
        CommandLineUtil.printHelp(group);
        return;
      }
     
      File inputFile = new File(cmdLine.getValue(inputOpt).toString());
     
      if (!inputFile.isFile()) {
        throw new IllegalArgumentException(inputFile + " does not exist or is not a file");
      }
     
      File modelDir = new File(cmdLine.getValue(modelOpt).toString());
     
      if (!modelDir.isDirectory()) {
        throw new IllegalArgumentException(modelDir + " does not exist or is not a directory");
      }
     
View Full Code Here

TOP

Related Classes of org.apache.commons.cli2.validation.Validator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.