def _get_text_type_ann_map(ann_objs, restrict_types=None, ignore_types=None,
    nested_types=None):
    """
    Helper function for search. Given annotations, returns a
    dict-of-dicts, outer key annotation text, inner type, values
    annotation objects.
    """
    restrict_types = [] if restrict_types is None else restrict_types
    ignore_types = [] if ignore_types is None else ignore_types
    nested_types = [] if nested_types is None else nested_types
    text_type_ann_map = {}
    for ann_obj in ann_objs:
        for text in ann_obj.get_textbounds():
            if text.type in ignore_types:
                continue
            if restrict_types != [] and text.type not in restrict_types:
                continue
            if text.text not in text_type_ann_map:
                text_type_ann_map[text.text] = {}
            if text.type not in text_type_ann_map[text.text]:
                text_type_ann_map[text.text][text.type] = []
            text_type_ann_map[text.text][text.type].append((ann_obj, text))
    return text_type_ann_map
