WordTagSampleStream extends FilterObjectStream<String, POSSample> { public POSSample read() throws IOException { String sentence = samples.read(); if (sentence != null) { POSSample sample; try { sample = POSSample.parse(sentence); } catch (InvalidFormatException e) { if (logger.isLoggable(Level.WARNING)) { logger.warning("Error during parsing, ignoring sentence: " + sentence); } sample = new POSSample(new String[]{}, new String[]{}); } return sample; } else { return null; } } WordTagSampleStream(Reader sentences);  WordTagSampleStream(ObjectStream<String> sentences); POSSample read();  }
@Test public void testParseSimpleSample() throws IOException { Collection<String> sampleString = new ArrayList<String>(1); sampleString.add("This_x1 is_x2 a_x3 test_x4 sentence_x5 ._x6"); WordTagSampleStream stream = new WordTagSampleStream(new CollectionObjectStream<String>(sampleString)); POSSample sample = stream.read(); String words[] = sample.getSentence(); assertEquals("This", words[0]); assertEquals("is", words[1]); assertEquals("a", words[2]); assertEquals("test", words[3]); assertEquals("sentence", words[4]); assertEquals(".", words[5]); String tags[] = sample.getTags(); assertEquals("x1", tags[0]); assertEquals("x2", tags[1]); assertEquals("x3", tags[2]); assertEquals("x4", tags[3]); assertEquals("x5", tags[4]); assertEquals("x6", tags[5]); assertNull(stream.read()); stream.reset(); assertNotNull(stream.read()); }