Package com.martiansoftware.jsap

Examples of com.martiansoftware.jsap.JSAPResult


          new FlaggedOption( "itemMimeType", JSAP.STRING_PARSER, "text/html", JSAP.NOT_REQUIRED, 'm', "item-mime-type", "A MIME type suggested to the class handling item display in the HTTP server." ),
          new FlaggedOption( "port", JSAP.INTEGER_PARSER, "4242", JSAP.NOT_REQUIRED, 'p', "port", "The port on localhost where the server will appear." ),
          new UnflaggedOption( "basenameWeight", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.GREEDY, "The indices that the servlet will use. Indices are specified using their basename, optionally followed by a colon and a double representing the weight used to score results from that index. Indices without a specified weight are weighted 1." )
      });

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

    final DocumentCollection documentCollection = (DocumentCollection)(jsapResult.userSpecified( "collection" ) ? AbstractDocumentSequence.load( jsapResult.getString( "collection" ) ) :
      jsapResult.userSpecified( "objectCollection" ) ? jsapResult.getObject( "objectCollection" ): null );
    final List<? extends CharSequence> titleList = (List<? extends CharSequence>) (
        jsapResult.userSpecified( "titleList" ) ? BinIO.loadObject( jsapResult.getString( "titleList" ) ) :
          jsapResult.userSpecified( "titleFile" ) ? new FileLinesList( jsapResult.getString( "titleFile" ), "UTF-8" ) :
            null );    final String[] basenameWeight = jsapResult.getStringArray( "basenameWeight" );
    final Object2ReferenceLinkedOpenHashMap<String,Index> indexMap = new Object2ReferenceLinkedOpenHashMap<String,Index>( Hash.DEFAULT_INITIAL_SIZE, .5f );
    final Reference2DoubleOpenHashMap<Index> index2Weight = new Reference2DoubleOpenHashMap<Index>();
    final boolean verbose = jsapResult.getBoolean( "verbose" );
    final boolean loadSizes = ! jsapResult.getBoolean( "noSizes" );
    Query.loadIndicesFromSpec( basenameWeight, loadSizes, documentCollection, indexMap, index2Weight );
   
    final Object2ObjectOpenHashMap<String,TermProcessor> termProcessors = new Object2ObjectOpenHashMap<String,TermProcessor>( indexMap.size() );
    for( String alias: indexMap.keySet() ) termProcessors.put( alias, indexMap.get( alias ).termProcessor );
   
    final SimpleParser simpleParser = new SimpleParser( indexMap.keySet(), indexMap.firstKey(), termProcessors );

    final Reference2ReferenceMap<Index, Object> index2Parser = new Reference2ReferenceOpenHashMap<Index, Object>();
    /*
    // Fetch parsers for payload-based fields.
    for( Index index: indexMap.values() ) if ( index.hasPayloads ) {
      if ( index.payload.getClass() == DatePayload.class ) index2Parser.put( index, DateFormat.getDateInstance( DateFormat.SHORT, Locale.UK ) );
    }
    */
   
    final QueryEngine queryEngine = new QueryEngine( simpleParser, new DocumentIteratorBuilderVisitor( indexMap, index2Parser, indexMap.get( indexMap.firstKey() ), MAX_STEMMING ), indexMap );
    queryEngine.setWeights( index2Weight );
    queryEngine.score( new Scorer[] { new BM25Scorer(), new VignaScorer() }, new double[] { 1, 1 } );
    // We set up an interval selector only if there is a collection for snippeting
    queryEngine.intervalSelector = documentCollection != null ? new IntervalSelector( 4, 40 ) : new IntervalSelector();
    queryEngine.multiplex = true;
    queryEngine.equalize( 1000 );
   
    Query query = new Query( queryEngine );
    query.displayMode = OutputType.SNIPPET;
   
    String q;

    System.err.println( "Welcome to the MG4J query class (setup with $mode snippet, $score BM25Scorer VignaScorer, $mplex on, $equalize 1000, $select " + ( documentCollection != null "4 40" : "all" ) + ")" );
    System.err.println( "Please type $ for help." );
   
    String prompt = indexMap.keySet().toString() + ">";
    int n;
   
    HttpQueryServer httpQueryServer = null;
    if ( jsapResult.getBoolean( "http" ) ) httpQueryServer = new HttpQueryServer( queryEngine, documentCollection, jsapResult.getClass( "itemClass" ), jsapResult.getString( "itemMimeType" ), jsapResult.getInt( "port" ), titleList );
    try {
      final BufferedReader br = new BufferedReader( new InputStreamReader( jsapResult.userSpecified( "input" ) ? new FileInputStream( jsapResult.getString( "input") ) : System.in ) );
      final ObjectArrayList<DocumentScoreInfo<Reference2ObjectMap<Index,SelectedInterval[]>>> results = new ObjectArrayList<DocumentScoreInfo<Reference2ObjectMap<Index,SelectedInterval[]>>>();
     
      for ( ;; ) {
        System.out.print( prompt );
        q = br.readLine();
View Full Code Here


        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( "outputBasename", JSAP.STRING_PARSER, JSAP.REQUIRED, "The basename of the resulting index." ),
        new UnflaggedOption( "inputBasename", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.GREEDY, "The basenames of the indices to be merged." )
    });
   
    JSAPResult jsapResult = jsap.parse( arg );
    if ( jsap.messagePrinted() ) return;

    final boolean skips = ! jsapResult.getBoolean( "noSkips" );
    final boolean interleaved = jsapResult.getBoolean( "interleaved" );
    if ( ! skips && ( jsapResult.userSpecified( "quantum" ) || jsapResult.userSpecified( "height" ) ) ) throw new IllegalArgumentException( "You specified quantum or height, but you also disabled skips." );
   
    if ( combineClass != null && jsapResult.userSpecified( "duplicates" ) || jsapResult.userSpecified( "merge") )
      throw new IllegalArgumentException( "When invoking " + Combine.class.getName() + " from " + combineClass.getName() + " you cannot choose the combination process" );
   
    final String[] inputBasename;
    if ( jsapResult.getBoolean( "properties" ) ) {
      if ( jsapResult.getStringArray( "inputBasename" ).length > 1 ) throw new IllegalArgumentException( "When using --properties, you must specify exactly one inputBasename" );
      inputBasename = new Properties( jsapResult.getStringArray( "inputBasename" )[ 0 ] + Scan.CLUSTER_PROPERTIES_EXTENSION ).getStringArray( IndexCluster.PropertyKeys.LOCALINDEX );
    }
    else inputBasename = jsapResult.getStringArray( "inputBasename" );
    // TODO: resolve problem of passing default flag values without knowing type of index
    ( combineClass == Paste.class || jsapResult.getBoolean( "duplicates" ) ?
    (Combine)new Paste( jsapResult.getString( "outputBasename" ),
        inputBasename,
        jsapResult.getBoolean( "metadataOnly" ),
        jsapResult.getBoolean( "incremental" ),
        jsapResult.getInt( "bufferSize" ),
        jsapResult.getFile( "tempFileDir" ),
        jsapResult.getInt( "tempFileBufferSize" ),
        CompressionFlags.valueOf( jsapResult.getStringArray( "comp" ), CompressionFlags.DEFAULT_STANDARD_INDEX ),
        interleaved,
        skips,
        jsapResult.getInt( "quantum" ),
        jsapResult.getInt( "height" ),
        jsapResult.getInt( "skipBufferSize" ),
        jsapResult.getLong( "logInterval" ) ) :
    combineClass == Merge.class || jsapResult.getBoolean( "merge" ) ?
        (Combine)new Merge( jsapResult.getString( "outputBasename" ),
            inputBasename,
            jsapResult.getBoolean( "metadataOnly" ),
            jsapResult.getInt( "bufferSize" ),
            CompressionFlags.valueOf( jsapResult.getStringArray( "comp" ), CompressionFlags.DEFAULT_STANDARD_INDEX ),
            interleaved,
            skips,
            jsapResult.getInt( "quantum" ),
            jsapResult.getInt( "height" ),
            jsapResult.getInt( "skipBufferSize" ),
            jsapResult.getLong( "logInterval" ) ) :
              (Combine)new Concatenate( jsapResult.getString( "outputBasename" ),
                  inputBasename,
                  jsapResult.getBoolean( "metadataOnly" ),
                  jsapResult.getInt( "bufferSize" ),
                  CompressionFlags.valueOf( jsapResult.getStringArray( "comp" ), CompressionFlags.DEFAULT_STANDARD_INDEX ),
                  interleaved,
                  skips,
                  jsapResult.getInt( "quantum" ),
                  jsapResult.getInt( "height" ),
                  jsapResult.getInt( "skipBufferSize" ),
                  jsapResult.getLong( "logInterval" ) )
                 
    ).run();
  }
View Full Code Here

            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 FlaggedOption( "tempDir", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'T', "temp-dir", "A directory for all temporary files (e.g., batches)." ),
            new UnflaggedOption( "basename", JSAP.STRING_PARSER, JSAP.REQUIRED, "The basename of the resulting index." ) } );

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

    if ( ( jsapResult.userSpecified( "builderClass" ) || jsapResult.userSpecified( "exact" ) ) && ! jsapResult.userSpecified( "buildCollection" ) )  throw new IllegalArgumentException( "To specify options about the collection building process, you must specify a basename first." );
    if ( jsapResult.userSpecified( "sequence" ) && jsapResult.userSpecified( "objectSequence" ) ) throw new IllegalArgumentException( "You cannot specify both a serialised and an parseable-object sequence" );
   
    final DocumentSequence documentSequence = jsapResult.userSpecified( "objectSequence" ) ? (DocumentSequence)jsapResult.getObject( "objectSequence" ) : Scan.getSequence( jsapResult.getString( "sequence" ), jsapResult.getClass( "factory" ), jsapResult.getStringArray( "property" ), jsapResult.getInt( "delimiter" ), LOGGER );

    final DocumentFactory factory = documentSequence.factory();
    final int[] indexedField = parseFieldNames( jsapResult.getStringArray( "indexedField" ), factory, jsapResult.getBoolean( "allFields" ) );
    final int batchSize = jsapResult.getInt( "batchSize" );
    final VirtualDocumentResolver[] virtualDocumentResolver = parseVirtualDocumentResolver( jsapResult.getStringArray( "virtualDocumentResolver" ), indexedField, factory );
    final int[] virtualDocumentGap = parseVirtualDocumentGap( jsapResult.getStringArray( "virtualDocumentGap" ), indexedField, factory );

    DocumentCollectionBuilder builder = null;
    if ( jsapResult.userSpecified( "buildCollection" ) ) {
      final Class<? extends DocumentCollectionBuilder> builderClass = jsapResult.getClass( "builderClass" );
      builder = builderClass != null ? builderClass.getConstructor( String.class, DocumentFactory.class, boolean.class ).newInstance(
          jsapResult.getString( "buildCollection" ),
          documentSequence.factory().numberOfFields() == indexedField.length ? documentSequence.factory().copy() : new SubDocumentFactory( documentSequence.factory().copy(), indexedField ),
          Boolean.valueOf( jsapResult.getBoolean( "exact" ) ) ) : null;
    }

    run( jsapResult.getString( "basename" ), documentSequence, Completeness.valueOf( jsapResult.getString( "completeness" ) ), jsapResult.getBoolean( "downcase" ) ? DowncaseTermProcessor.getInstance() : ObjectParser.fromSpec( jsapResult
        .getString( "termProcessor" ), TermProcessor.class, MG4JClassParser.PACKAGE, new String[] { "getInstance" } ), builder, jsapResult
        .getInt( "bufferSize" ), batchSize, jsapResult.getInt( "maxTerms" ), indexedField, virtualDocumentResolver, virtualDocumentGap, jsapResult.getString( "renumber" ), jsapResult.getLong( "logInterval" ), jsapResult
        .getString( "tempDir" ) );
  }
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 = PropertyBasedDocumentFactory.getInstance( jsapResult.getClass( "factory" ), jsapResult.getStringArray( "property" ) );
   
    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 FileSetDocumentCollection( file, uri, factory ), jsapResult.getString( "collection" ) );
  }
View Full Code Here

        new Switch( "termsOnly", 't', "terms-only", "Just partition the term list." ),
        new UnflaggedOption( "inputBasename", JSAP.STRING_PARSER, JSAP.REQUIRED, "The basename of the global index." ),
        new UnflaggedOption( "outputBasename", JSAP.STRING_PARSER, JSAP.REQUIRED, "The basename of the local indices." )
    });
   
    JSAPResult jsapResult = jsap.parse( arg );
    if ( jsap.messagePrinted() ) return;
    String inputBasename = jsapResult.getString( "inputBasename" );
    String outputBasename = jsapResult.getString( "outputBasename" );
    String strategyFilename = jsapResult.getString( "strategy" );
    LexicalPartitioningStrategy strategy = null;

    if ( jsapResult.userSpecified( "uniformStrategy" ) ) {
      strategy = LexicalStrategies.uniform( jsapResult.getInt( "uniformStrategy" ), DiskBasedIndex.getInstance( inputBasename, false, false, true ) );
      BinIO.storeObject( strategy, strategyFilename = outputBasename + IndexCluster.STRATEGY_DEFAULT_EXTENSION );
    }
    else if ( strategyFilename != null ) strategy = (LexicalPartitioningStrategy)BinIO.loadObject( strategyFilename );
    else throw new IllegalArgumentException( "You must specify a splitting strategy" );

    final PartitionLexically partitionLexically = new PartitionLexically( inputBasename,
        outputBasename,
        strategy,
        strategyFilename,
        jsapResult.getInt( "bufferSize" ),
        jsapResult.getLong( "logInterval" ) );

   
    if ( jsapResult.getBoolean( "termsOnly" ) ) partitionLexically.runTermsOnly();
    else partitionLexically.run();
  }
View Full Code Here

          new UnflaggedOption( "storeUrl", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The javamail store." ),
          new UnflaggedOption( "folder", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The folder to be read." )
        }
    );
   
    JSAPResult jsapResult = jsap.parse( arg );
    if ( jsap.messagePrinted() ) return;
   
    BinIO.storeObject( new JavamailDocumentCollection( jsapResult.getString( "storeUrl" ), jsapResult.getString( "folder" ), jsapResult.getStringArray( "property" ) ), jsapResult.getString( "collection" ) );
  }
View Full Code Here

      new Switch( "forceremote", 'f', "force-remote", "Forces a remote index instead of a remote bitstream index." ),
      new UnflaggedOption( "ipaddr", JSAP.INETADDRESS_PARSER, JSAP.REQUIRED, "The server address." ),
      new UnflaggedOption( "basename", JSAP.STRING_PARSER, JSAP.REQUIRED, "The basename or uri of the index" )
    } );
   
    JSAPResult jsapResult = jsap.parse( arg );
    if ( jsap.messagePrinted() ) return;
   
    int port = jsapResult.getInt( "port" );
    String basename = jsapResult.getString( "basename" );
    boolean forceRemote = jsapResult.getBoolean( "forceremote" );
    start( Index.getInstance( basename ), jsapResult.getInetAddress( "ipaddr"), port, forceRemote );
  }
View Full Code Here

    SimpleJSAP jsap = new SimpleJSAP( "java IndexIteratorTest", "Compare IndexIterator of equals indexes." +
        "\nGiven two index basename, IndexIteratorTest compare that every IndexIterator method give the same results.", new Parameter[] {
        new UnflaggedOption( "basename_1", JSAP.STRING_PARSER, JSAP.REQUIRED, "The basename of the first index." ),     
        new Switch( "text_term", 't', "use text term during document method invocation on second index" ),
        new UnflaggedOption( "basename_2", JSAP.STRING_PARSER, JSAP.REQUIRED, "The basename of the second index." )} );   
    JSAPResult jsapResult = jsap.parse( _DEBUG_SERVER ? debugServerArg :(_DEBUG_CLUSTER ? debugClusterArg : arg) );
    if(!(jsapResult.contains("basename_1") && jsapResult.contains("basename_2")))
      return;
    firstBaseName = jsapResult.getString("basename_1");
    secondBaseName = jsapResult.getString("basename_2");
    firstIndex = DiskBasedIndex.getInstance(firstBaseName,true,true);
    textTerm = jsapResult.getBoolean("text_term");
    if(_DEBUG_SERVER){
      new Thread(){
        public void run(){   
          try {
            IndexServer.start(Index.getInstance(firstBaseName),InetAddress.getLocalHost(),9090,false);
View Full Code Here

      new Parameter[] {
        new UnflaggedOption( "basename", JSAP.STRING_PARSER, JSAP.REQUIRED, "The basename of the height files." ),
        new UnflaggedOption( "h", JSAP.INTEGER_PARSER, JSAP.REQUIRED, "The maximum height to scan." )
    });

    JSAPResult jsapResult = jsap.parse( arg );
    if ( jsap.messagePrinted() ) return;
    Pattern pattern = Pattern.compile( "\t" );
    Matcher matcher = pattern.matcher( "" );
   
    final int h = jsapResult.getInt( "h" );
    final String basename = jsapResult.getString( "basename" );
    final PrintStream printStream[] = new PrintStream[ h + 1 ];
    for( int i = 0; i <= h; i++ ) printStream[ i ] = new PrintStream( new FastBufferedOutputStream( new FileOutputStream( basename + "-" + i + DiskBasedIndex.STATS_EXTENSION ) ) );
   
    final MutableString line = new MutableString();
    final FastBufferedReader reader = new FastBufferedReader( new InputStreamReader( System.in ) );
View Full Code Here

        new FlaggedOption( "docperquery", JSAP.INTEGER_PARSER, "2", JSAP.NOT_REQUIRED, 'd', "docperquery", "The number of documents per query." ),
        new FlaggedOption( "wordsperdoc", JSAP.INTEGER_PARSER, "2", JSAP.NOT_REQUIRED, 'w', "words", "The (maximum) number of words per document." ),
     
    });

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

    final int numberOfDocuments = jsapResult.getInt( "numberOfDocuments" );
    final int queries = jsapResult.getInt( "queries" );
    final int docperquery = jsapResult.getInt( "docperquery" );
    final int wordsperdoc = jsapResult.getInt( "wordsperdoc" );
   
    if ( docperquery > numberOfDocuments ) {
      System.err.println( "There are not enough documents for the number of documents/query required" );
      System.exit( 1 );
    }
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.