def add_annotataions_part(text_part, annotations, start_pos, end_pos, func_dict): """ Inserts annotations in a part of text (text_part) given an annotation list. Selects the annotations that are on that spam. Ajdusts the indexes wrap_text_with_tags calls """ if annotations is None or annotations == []: return text_part filtered_annotations = [] for annotation in annotations: annot_start = annotation["start"] annot_end = annotation["end"] if annot_start < start_pos: continue elif annot_start >= end_pos: continue new_annot = copy_dict(annotation) new_annot["start"] = annot_start - start_pos new_annot["end"] = annot_end - start_pos filtered_annotations.append(new_annot) new_text_part = wrap_text_with_tags(text_part, filtered_annotations, func_dict) return new_text_part