private void getAnnotationClasses(int from, int to, Set<AnnotationClass> classes) {
        if (!contains(from, to)) {
            return;
        }
        classes.addAll(annotations.keySet());
        for (Span subSpan : getSubSpans()) {
            subSpan.getAnnotationClasses(from, to, classes);
        }
    }
How this works:

First we check if any excisting subannotation can contain this annotation. If so, we leave it to them to add
the new annotation.

Then we check if the new annotation intersects any of the excisting annotations. That is illegal to do

We then add all subannotations that are strictly contained in the new annotation to the new annotation.
container-search/src/main/java/com/yahoo/text/interpretation/Span.java