ChunkSample { public static Span[] phrasesAsSpanList(String[] aSentence, String[] aTags, String[] aPreds) { validateArguments(aSentence.length, aTags.length, aPreds.length); List<Span> phrases = new ArrayList<Span>(aSentence.length); String startTag = ""; int startIndex = 0; boolean foundPhrase = false; for (int ci = 0, cn = aPreds.length; ci < cn; ci++) { String pred = aPreds[ci]; if (pred.startsWith("B-") || (!pred.equals("I-" + startTag) && !pred.equals("O"))) { if (foundPhrase) { phrases.add(new Span(startIndex, ci, startTag)); } startIndex = ci; startTag = pred.substring(2); foundPhrase = true; } else if (pred.equals("I-" + startTag)) { } else if (foundPhrase) { phrases.add(new Span(startIndex, ci, startTag)); foundPhrase = false; startTag = ""; } } if (foundPhrase) { phrases.add(new Span(startIndex, aPreds.length, startTag)); } return phrases.toArray(new Span[phrases.size()]); } ChunkSample(String[] sentence, String[] tags, String[] preds);  ChunkSample(List<String> sentence, List<String> tags, List<String> preds); String[] getSentence(); String[] getTags(); String[] getPreds(); Span[] getPhrasesAsSpanList(); static Span[] phrasesAsSpanList(String[] aSentence, String[] aTags,
      String[] aPreds); String nicePrint(); @Override String toString(); @Override boolean equals(Object obj);  }
@Test(expected = IllegalArgumentException.class) public void testInvalidPhraseAsSpan3() { ChunkSample.phrasesAsSpanList(new String[1], new String[1], new String[2]); }
@Test public void testPhraseAsSpan() { Span[] spans = ChunkSample.phrasesAsSpanList(createSentence(), createTags(), createChunks()); assertEquals(10, spans.length); assertEquals(new Span(0, 1, "NP"), spans[0]); assertEquals(new Span(1, 2, "PP"), spans[1]); assertEquals(new Span(2, 5, "NP"), spans[2]); assertEquals(new Span(5, 6, "VP"), spans[3]); assertEquals(new Span(6, 7, "ADVP"), spans[4]); assertEquals(new Span(8, 9, "NP"), spans[5]); assertEquals(new Span(9, 10, "PP"), spans[6]); assertEquals(new Span(10, 13, "NP"), spans[7]); assertEquals(new Span(13, 14, "VP"), spans[8]); assertEquals(new Span(14, 15, "ADVP"), spans[9]); }
@Test(expected = IllegalArgumentException.class) public void testInvalidPhraseAsSpan1() { ChunkSample.phrasesAsSpanList(new String[2], new String[1], new String[1]); }
@Test(expected = IllegalArgumentException.class) public void testInvalidPhraseAsSpan2() { ChunkSample.phrasesAsSpanList(new String[1], new String[2], new String[1]); }