### Question:
AnnotationRuleEngine { public List<ClassifiedAnnotation> apply(String text, List<? extends Annotation> annotations) { Map<Annotation, CategoryEntriesBuilder> probabilities = new LinkedHashMap<>(); for (Annotation annotation : annotations) { probabilities.put(annotation, new CategoryEntriesBuilder()); } for (Annotation annotation : annotations) { for (Rule rule : rules) { rule.apply(annotation, text, probabilities); } } List<ClassifiedAnnotation> result = new ArrayList<>(); for (Entry<Annotation, CategoryEntriesBuilder> resultEntry : probabilities.entrySet()) { result.add(new ClassifiedAnnotation(resultEntry.getKey(), resultEntry.getValue().create())); } return result; } AnnotationRuleEngine(InputStream inputStream); List<ClassifiedAnnotation> apply(String text, List<? extends Annotation> annotations);  }### Answer:
@Test public void testRuleEngine() throws FileNotFoundException { InputStream ruleFile = ResourceHelper.getResourceStream("/ruleEngine.rules"); AnnotationRuleEngine ruleEngine = new AnnotationRuleEngine(ruleFile); String sampleText = "English is the language of the world. There is a place called English Lake in Indiana. Mr. Smith speaks English. It is common within Great Britain to speak English, Mr. John Smith commented. John likes marvel cakes. Let's make a trip to Miami, yes Miami is nice! The incredibly beautiful River Neckar flows through Stuttgart. And the Neckar also flows through Heilbronn. USA, US, GB, XY, yeah."; List<Annotation> annotations = StringTagger.INSTANCE.getAnnotations(sampleText); List<ClassifiedAnnotation> result = ruleEngine.apply(sampleText, annotations); assertEquals(17, result.size()); Iterator<ClassifiedAnnotation> iterator = result.iterator(); assertEquals(null, iterator.next().getTag()); assertEquals(null, iterator.next().getTag()); assertEquals(null, iterator.next().getTag()); assertEquals(null, iterator.next().getTag()); assertEquals("LOC", iterator.next().getTag()); assertEquals(null, iterator.next().getTag()); assertEquals("LOC", iterator.next().getTag()); assertEquals("LOC", iterator.next().getTag()); assertEquals(null, iterator.next().getTag()); assertEquals("LOC", iterator.next().getTag()); assertEquals(null, iterator.next().getTag()); assertEquals(null, iterator.next().getTag()); assertEquals("LOC", iterator.next().getTag()); assertEquals(null, iterator.next().getTag()); assertEquals(null, iterator.next().getTag()); assertEquals(null, iterator.next().getTag()); }