/** * Initializes the parser with a data array, specifying whether the data is zipped. * * @param data The examples can be parsed out of this array. * @param zip Whether or not the input stream is zipped. **/ public ArrayFileParser(byte[] data, boolean zip) { exampleData = data; zipped = zip; reset(); }
/** * Initializes the parser with a file name, specifying whether the data is zipped. * * @param exampleFile The name of the file containing the examples. * @param zip Whether or not the input stream is zipped. **/ public ArrayFileParser(String exampleFile, boolean zip) { exampleFileName = exampleFile; zipped = zip; reset(); }
/** * Returns the number of examples left in the example file. This may be slow to compute as it * must read through the entire file and increment the count. {@link #reset()} is called after * the examples are counted. * * @return The number of examples left in the example file. **/ public int getNumExamples() { int result = 0; try { while (true) { int L = in.readInt(); if (L == -1) continue; ++result; in.skipBytes(12 * L); // 4 for label index, 8 for its value L = in.readInt() + in.readInt(); in.skipBytes(12 * L); // 4 for feature index, 8 for its value } } catch (EOFException eof) { } catch (Exception e) { System.err.println("Can't read from '" + exampleFileName + "':"); e.printStackTrace(); System.exit(1); } reset(); return result; }