IobDecoder { public void decode(List<? extends AnnotationFS> aTokens, String[] aChunkTags) { int i = 0; for (AnnotationFS token : aTokens) { String[] fields = aChunkTags[i].split("-"); String flag = fields.length == 2 ? fields[0] : "NONE"; String chunk = fields.length == 2 ? fields[1] : null; if (chunk == null || !chunk.equals(openChunk) || "B".equals(flag)) { if (openChunk != null) { chunkComplete(); } if ("O".equals(flag)) { openChunk = null; } else { openChunk = chunk; } start = token.getBegin(); } end = token.getEnd(); i++; } chunkComplete(); } IobDecoder(CAS aCas, Feature aChunkValue, MappingProvider aMappingProvider); void setInternTags(boolean aInternTags); void decode(List<? extends AnnotationFS> aTokens, String[] aChunkTags);  }
@Test public void iobEncoderTest() throws Exception { String[] input = new String[] { "O", "O", "O", "B-NP", "I-NP", "I-NP", "I-NP", "O", "O", "O", "O", "O", "B-NP", "O", "B-NP", "O", "O", "O" }; String[] chunks = new String[] { "[ 10, 43]Chunk(NP) (very complicated example sentence)", "[ 69, 81]Chunk(NP) (constituents)", "[ 86, 98]Chunk(NP) (dependencies)" }; JCas jcas = getJCas(); MappingProvider mappingProvider = new MappingProvider(); mappingProvider.setDefault(MappingProvider.BASE_TYPE, Chunk.class.getName()); mappingProvider.setDefault(MappingProvider.LOCATION, "dummy"); mappingProvider.configure(jcas.getCas()); Type chunkType = JCasUtil.getType(jcas, Chunk.class); Feature chunkValue = chunkType.getFeatureByBaseName("chunkValue"); IobDecoder decoder = new IobDecoder(jcas.getCas(), chunkValue, mappingProvider); List<Token> tokens = new ArrayList<Token>(JCasUtil.select(jcas, Token.class)); decoder.decode(tokens, input); assertChunks(chunks, select(jcas, Chunk.class)); }