BilouDecoder { public void decode(List<? extends AnnotationFS> aTokens, String[] aTags) { int i = 0; for (AnnotationFS token : aTokens) { String tag = aTags[i]; if ( !(tag.length() == 1 && tag.charAt(0) == 'O') && !(tag.length() >= 2 && tag.charAt(1) == '-') ) { throw new IllegalStateException("Tag is not BILOU-encoded: [" + tag + "]"); } switch (tag.charAt(0)) { case 'B': start = token.getBegin(); openChunk = tag.substring(2); break; case 'I': break; case 'L': end = token.getEnd(); chunkComplete(); break; case 'O': break; case 'U': start = token.getBegin(); end = token.getEnd(); openChunk = tag.substring(2); chunkComplete(); break; default: throw new IllegalStateException("Tag is not BILOU-encoded: [" + tag + "]"); } i++; } chunkComplete(); } BilouDecoder(CAS aCas, Feature aValueFeature, MappingProvider aMappingProvider); void setInternTags(boolean aInternTags); void decode(List<? extends AnnotationFS> aTokens, String[] aTags);  }
@Test public void bilouEncoderTest() throws Exception { String[] input = new String[] { "O", "O", "O", "B-NP", "I-NP", "I-NP", "L-NP", "O", "O", "O", "O", "O", "U-NP", "O", "U-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"); BilouDecoder decoder = new BilouDecoder(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)); }