private Annotations getBestAnnotation(int from, int to, AnnotationClass clazz) {
        if (!contains(from, to)) {
            return null;
        }
        // First yourself, then the subs
        Annotations annotations = this.annotations.get(clazz);
        for (Span subSpan : getSubSpans()) {
            Annotations subAnnotations = subSpan.getBestAnnotation(from, to, clazz);
            if (subAnnotations != null) {
                annotations = subAnnotations;
            }
        }
        return annotations;
    }
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