Package com.martiansoftware.jsap

Examples of com.martiansoftware.jsap.JSAPResult


            new FlaggedOption( "bufferSize", JSAP.INTSIZE_PARSER, DEFAULT_BUFFER_SIZE, JSAP.NOT_REQUIRED, 'b', "buffer-size", "The size of an I/O buffer." ),
            new UnflaggedOption( "collection", JSAP.STRING_PARSER, JSAP.REQUIRED, "The filename for the serialised collection." ),
            new UnflaggedOption( "file", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, JSAP.GREEDY, "A list of files that will be indexed. If missing, a list of files will be read from standard input." )
    } );

    JSAPResult jsapResult = jsap.parse( arg );
    if ( jsap.messagePrinted() ) return;

    final DocumentFactory userFactory = PropertyBasedDocumentFactory.getInstance( jsapResult.getClass( "factory" ), jsapResult.getStringArray( "property" ) );

    String[] file = jsapResult.getStringArray( "file" );
    if ( file.length == 0 ) {
      final ObjectArrayList<String> files = new ObjectArrayList<String>();
      BufferedReader bufferedReader = new BufferedReader( new InputStreamReader( System.in ) );
      String s;
      while ( ( s = bufferedReader.readLine() ) != null ) files.add( s );
      file = files.toArray( new String[ 0 ] );
    }

    // To avoid problems with find and similar utilities, we sort the file names
    if ( !jsapResult.getBoolean( "unsorted" ) ) Arrays.sort( file );

    final DocumentFactory composite = CompositeDocumentFactory.getFactory( new TRECHeaderDocumentFactory(), userFactory );

    if ( file.length == 0 ) System.err.println( "WARNING: empty file set." );
    BinIO.storeObject( new TRECDocumentCollection( file, composite, jsapResult.getInt( "bufferSize" ), jsapResult.getBoolean( "gzipped" ) ), jsapResult.getString( "collection" ) );
  }
View Full Code Here


          new UnflaggedOption( "file", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, JSAP.GREEDY, "A list of files that will be indexed. If missing, a list of files will be read from standard input." )
        }
    );
   

    JSAPResult jsapResult = jsap.parse( arg );
    if ( jsap.messagePrinted() ) return;
   
    /*String uri[] = null;
    if ( jsapResult.getString( "uris" ) != null ) {
      Collection<MutableString> lines = new FileLinesCollection( jsapResult.getString( "uris" ), "ASCII" ).allLines();
      uri = new String[ lines.size() ];
      int i = 0;
      for( Object l: lines ) uri[ i++ ] = l.toString();
    }*/
   
    final DocumentFactory factory = new IdentityDocumentFactory( new Reference2ObjectOpenHashMap<Enum<?>,Object>(
        new PropertyBasedDocumentFactory.MetadataKeys[] { PropertyBasedDocumentFactory.MetadataKeys.ENCODING, PropertyBasedDocumentFactory.MetadataKeys.WORDREADER },
        new Object[] { "UTF-8", WhitespaceWordReader.class.getName() } ) );
   
    String[] file = (String[])jsapResult.getObjectArray( "file", new String[ 0 ] );
    if ( file.length == 0 ) {
      final ObjectArrayList<String> files = new ObjectArrayList<String>();
      BufferedReader bufferedReader = new BufferedReader( new InputStreamReader( System.in ) );
      String s;
      while( ( s = bufferedReader.readLine() ) != null ) files.add( s );
      file = files.toArray( new String[ 0 ] );
    }
   
    if ( file.length == 0 ) System.err.println( "WARNING: empty file set." );
    //if ( uri != null && file.length != uri.length ) throw new IllegalArgumentException( "The number of files (" + file.length + ") and the number of URIs (" + uri.length + ") differ" );
    BinIO.storeObject( new WikipediaDocumentCollection( file, ReplicatedDocumentFactory.getFactory( factory, NUM_FIELDS, FIELD_NAME ), jsapResult.getBoolean( "sentence"), jsapResult.getBoolean( "gzipped" ) ), jsapResult.getString( "collection" ) );
  }
View Full Code Here

          new Switch( "approximated", 'a', "approximated", "If specified, non-words will not be copied." ),
          new FlaggedOption( "logInterval", JSAP.LONG_PARSER, Long.toString( ProgressLogger.DEFAULT_LOG_INTERVAL ), JSAP.NOT_REQUIRED, 'l', "log-interval", "The minimum time interval between activity logs in milliseconds." ),
          new UnflaggedOption( "basename", JSAP.STRING_PARSER, JSAP.REQUIRED, "The basename for the collection." ),
        }
    );
    JSAPResult jsapResult = jsap.parse( arg );
    if ( jsap.messagePrinted() ) return;

    DocumentSequence documentSequence = Scan.getSequence( jsapResult.getString( "sequence" ), jsapResult.getClass( "factory" ), jsapResult.getStringArray( "property" ), jsapResult.getInt( "delimiter" ), LOGGER );
    final ProgressLogger progressLogger = new ProgressLogger( LOGGER, "documents" );
    if ( documentSequence instanceof DocumentCollection ) progressLogger.expectedUpdates = ((DocumentCollection)documentSequence).size();
    final ZipDocumentCollectionBuilder zipDocumentCollectionBuilder = new ZipDocumentCollectionBuilder( jsapResult.getString( "basename" ), documentSequence.factory(), !jsapResult.getBoolean( "approximated") );
    zipDocumentCollectionBuilder.open( "" );
    zipDocumentCollectionBuilder.build( documentSequence );
  }
View Full Code Here

            new FlaggedOption("nfile", JSAP.STRING_PARSER, null, JSAP.NOT_REQUIRED, 'n', JSAP.NO_LONGFLAG,
                "Location of influenza_na.dat") });
    if (jsap.messagePrinted())
      System.exit(1);

    JSAPResult config = jsap.parse(args);
    InfluenzaDataLoader fluDemo = new InfluenzaDataLoader();
    try {
      fluDemo.createCache(config.getString("InfinispanCfg"));
      fluDemo.populateCache(config);
    } catch (SAXException e1) {
      e1.printStackTrace();
      System.exit(1);
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(2);
    }

    while (true) {
      if (config.getBoolean("query")) {
        System.out.print("Enter Virus Genbank Accession Number: ");
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String GBAN = null;
        try {
          GBAN = br.readLine();
View Full Code Here

   }

   protected JSAPResult parseParameters(String[] args) throws Exception {
      SimpleJSAP jsap = buildCommandLineOptions();

      JSAPResult config = jsap.parse(args);
      if (!config.success() || jsap.messagePrinted()) {
         Iterator<?> messageIterator = config.getErrorMessageIterator();
         while (messageIterator.hasNext()) System.err.println(messageIterator.next());
         System.err.println(jsap.getHelp());
         return null;
      }
View Full Code Here

                      .setRequired(false)
                      .setGreedy(false);
   
    jsap.registerParameter(val);
   
    JSAPResult config = jsap.parse(args);
       
    usage(jsap, config);
   
    String subCmd = config.getString("command");

    if (subCmd.equals(CMD_GET)) {
      processKey(config.getString("key"));
     
    } else if (subCmd.equals(CMD_LIST)) {
      if (config.getBoolean("local"))
        processListLocal();
      else
        processList();
    } else if (subCmd.equals(CMD_SET)) {
      String propKey = config.getString("key");
      String propVal = config.getString("value");
      if ( ( propKey==null) || (propVal == null)) {
        logger.error("either property key or proerty value is missing!");
        System.exit(1);
      }
      processSet(propKey, propVal);
View Full Code Here

* @author Christophe Pollet
*/
public class Main {
    public static void main(String[] args) throws ParserException, IOException, DateTimeException, JSAPException {
        JSAP jsap = new ArgumentsParser();
        JSAPResult config = jsap.parse(args);

        if (!config.success() || config.getBoolean("help")) {
            System.out.println();
            for (Iterator errs = config.getErrorMessageIterator(); errs.hasNext();) {
                System.out.println("Error: " + errs.next());
            }
            System.out.println();
            System.out.println("Usage: java " + Main.class.getName());
            System.out.println("\t" + jsap.getUsage());
            System.out.println();
            System.out.println(jsap.getHelp());
            System.exit(0);
        }

        Database database = new Database();
        Parser parser     = new Parser(database);
        Compiler compiler = new Compiler(database);
        Writer writer = new Writer(database);

        parser.parse(config.getStringArray("inputFiles"));

        //todo: implement
//        compiler.setMinYear(config.getInt("minYear"));
//        compiler.setMaxYear(config.getInt("maxYear"));
        compiler.compile();

//        database.dump();

        writer.write(config.getString("outputPath"),
                     config.getStringArray("outputFormats"),
                     config.getBoolean("singleFile"));
    }
View Full Code Here

            new FlaggedOption("nfile", JSAP.STRING_PARSER, null, JSAP.NOT_REQUIRED, 'n', JSAP.NO_LONGFLAG,
                "Location of influenza_na.dat") });
    if (jsap.messagePrinted())
      System.exit(1);

    JSAPResult config = jsap.parse(args);
    InfluenzaDataLoader fluDemo = new InfluenzaDataLoader();
    try {
      fluDemo.createCache(config.getString("InfinispanCfg"));
      fluDemo.populateCache(config);
    } catch (SAXException e1) {
      e1.printStackTrace();
      System.exit(1);
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(2);
    }

    while (true) {
      if (config.getBoolean("query")) {
        System.out.print("Enter Virus Genbank Accession Number: ");
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String GBAN = null;
        try {
          GBAN = br.readLine();
View Full Code Here

      }
    }
  }
 
  private String[] processGlobalCommandFlags(String[] args) {
    JSAPResult parsedArgs;
    int i = 0;
    while(i < args.length) {
      parsedArgs = argsParser.parse(Arrays.copyOfRange(args, i, args.length));
     
      if(parsedArgs.success()) {
        args = Arrays.copyOfRange(args, 0, i);
        processedParsedArgs(parsedArgs);
        break;
      }
      ++i;
View Full Code Here

    return argsParser.getHelp();
  }
 
  @Override
  public final int doCommand(String... args) throws CommandArgumentsException, CommandOperationException {
    JSAPResult parsedArgs = parseArgs(args);
    return doCommand(parsedArgs);
  }
View Full Code Here

TOP

Related Classes of com.martiansoftware.jsap.JSAPResult

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.