@Test public void shouldSplitSimpleText() throws Exception { { final LinkedList<TextBlock> textBlocks = splitter.splitToTextParts("a b"); assertThat(textBlocks, hasSize(3)); assertThat(textBlocks.get(0), equalTo(new TextBlock("a", TextBlockType.Word))); assertThat(textBlocks.get(1), equalTo(new TextBlock(" ", TextBlockType.Space))); assertThat(textBlocks.get(2), equalTo(new TextBlock("b", TextBlockType.Word))); } { final LinkedList<TextBlock> textBlocks = splitter.splitToTextParts("a\nb12"); assertThat(textBlocks, hasSize(4)); assertThat(textBlocks.get(0), equalTo(new TextBlock("a", TextBlockType.Word))); assertThat(textBlocks.get(1), equalTo(new TextBlock("\n", TextBlockType.Other_WhiteSpace))); assertThat(textBlocks.get(2), equalTo(new TextBlock("b", TextBlockType.Word))); assertThat(textBlocks.get(3), equalTo(new TextBlock("12", TextBlockType.Digits))); } { final LinkedList<TextBlock> textBlocks = splitter.splitToTextParts("WORD Word word"); assertThat(textBlocks, hasSize(5)); assertThat(textBlocks.get(0), equalTo(new TextBlock("WORD", TextBlockType.AllCaps_Word))); assertThat(textBlocks.get(1), equalTo(new TextBlock(" ", TextBlockType.Space))); assertThat(textBlocks.get(2), equalTo(new TextBlock("Word", TextBlockType.Capitalized_Word))); assertThat(textBlocks.get(3), equalTo(new TextBlock(" ", TextBlockType.Space))); assertThat(textBlocks.get(4), equalTo(new TextBlock("word", TextBlockType.Word))); } }
protected LinkedList<TextBlock> splitToTextParts(String text) { final LinkedList<TextBlock> textBlocks = new LinkedList<TextBlock>(); while (StringUtils.isNotBlank(text)) { boolean foundOneClass = false; for (TextBlockType textBlockType : TextBlockType.PHYSICAL_TYPES) { final String matchedStr = textBlockType.findMatchFromBeginning(text); if (matchedStr != null) { textBlocks.add(new TextBlock(matchedStr, textBlockType)); text = text.substring(matchedStr.length()); foundOneClass = true; break; } else { continue; } } if (!foundOneClass) { throw new IllegalArgumentException("Text is not matched with any of the classes: \"" + text + "\""); } } return textBlocks; }
TextBlockSplitter { protected LinkedList<TextBlock> splitToTextParts(String text) { final LinkedList<TextBlock> textBlocks = new LinkedList<TextBlock>(); while (StringUtils.isNotBlank(text)) { boolean foundOneClass = false; for (TextBlockType textBlockType : TextBlockType.PHYSICAL_TYPES) { final String matchedStr = textBlockType.findMatchFromBeginning(text); if (matchedStr != null) { textBlocks.add(new TextBlock(matchedStr, textBlockType)); text = text.substring(matchedStr.length()); foundOneClass = true; break; } else { continue; } } if (!foundOneClass) { throw new IllegalArgumentException("Text is not matched with any of the classes: \"" + text + "\""); } } return textBlocks; } }
TextBlockSplitter { protected LinkedList<TextBlock> splitToTextParts(String text) { final LinkedList<TextBlock> textBlocks = new LinkedList<TextBlock>(); while (StringUtils.isNotBlank(text)) { boolean foundOneClass = false; for (TextBlockType textBlockType : TextBlockType.PHYSICAL_TYPES) { final String matchedStr = textBlockType.findMatchFromBeginning(text); if (matchedStr != null) { textBlocks.add(new TextBlock(matchedStr, textBlockType)); text = text.substring(matchedStr.length()); foundOneClass = true; break; } else { continue; } } if (!foundOneClass) { throw new IllegalArgumentException("Text is not matched with any of the classes: \"" + text + "\""); } } return textBlocks; }  }
TextBlockSplitter { protected LinkedList<TextBlock> splitToTextParts(String text) { final LinkedList<TextBlock> textBlocks = new LinkedList<TextBlock>(); while (StringUtils.isNotBlank(text)) { boolean foundOneClass = false; for (TextBlockType textBlockType : TextBlockType.PHYSICAL_TYPES) { final String matchedStr = textBlockType.findMatchFromBeginning(text); if (matchedStr != null) { textBlocks.add(new TextBlock(matchedStr, textBlockType)); text = text.substring(matchedStr.length()); foundOneClass = true; break; } else { continue; } } if (!foundOneClass) { throw new IllegalArgumentException("Text is not matched with any of the classes: \"" + text + "\""); } } return textBlocks; }  TextBlockGroup getTextBlockGroup(List<TextBlock> textBlocks, int blockSize, int startIndex); void addTextStartsAndEnds(List<TextBlock> textBlocks, int blockSize); }
TextBlockSplitter { protected LinkedList<TextBlock> splitToTextParts(String text) { final LinkedList<TextBlock> textBlocks = new LinkedList<TextBlock>(); while (StringUtils.isNotBlank(text)) { boolean foundOneClass = false; for (TextBlockType textBlockType : TextBlockType.PHYSICAL_TYPES) { final String matchedStr = textBlockType.findMatchFromBeginning(text); if (matchedStr != null) { textBlocks.add(new TextBlock(matchedStr, textBlockType)); text = text.substring(matchedStr.length()); foundOneClass = true; break; } else { continue; } } if (!foundOneClass) { throw new IllegalArgumentException("Text is not matched with any of the classes: \"" + text + "\""); } } return textBlocks; }  TextBlockGroup getTextBlockGroup(List<TextBlock> textBlocks, int blockSize, int startIndex); void addTextStartsAndEnds(List<TextBlock> textBlocks, int blockSize);  }