import re


def parse_text_annotations(ann_file):
    """ Parses BRAT annotations provided in the .ann file and converts them
        to annotation spans of (start_position, end_position, entity_class).

        Args:
            ann_file (str): full path to the BRAT .ann file.

        Returns:
            annotations (list((int, int, str))): list of annotation spans.
                Spans are triples of (start_offset, end_offset, entity_class)
                where offset is relative to the text.
    """
    annots = []
    fann = open(ann_file, "r")
    for line in fann:
        cols = re.split(r"\s+", line.strip())
        if not cols[0].startswith("T"):
            continue
        annots.append((int(cols[2]), int(cols[3]), cols[1]))
    fann.close()
    return annots