@Test public void testReadingEvents() throws IOException { String sample = "word11 tag11 pred11" + '\n' + "word12 tag12 pred12" + '\n' + "word13 tag13 pred13" + '\n' + '\n' + "word21 tag21 pred21" + '\n' + "word22 tag22 pred22" + '\n' + "word23 tag23 pred23" + '\n'; ObjectStream<String> stringStream = new PlainTextByLineStream( new MockInputStreamFactory(sample), StandardCharsets.UTF_8); ObjectStream<ChunkSample> chunkStream = new ChunkSampleStream(stringStream); ChunkSample firstSample = chunkStream.read(); Assert.assertEquals("word11", firstSample.getSentence()[0]); Assert.assertEquals("tag11", firstSample.getTags()[0]); Assert.assertEquals("pred11", firstSample.getPreds()[0]); Assert.assertEquals("word12", firstSample.getSentence()[1]); Assert.assertEquals("tag12", firstSample.getTags()[1]); Assert.assertEquals("pred12", firstSample.getPreds()[1]); Assert.assertEquals("word13", firstSample.getSentence()[2]); Assert.assertEquals("tag13", firstSample.getTags()[2]); Assert.assertEquals("pred13", firstSample.getPreds()[2]); ChunkSample secondSample = chunkStream.read(); Assert.assertEquals("word21", secondSample.getSentence()[0]); Assert.assertEquals("tag21", secondSample.getTags()[0]); Assert.assertEquals("pred21", secondSample.getPreds()[0]); Assert.assertEquals("word22", secondSample.getSentence()[1]); Assert.assertEquals("tag22", secondSample.getTags()[1]); Assert.assertEquals("pred22", secondSample.getPreds()[1]); Assert.assertEquals("word23", secondSample.getSentence()[2]); Assert.assertEquals("tag23", secondSample.getTags()[2]); Assert.assertEquals("pred23", secondSample.getPreds()[2]); Assert.assertNull(chunkStream.read()); chunkStream.close(); }
public ChunkSample read() throws IOException { List<String> toks = new ArrayList<>(); List<String> tags = new ArrayList<>(); List<String> preds = new ArrayList<>(); for (String line = samples.read(); line != null && !line.equals(""); line = samples.read()) { String[] parts = line.split(" "); if (parts.length != 3) { System.err.println("Skipping corrupt line: " + line); } else { toks.add(parts[0]); tags.add(parts[1]); preds.add(parts[2]); } } if (toks.size() > 0) { return new ChunkSample(toks.toArray(new String[toks.size()]), tags.toArray(new String[tags.size()]), preds.toArray(new String[preds.size()])); } return null; }
ChunkSampleStream extends FilterObjectStream<String, ChunkSample> { public ChunkSample read() throws IOException { List<String> toks = new ArrayList<>(); List<String> tags = new ArrayList<>(); List<String> preds = new ArrayList<>(); for (String line = samples.read(); line != null && !line.equals(""); line = samples.read()) { String[] parts = line.split(" "); if (parts.length != 3) { System.err.println("Skipping corrupt line: " + line); } else { toks.add(parts[0]); tags.add(parts[1]); preds.add(parts[2]); } } if (toks.size() > 0) { return new ChunkSample(toks.toArray(new String[toks.size()]), tags.toArray(new String[tags.size()]), preds.toArray(new String[preds.size()])); } return null; } }
ChunkSampleStream extends FilterObjectStream<String, ChunkSample> { public ChunkSample read() throws IOException { List<String> toks = new ArrayList<>(); List<String> tags = new ArrayList<>(); List<String> preds = new ArrayList<>(); for (String line = samples.read(); line != null && !line.equals(""); line = samples.read()) { String[] parts = line.split(" "); if (parts.length != 3) { System.err.println("Skipping corrupt line: " + line); } else { toks.add(parts[0]); tags.add(parts[1]); preds.add(parts[2]); } } if (toks.size() > 0) { return new ChunkSample(toks.toArray(new String[toks.size()]), tags.toArray(new String[tags.size()]), preds.toArray(new String[preds.size()])); } return null; } ChunkSampleStream(ObjectStream<String> samples); }
ChunkSampleStream extends FilterObjectStream<String, ChunkSample> { public ChunkSample read() throws IOException { List<String> toks = new ArrayList<>(); List<String> tags = new ArrayList<>(); List<String> preds = new ArrayList<>(); for (String line = samples.read(); line != null && !line.equals(""); line = samples.read()) { String[] parts = line.split(" "); if (parts.length != 3) { System.err.println("Skipping corrupt line: " + line); } else { toks.add(parts[0]); tags.add(parts[1]); preds.add(parts[2]); } } if (toks.size() > 0) { return new ChunkSample(toks.toArray(new String[toks.size()]), tags.toArray(new String[tags.size()]), preds.toArray(new String[preds.size()])); } return null; } ChunkSampleStream(ObjectStream<String> samples); ChunkSample read(); }
ChunkSampleStream extends FilterObjectStream<String, ChunkSample> { public ChunkSample read() throws IOException { List<String> toks = new ArrayList<>(); List<String> tags = new ArrayList<>(); List<String> preds = new ArrayList<>(); for (String line = samples.read(); line != null && !line.equals(""); line = samples.read()) { String[] parts = line.split(" "); if (parts.length != 3) { System.err.println("Skipping corrupt line: " + line); } else { toks.add(parts[0]); tags.add(parts[1]); preds.add(parts[2]); } } if (toks.size() > 0) { return new ChunkSample(toks.toArray(new String[toks.size()]), tags.toArray(new String[tags.size()]), preds.toArray(new String[preds.size()])); } return null; } ChunkSampleStream(ObjectStream<String> samples); ChunkSample read();  }