int numberOfPartialQueries = queries;
ProgressLogger pl = new ProgressLogger( LOGGER );
pl.itemsName = "Klines";
pl.expectedUpdates = maxDoc / 1000;
pl.start( "Generating queries..." );
MutableString line = new MutableString();
while( reader.readLine( line ) != null && numberOfPartialQueries > 0 ) {
if ( used[ lineNumber ] ) {
for ( q = 0; q < queries; q++ )
if ( coveredForQuery[ q ] < docperquery && docForQuery[ q ][ coveredForQuery[ q ] ] == lineNumber ) {
split = line.toString().split( " " );
int nw = split.length;
words = IntArrays.ensureCapacity( words, nw + 1 );
for ( i = 0; i < nw; i++ ) words[ i ] = i;
for ( i = 0; i < Math.min( wordsperdoc, nw ); i++ ) {
j = i + (int)( ( nw - i ) * Math.random() );
t = words[ i ]; words[ i ] = words[ j ]; words[ j ] = t;
query[ q ][ coveredForQuery[ q ] ][ i ] = split[ words[ i ] ];
}
coveredForQuery[ q ]++;
if ( coveredForQuery[ q ] == docperquery ) numberOfPartialQueries--;
}
}
lineNumber++;
if ( lineNumber % 1000 == 0 ) pl.update();
}
pl.done();
MutableString p[] = new MutableString[ Math.max( queries, wordsperdoc ) ], s = new MutableString();
for( i = 0; i < p.length; i++ ) p[ i ] = new MutableString();
for ( q = 0; q < queries; q++ ) {
for( int d = 0; d < wordsperdoc; d++ ) {
int last = 0;
while( last < wordsperdoc && query[ q ][ d ][ last ] != null ) last++;
p[ d ].replace( '(' ).append( query[ q ][ d ], 0, last, " AND " ).append( ')' );
}
System.out.println( s.length( 0 ).append( p, 0, queries, " OR " ) );
}
ArrayList<String> l = new ArrayList<String>();
final String[] emptyArray = new String[ 0 ];
for ( q = 0; q < queries; q++ ) {
for( int w = 0; w < wordsperdoc; w++ ) {
l.clear();
for( int d = 0; d < wordsperdoc; d++ ) if ( query[ q ][ d ][ w ] != null ) l.add( query[ q ][ d ][ w ] );
p[ w ].replace( '(' ).append( l.toArray( emptyArray ), " OR " ).append( ')' );
}
System.err.println( s.length( 0 ).append( p, 0, wordsperdoc, " AND " ) );
}
}