### Question:
TextExtractorMapper implements FlatMapFunction<String, RawWikiDocument> { @Override public void flatMap(String content, Collector<RawWikiDocument> out) throws Exception { Matcher titleMatcher = TITLE_PATTERN.matcher(content); if (!titleMatcher.find()) { return; } String title = titleMatcher.group(1); LOGGER.info("processing document '{}'...", title); Matcher namespaceMatcher = NAMESPACE_PATTERN.matcher(content); if (!namespaceMatcher.find()) { return; } int ns = Integer.parseInt(namespaceMatcher.group(1)); if (ns != 0) { return; } Matcher textMatcher = TEXT_PATTERN.matcher(content); if (!textMatcher.find()) { return; } String rawText = textMatcher.group(1); String text = unescape(rawText); out.collect(new RawWikiDocument(title, ns, text)); }  @Override void flatMap(String content, Collector<RawWikiDocument> out); static String unescape(String text);  }### Answer:
@Test public void test() throws Exception { InputStream stream = PatternMatchingRelationFinder.class.getResourceAsStream("augmentendwikitext.xml"); String rawImput = IOUtils.toString(stream,"UTF-8"); assertTrue(rawImput.contains("&lt;math")); String[] pages = rawImput.split("</page>"); TextExtractorMapper textExtractor = new TextExtractorMapper(); ListCollector<RawWikiDocument> out = new ListCollector<>(); for (String page : pages) { textExtractor.flatMap(page, out); } List<RawWikiDocument> output = out.getList(); assertEquals(2, output.size()); RawWikiDocument doc1 = output.get(0); assertEquals("Schrödinger equation", doc1.title); assertFalse(doc1.text.contains("&lt;math")); assertTrue(doc1.text.contains("<math")); RawWikiDocument doc2 = output.get(1); assertEquals(doc2.title, "Gas constant"); }
@Test public void testGer() throws Exception { InputStream stream = PatternMatchingRelationFinder.class.getResourceAsStream("dewikimath-20151213130534.xml"); String rawImput = IOUtils.toString(stream,"UTF-8"); final String expected = IOUtils.toString(PatternMatchingRelationFinder.class.getResourceAsStream("text/deText.txt"),"UTF-8"); assertTrue(rawImput.contains("&lt;math")); String[] pages = rawImput.split("</page>"); TextExtractorMapper textExtractor = new TextExtractorMapper(); ListCollector<RawWikiDocument> out = new ListCollector<>(); for (String page : pages) { textExtractor.flatMap(page, out); } List<RawWikiDocument> output = out.getList(); assertEquals(1, output.size()); RawWikiDocument doc1 = output.get(0); assertEquals("Clapeyron-Gleichung", doc1.title); assertThat(doc1.text, not(containsString("&lt;math"))); assertThat(doc1.text, containsString("<math")); assertEquals(expected, doc1.text); }