/** Creates a new immutable graph with the specified arguments. * * @param arg a 3-element array: the first is the basename of a {@link DocumentSequence}, the second is the name of a virtual * field, the third is the filename of a {@link VirtualDocumentResolver}. */ public DocumentSequenceImmutableGraph( final String... arg ) throws IOException, ClassNotFoundException { this( (DocumentSequence)BinIO.loadObject( arg[ 0 ] ), arg[ 1 ], (VirtualDocumentResolver)BinIO.loadObject( arg[ 2 ] ) ); }
/** Stores an object in a file given by a pathname. * * @param o an object. * @param filename a filename. * @see #loadObject(CharSequence) */ public static void storeObject(final Object o, final CharSequence filename) throws IOException { storeObject(o, new File(filename.toString())); } /** Loads an object from a file given by a {@link File} object.
/** Loads elements from a file given by a pathname, storing them in a given big array. * * @param filename a filename. * @param array a big array which will be filled with data from the specified file. * @return the number of elements actually read from the given file (it might be less than the array length if the file is too short). */ public static long loadInts(final CharSequence filename, final int[][] array) throws IOException { return loadInts(new File(filename.toString()), array); } /** Loads elements from a file given by a {@link File} object, storing them in a new big array.
public static void main( final String[] arg ) throws IOException, ClassNotFoundException, JSAPException { SimpleJSAP jsap = new SimpleJSAP( PermutedFrontCodedStringList.class.getName(), "Builds a permuted front-coded list of strings using a given front-coded string list and permutation", new Parameter[] { new Switch( "invert", 'i', "invert", "Invert permutation before creating the permuted list." ), new UnflaggedOption( "list", JSAP.STRING_PARSER, JSAP.REQUIRED, "A front-coded string list." ), new UnflaggedOption( "permutation", JSAP.STRING_PARSER, JSAP.REQUIRED, "A permutation for the indices of the list." ), new UnflaggedOption( "permutedList", JSAP.STRING_PARSER, JSAP.REQUIRED, "A the filename for the resulting permuted list." ), } ); JSAPResult jsapResult = jsap.parse( arg ); if ( jsap.messagePrinted() ) return; int[] basePermutation = BinIO.loadInts( jsapResult.getString( "permutation" ) ), permutation; if ( jsapResult.getBoolean( "invert" ) ) { int i = basePermutation.length; permutation = new int[ i ]; while( i-- != 0 ) permutation[ basePermutation[ i ] ] = i; } else permutation = basePermutation; basePermutation = null; BinIO.storeObject( new PermutedFrontCodedStringList( (FrontCodedStringList)BinIO.loadObject( jsapResult.getString( "list" ) ), permutation ), jsapResult.getString( "permutedList" ) ); } }
@SuppressWarnings("unchecked") public static void main(final String[] arg) throws IOException, JSAPException, ClassNotFoundException { final SimpleJSAP jsap = new SimpleJSAP(SignedFunctionStringMap.class.getName(), "Saves a string map wrapping a signed function on character sequences.", new Parameter[] { new UnflaggedOption("function", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The filename of a signed function defined on character sequences."), new UnflaggedOption("map", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The filename of the resulting string map."), }); final JSAPResult jsapResult = jsap.parse(arg); if (jsap.messagePrinted()) return; final String functionName = jsapResult.getString("function"); final String mapName = jsapResult.getString("map"); BinIO.storeObject(new SignedFunctionStringMap((Object2LongFunction<? extends CharSequence>)BinIO.loadObject(functionName)), mapName); } }
else graph = ImmutableGraph.loadOffline(basename, pl); final LongArrayBitVector buckets = (LongArrayBitVector)(new File(basename + ".buckets").exists() ? BinIO.loadObject(basename + ".buckets") : null); final int[] sccsize = new File(basename + ".sccsizes").exists() ? BinIO.loadInts(basename + ".sccsizes") : null;
BinIO.loadBytes(fis, graphMemory); fis.close(); isMemory = true; if (new File(basename + OFFSETS_EXTENSION).lastModified() > offsetsBigListFile.lastModified()) LOGGER.warn("A cached long big list of offsets was found, but the corresponding offsets file has a later modification time"); else try { offsets = (LongBigList)BinIO.loadObject(offsetsBigListFile);
private void write( final int b ) { if ( avail == 0 ) { final int oldLength = buffer.length; try { buffer = ByteArrays.grow( buffer, buffer.length + 1 ); } catch( OutOfMemoryError e ) { outOfMemoryError = true; try { // We try at all costs to avoid out-of-memory errors: we dump the buffer, try to allocate a slightly larger array and reload it. File temp = File.createTempFile( ByteArrayPostingList.class.getSimpleName(), "dump" ); temp.deleteOnExit(); BinIO.storeBytes( buffer, temp ); buffer = null; buffer = new byte[ oldLength + POSTINGS_EMERGENCY_INCREMENT ]; BinIO.loadBytes( temp, buffer ); temp.delete(); } catch ( IOException f ) { throw new RuntimeException( f ); } } avail += buffer.length - oldLength; } avail--; buffer[ pos++ ] = (byte)b; }
/** Loads elements from a file given by a pathname, storing them in a given big array. * * @param filename a filename. * @param array a big array which will be filled with data from the specified file. * @return the number of elements actually read from the given file (it might be less than the array length if the file is too short). */ public static long loadBytes(final CharSequence filename, final byte[][] array) throws IOException { return loadBytes(new File(filename.toString()), array); } /** Loads elements from a file given by a {@link File} object, storing them in a new big array.
final int size[] = components.computeSizes(); if (jsapResult.getBoolean("renumber")) components.sortBySize(size); if (jsapResult.getBoolean("sizes")) BinIO.storeInts(size, resultsBasename + ".sccsizes"); BinIO.storeInts(components.component, resultsBasename + ".scc"); if (components.buckets != null) BinIO.storeObject(components.buckets, resultsBasename + ".buckets");
valueFile.deleteOnExit(); BinIO.storeLongs(map.key, 0, map.size(), keyFile); BinIO.storeInts(map.value, 0, map.size(), valueFile); long[][] key = BinIO.loadLongsBig(keyFile); keyFile.delete(); int[][] value = BinIO.loadIntsBig(valueFile); valueFile.delete();
/** Stores an array fragment to a file given by a pathname. * * @param array an array whose elements will be written to {@code filename}. * @param offset the index of the first element of {@code array} to be written. * @param length the number of elements of {@code array} to be written. * @param filename a filename. */ public static void storeInts(final int array[], final int offset, final int length, final CharSequence filename) throws IOException { storeInts(array, offset, length, new File(filename.toString())); } /** Stores an array to a file given by a {@link File} object.
/** Builds a document scorer by first reading the ranks from a file. * Ranks are saved as doubles (the first double is the rank of document 0 * and so on). * * @param filename the name of the rank file. */ public DecreasingDocumentRankScorer( final String filename ) throws IOException { this( BinIO.loadDoubles( filename ) ); }
/** Stores an array fragment to a file given by a pathname. * * @param array an array whose elements will be written to {@code filename}. * @param offset the index of the first element of {@code array} to be written. * @param length the number of elements of {@code array} to be written. * @param filename a filename. */ public static void storeBytes(final byte array[], final int offset, final int length, final CharSequence filename) throws IOException { storeBytes(array, offset, length, new File(filename.toString())); } /** Stores an array to a file given by a {@link File} object.
public static void main( final String[] arg ) throws IOException, ClassNotFoundException, JSAPException { SimpleJSAP jsap = new SimpleJSAP( PermutedFrontCodedStringList.class.getName(), "Builds a permuted front-coded list of strings using a given front-coded string list and permutation", new Parameter[] { new Switch( "invert", 'i', "invert", "Invert permutation before creating the permuted list." ), new UnflaggedOption( "list", JSAP.STRING_PARSER, JSAP.REQUIRED, "A front-coded string list." ), new UnflaggedOption( "permutation", JSAP.STRING_PARSER, JSAP.REQUIRED, "A permutation for the indices of the list." ), new UnflaggedOption( "permutedList", JSAP.STRING_PARSER, JSAP.REQUIRED, "A the filename for the resulting permuted list." ), } ); JSAPResult jsapResult = jsap.parse( arg ); if ( jsap.messagePrinted() ) return; int[] basePermutation = BinIO.loadInts( jsapResult.getString( "permutation" ) ), permutation; if ( jsapResult.getBoolean( "invert" ) ) { int i = basePermutation.length; permutation = new int[ i ]; while( i-- != 0 ) permutation[ basePermutation[ i ] ] = i; } else permutation = basePermutation; basePermutation = null; BinIO.storeObject( new PermutedFrontCodedStringList( (FrontCodedStringList)BinIO.loadObject( jsapResult.getString( "list" ) ), permutation ), jsapResult.getString( "permutedList" ) ); } }
private void write( final int b ) { if ( avail == 0 ) { final int oldLength = buffer.length; try { buffer = ByteArrays.grow( buffer, buffer.length + 1 ); } catch( OutOfMemoryError e ) { outOfMemoryError = true; try { // We try at all costs to avoid out-of-memory errors: we dump the buffer, try to allocate a slightly larger array and reload it. File temp = File.createTempFile( ByteArrayPostingList.class.getSimpleName(), "dump" ); temp.deleteOnExit(); BinIO.storeBytes( buffer, temp ); buffer = null; buffer = new byte[ oldLength + POSTINGS_EMERGENCY_INCREMENT ]; BinIO.loadBytes( temp, buffer ); temp.delete(); } catch ( IOException f ) { throw new RuntimeException( f ); } } avail += buffer.length - oldLength; } avail--; buffer[ pos++ ] = (byte)b; }
/** Loads elements from a file given by a pathname, storing them in a given array fragment. * * @param filename a filename. * @param array an array which will be filled with data from the specified file. * @param offset the index of the first element of {@code array} to be filled. * @param length the number of elements of {@code array} to be filled. * @return the number of elements actually read from the given file (it might be less than {@code length} if the file is too short). */ public static int loadBytes(final CharSequence filename, final byte[] array, final int offset, final int length) throws IOException { return loadBytes(new File(filename.toString()), array, offset, length); } /** Loads elements from a file given by a {@link File} object, storing them in a given array.
valueFile.deleteOnExit(); BinIO.storeLongs(map.key, 0, map.size(), keyFile); BinIO.storeInts(map.value, 0, map.size(), valueFile); long[][] key = BinIO.loadLongsBig(keyFile); keyFile.delete(); int[][] value = BinIO.loadIntsBig(valueFile); valueFile.delete();