def add_attributes_to_annotations(markup): """ For each tag add the tag id as annotation to the tag text. """ markup = copy_dict(markup) attr_markup = {} for idx in markup: new_tags = [] for tag in markup[idx]: new_tag = add_attribute_to_tag(copy_dict(tag)) new_tags.append(new_tag) attr_markup[idx] = new_tags return attr_markup
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