class 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;
    }

    public  AnnotationRuleEngine(InputStream inputStream);

}