PennTreebankPOSReader { public TextAnnotation createTextAnnotation(String line, String lineId) { String[] wordPOSPairs = splitWordsPattern.split(line.substring(1, line.length() - 1)); List<String> words = new ArrayList<>(wordPOSPairs.length); List<String> pos = new ArrayList<>(wordPOSPairs.length); for (String wordPOSPair : wordPOSPairs) { String[] split = whitespacePattern.split(wordPOSPair); words.add(split[1]); pos.add(split[0]); } List<String[]> tokenizedSentences = Collections.singletonList(words.toArray(new String[words.size()])); TextAnnotation ta = BasicTextAnnotationBuilder.createTextAnnotationFromTokens(corpusName, lineId, tokenizedSentences); TokenLabelView posView = new TokenLabelView(ViewNames.POS, ta); for (int i = 0; i < pos.size(); i++) posView.addTokenLabel(i, pos.get(i), 1.0); ta.addView(ViewNames.POS, posView); return ta; } PennTreebankPOSReader(String corpusName); void readFile(String fileName); TextAnnotation createTextAnnotation(String line, String lineId); List<TextAnnotation> getTextAnnotations();  }
@Test public void testCreateTextAnnotation() throws Exception { PennTreebankPOSReader reader = new PennTreebankPOSReader("test"); TextAnnotation ta = reader.createTextAnnotation(lines.get(0), "sent0"); assertTrue(ta.hasView(ViewNames.POS)); assertEquals("NNP", ta.getView(ViewNames.POS).getConstituents().get(1).getLabel()); }