/** Opens a reader to the file called filename. Provided for easy overriding for encoding support etc in * child classes. Called from openNextFile(). * @param filename File to open. * @return BufferedReader of the file */ public static BufferedReader openFileReader(String filename) throws IOException { return openFileReader(filename,null); }
/** Opens a reader to the file called filename. Provided for easy overriding for encoding support etc in * child classes. Called from openNextFile(). * @param filename File to open. * @return BufferedReader of the file */ public static BufferedReader openFileReader(String filename) throws IOException { return openFileReader(filename,null); }
/** Opens a reader to the file called file. Provided for easy overriding for encoding support etc in * child classes. Called from openNextFile(). * @param file File to open. * @return BufferedReader of the file */ public static BufferedReader openFileReader(File file) throws IOException { return openFileReader(file.getPath(),null); }
/** Opens a reader to the file called filename. Provided for easy overriding for encoding support etc in * child classes. Called from openNextFile(). * @param file File to open. * @param charset Character set encoding of file. null for system default. * @return BufferedReader of the file */ public static BufferedReader openFileReader(File file, String charset) throws IOException { return openFileReader(file.getPath(), charset); }
/** Opens a reader to the file called file. Provided for easy overriding for encoding support etc in * child classes. Called from openNextFile(). * @param file File to open. * @return BufferedReader of the file */ public static BufferedReader openFileReader(File file) throws IOException { return openFileReader(file.getPath(),null); }
/** Opens a reader to the file called filename. Provided for easy overriding for encoding support etc in * child classes. Called from openNextFile(). * @param file File to open. * @param charset Character set encoding of file. null for system default. * @return BufferedReader of the file */ public static BufferedReader openFileReader(File file, String charset) throws IOException { return openFileReader(file.getPath(), charset); }
protected void reopen() throws IOException { if (reader != null) { try { reader.close(); } catch (IOException e) {} } reader = Files.openFileReader(filename); logger.info(this.getClass().getSimpleName() + " opened " + filename); }
protected void reopen() throws IOException { if (reader != null) { try { reader.close(); } catch (IOException e) {} } reader = Files.openFileReader(filename); logger.info(this.getClass().getSimpleName() + " opened " + filename); }
protected void readCollectionSpec(String CollectionSpecFilename) { //reads the collection specification file try { BufferedReader br2 = Files.openFileReader(CollectionSpecFilename); String filename = null; FilesToProcess = new ArrayList<String>(); while ((filename = br2.readLine()) != null) { filename = filename.trim(); if (!filename.startsWith("#") && !filename.equals("")) FilesToProcess.add(filename); } br2.close(); logger.info("TRECCollection read collection specification ("+FilesToProcess.size()+" files)"); } catch (IOException ioe) { logger.error("Input output exception while loading the collection.spec file. " + "("+CollectionSpecFilename+")", ioe); } }
protected void loadDocid2score(int numDocs, String inputFile, final int column) { logger.info("Opening docid2score feature file " + inputFile); try { String line = null; BufferedReader br = Files.openFileReader(inputFile); staticScores = new double[numDocs]; while((line = br.readLine())!= null) { final String[] parts = SPLIT_SPACE.split(line, column+1); staticScores[Integer.parseInt(parts[0])] = Double.parseDouble(parts[column-1]); } printStats(staticScores); br.close(); } catch (Exception e) { System.err.println("Problem opening file: \""+inputFile+"\" : "+e); e.printStackTrace(); } }
protected void loadJSON(String file) throws IOException { if (file.endsWith("bz2")) currentTweetStream = new BufferedReader(new InputStreamReader(new BZip2CompressorInputStream(new FileInputStream(file)),"UTF-8")); else currentTweetStream = Files.openFileReader(file, "UTF-8"); JSONStream = new JsonStreamParser(currentTweetStream); }
protected void loadJSON(String file) throws IOException { if (file.endsWith("bz2")) currentTweetStream = new BufferedReader(new InputStreamReader(new BZip2CompressorInputStream(new FileInputStream(file)),"UTF-8")); else currentTweetStream = Files.openFileReader(file, "UTF-8"); JSONStream = new JsonStreamParser(currentTweetStream); }
protected String readFirstLineReader(String filename) throws Exception { BufferedReader br = Files.openFileReader(filename); String rtr = br.readLine(); br.close(); return rtr; }
protected void loadScorefile(Index index) { String inputFile = ApplicationSetup.getProperty("ssa.input.file",""); try { staticScores = new double[index.getCollectionStatistics().getNumberOfDocuments()]; BufferedReader br = Files.openFileReader(inputFile); String line = null; int i=0; while((line = br.readLine()) != null) { staticScores[i++] = Double.parseDouble(line); } br.close(); } catch (Exception e) { logger.error("Problem opening file: \""+inputFile+"\"", e); } }
protected void loadScorefile(Index index) { String inputFile = ApplicationSetup.getProperty("ssa.input.file",""); try { staticScores = new double[index.getCollectionStatistics().getNumberOfDocuments()]; BufferedReader br = Files.openFileReader(inputFile); String line = null; int i=0; while((line = br.readLine()) != null) { staticScores[i++] = Double.parseDouble(line); } br.close(); } catch (Exception e) { logger.error("Problem opening file: \""+inputFile+"\"", e); } }
@Override protected int countNumberOfTopics(String filename) throws Exception { BufferedReader br = Files.openFileReader(filename); String line; int count = 0; while((line = br.readLine()) != null) { if (line.toLowerCase().contains("<top>")) count++; } br.close(); return count; }
protected void runsAndEvaluate() throws Exception { BufferedReader br = Files.openFileReader(testData+this.corpusName+".runs"); String line = null; while((line = br.readLine()) != null) { if (line.startsWith("#")) continue; String[] parts = line.split("\\t"); doTrecTerrierRunAndEvaluate( new String[]{this.topicsFile}, parts[0].split(" "), this.qrelsFile, Float.parseFloat(parts[1])); } br.close(); }
@Override public void checkIndex(BatchEndToEndTest test, Index index) throws Exception { String line = null; BufferedReader br = Files.openFileReader(testData+corpus+".indexproperties"); while((line = br.readLine()) != null) { if (line.startsWith("#")) continue; String[] parts = line.split("\\t"); assertEquals(parts[1], index.getIndexProperty(parts[0], "")); } }
@Test public void testAllExamples() throws Exception { BufferedReader brVocab = Files.openFileReader("../../share/tests/porterstemmer/voc.txt"); BufferedReader brTest = Files.openFileReader("../../share/tests/porterstemmer/output.txt"); String testWord; while((testWord = brVocab.readLine()) != null) { testWord = testWord.trim(); String targetWord = brTest.readLine(); if (targetWord == null) throw new IllegalStateException("Test files not of same length"); targetWord = targetWord.trim(); assertEquals("Incorrect stem for "+ testWord + " -> " + targetWord, targetWord, stemmer.stem(testWord)); } } }
@Test public void testSingleFileLeftOpen() throws Exception { String filename = super.writeTemporaryFile("test.txt", new String[]{"line1"}); CheckClosedStreams.enable(); BufferedReader br = Files.openFileReader(filename); assertFalse(CheckClosedStreams.allClosed()); br.close(); assertTrue(CheckClosedStreams.allClosed()); }