LineReader extends JCasCollectionReader_ImplBase { public boolean hasNext() throws IOException, CollectionException { if (line == null) { line = input.readLine(); if (line != null) { for (String commentSpecifier : commentSpecifiers) { if (line.startsWith(commentSpecifier)) { line = null; return hasNext(); } } if (skipBlankLines && line.trim().equals("")) { line = null; return hasNext(); } } } if (line == null) { if (moveToNextFile()) return hasNext(); else return false; } return true; }  @Override void initialize(UimaContext context); void getNext(JCas jCas); Progress[] getProgress(); boolean hasNext(); void close(); static final String PARAM_FILE_OR_DIRECTORY_NAME; static final String PARAM_VIEW_NAME; static final String PARAM_LANGUAGE; static final String PARAM_ENCODING; static final String PARAM_SUFFIXES; static final String PARAM_LINE_HANDLER_CLASS_NAME; static final String PARAM_COMMENT_SPECIFIERS; static final String PARAM_SKIP_BLANK_LINES; }
@Test public void test1() throws Exception { String languageCode = "en-us"; CollectionReaderDescription reader = CollectionReaderFactory.createReaderDescription( LineReader.class, null, LineReader.PARAM_FILE_OR_DIRECTORY_NAME, inputDir, LineReader.PARAM_LANGUAGE, languageCode, LineReader.PARAM_SUFFIXES, new String[] { ".txt" }); JCasIterator jCasIterator = new JCasIterable(reader).iterator(); test( jCasIterator, "# this file was created by Philip Ogren on Monday 10/27/2008", toURI("a-test1.txt") + "#1"); test(jCasIterator, "# for more files like this please make your own", toURI("a-test1.txt") + "#2"); test(jCasIterator, "A|This is the first sentence.", toURI("a-test1.txt") + "#3"); test(jCasIterator, "B|This is the second sentence. ", toURI("a-test1.txt") + "#4"); test( jCasIterator, "C|You are likely completely absorbed by the narrative at this point.", toURI("a-test1.txt") + "#5"); test(jCasIterator, "D|... but too bad! ", toURI("a-test1.txt") + "#6"); test(jCasIterator, "EEEK|will it ever end? yes - very soon...", toURI("a-test1.txt") + "#7"); test(jCasIterator, "Z|Fin", toURI("a-test1.txt") + "#8"); reader = CollectionReaderFactory.createReaderDescription( LineReader.class, null, LineReader.PARAM_FILE_OR_DIRECTORY_NAME, inputDir, LineReader.PARAM_LANGUAGE, languageCode, LineReader.PARAM_SUFFIXES, new String[] { ".dat" }); jCasIterator = new JCasIterable(reader).iterator(); test(jCasIterator, " + "#1"); test( jCasIterator, " toURI("b-test2.dat") + "#2"); test(jCasIterator, " test(jCasIterator, "1234|a bc def ghij klmno pqrstu vwxyz", toURI("b-test2.dat") + "#4"); assertFalse(jCasIterator.hasNext()); }
@Test public void test2() throws Exception { CollectionReaderDescription reader = CollectionReaderFactory.createReaderDescription( LineReader.class, null, LineReader.PARAM_FILE_OR_DIRECTORY_NAME, inputDir, LineReader.PARAM_LINE_HANDLER_CLASS_NAME, SimpleLineHandler.class.getName(), SimpleLineHandler.PARAM_DELIMITER, "|", LineReader.PARAM_SUFFIXES, new String[] { ".txt" }, LineReader.PARAM_COMMENT_SPECIFIERS, new String[] { "#", " JCasIterator jCasIterator = new JCasIterable(reader).iterator(); test(jCasIterator, "This is the first sentence.", toURI("a-test1.txt") + "#A"); test(jCasIterator, "This is the second sentence. ", toURI("a-test1.txt") + "#B"); test( jCasIterator, "You are likely completely absorbed by the narrative at this point.", toURI("a-test1.txt") + "#C"); test(jCasIterator, "... but too bad! ", toURI("a-test1.txt") + "#D"); test(jCasIterator, "will it ever end? yes - very soon...", toURI("a-test1.txt") + "#EEEK"); test(jCasIterator, "Fin", toURI("a-test1.txt") + "#Z"); reader = CollectionReaderFactory.createReaderDescription( LineReader.class, null, LineReader.PARAM_FILE_OR_DIRECTORY_NAME, inputDir, LineReader.PARAM_LINE_HANDLER_CLASS_NAME, SimpleLineHandler.class.getName(), SimpleLineHandler.PARAM_DELIMITER, "|", LineReader.PARAM_SUFFIXES, new String[] { ".dat" }, LineReader.PARAM_COMMENT_SPECIFIERS, new String[] { "#", " jCasIterator = new JCasIterable(reader).iterator(); test(jCasIterator, "a bc def ghij klmno pqrstu vwxyz", toURI("b-test2.dat") + "#1234"); assertFalse(jCasIterator.hasNext()); }
@Test public void test3() throws Exception { File file = new File(inputDir, "b-test2.dat"); CollectionReaderDescription reader = CollectionReaderFactory.createReaderDescription( LineReader.class, null, LineReader.PARAM_FILE_OR_DIRECTORY_NAME, file.getPath(), LineReader.PARAM_COMMENT_SPECIFIERS, new String[] { " LineReader.PARAM_SKIP_BLANK_LINES, false); JCasIterator jCasIterator = new JCasIterable(reader).iterator(); test(jCasIterator, "", file.toURI() + "#1"); test(jCasIterator, "", file.toURI() + "#2"); test(jCasIterator, "", file.toURI() + "#3"); test(jCasIterator, "1234|a bc def ghij klmno pqrstu vwxyz", file.toURI() + "#4"); test(jCasIterator, "", file.toURI() + "#5"); test(jCasIterator, " ", file.toURI() + "#6"); assertFalse(jCasIterator.hasNext()); }