The method of displaying chunkings in the previous recipes is not well suited for applications that need to modify the underlying string. For example, a sentiment analyzer might want to highlight only sentences that are strongly positive and not mark up the remaining sentences while still displaying the entire text. The slight complication in producing the marked-up text is that adding markups changes the underlying string. This recipe provides working code to insert the chunking by adding chunks in reverse.
While this recipe may not be technically complex it is useful to get span annotations into a text without out having to invent the code from whole cloth. The src/com/lingpipe/coobook/chapter5/WriteSentDetectedChunks
class has the referenced code:
The sentence chunking is created as per the first sentence-detection recipe. The following code extracts the chunks as
Set<Chunk>
and then sorts them byChunk.LONGEST_MATCH_ORDER_COMPARITOR...