def _build_annotations(self):
 
        elements = dict()
        ids = dict()

        current_record_id = 0
        current_utterance_id = 0
        current_id = 0

        first_marker_found = False
        tier_marker = None

        current_utterance = None

        # Go through lines in the input file
        for line_number, line in enumerate(self.input_stream):
            # remove BOM
            if line_number == 0:

                if line.startswith(codecs.BOM_UTF8):
                    line = line[BOMLEN:]
                    
            line = line.decode("utf-8", 'ignore')
            line = line.strip()

            if "\name" in line:
                self.meta_information = line.split(None,2)[2]

            if line == "":
                if len(elements) > 0:
                    self._process_record(elements, ids, current_utterance_id)
                    elements = dict()
                    ids = dict()
                continue

            # parse line
            last_tier_marker = tier_marker
            tier_marker = None
            line_content = None
            match_tier_marker = re_tier_marker.search(line)
            if match_tier_marker:
                tier_marker = match_tier_marker.group(1)
                line_content = re_tier_marker.sub("", line)
                line_content = line_content.lstrip()
            elif first_marker_found:
                # append to last annotation´s content
                id_to_add = current_record_id
                if last_tier_marker in self.utterance_level_markers:
                    id_to_add = current_utterance_id

                if self._tier_labels.tier_label_exists(last_tier_marker):
                    self._annotations_for_parent[
                        ("a{0}".format(id_to_add),
                            last_tier_marker)][-1].value += " " + \
                            line

                tier_marker = last_tier_marker
                continue

            # skip all lines before first record marker
            if not first_marker_found:
                if tier_marker != self.record_marker:
                    continue
                else:
                    first_marker_found = True

            if tier_marker in self.word_level_markers:
                # Is it a new utterance? Then create a new ID.
                if current_utterance is None:
                    current_utterance = ""

                if current_utterance == "":
                    current_utterance_id = current_id
                    current_id += 1

                current_utterance += re.sub("\s+", " ", line_content) + " "

            if tier_marker in self.word_level_markers or \
                    tier_marker in self.morpheme_level_markers or \
                    tier_marker in self.tag_level_markers:

                if tier_marker not in elements:
                    elements[tier_marker] = dict()
                if tier_marker not in ids:
                    ids[tier_marker] = dict()

                for j, match in enumerate(re_word.finditer(line)):
                    pos = char_len(line[:match.start(1)])
                    elements[tier_marker][pos] = match.group(1)
                    ids[tier_marker][pos] = "a{0}".format(current_id)
                    current_id += 1

            # utterance level markers
            elif tier_marker in self.utterance_level_markers:

                # we left the utterance tiers, so create an utterance
                # annotation based on the content and make it the current
                # utterance
                if current_utterance is not None and current_utterance != "":
                    current_utterance = current_utterance.rstrip()
                    self._annotate_utterance(current_record_id,
                                             current_utterance_id,
                                             current_utterance)

                    current_utterance = ""

                elif current_utterance is None:
                    current_utterance_id = current_id
                    current_id += 1
                    self._annotate_utterance(current_record_id,
                                             current_utterance_id, "")

                    current_utterance = ""

                # add the annotation to the current utterance
                self._annotations_for_parent[
                    ("a{0}".format(current_utterance_id), tier_marker)].append(
                        poioapi.io.graf.Annotation(
                            "a{0}".format(current_id), line_content))
                current_id += 1

            # record level markers
            elif tier_marker in self.record_level_markers:

                if tier_marker == self.record_marker:
                    # this is to ensure that the utterance get annotated even
                    # if there were no other utterance_level_markers to cause
                    # it to be
                    if current_utterance is not None and current_utterance != '':
                        self._annotate_utterance(current_record_id,
                                                 current_utterance_id,
                                                 current_utterance)

                    self._annotations_for_parent[
                        (None, tier_marker)].append(
                            poioapi.io.graf.Annotation(
                                "a{0}".format(current_id), line_content))
                    current_record_id = current_id
                    current_id += 1
                    current_utterance = None

                else:
                    # this is to ensure that the utterance get annotated even
                    # if there were no other utterance_level_markers to cause
                    # it to be
                    if current_utterance is not None and current_utterance != '':
                        self._annotate_utterance(current_record_id,
                                                 current_utterance_id,
                                                 current_utterance)

                    self._annotations_for_parent[
                        ("a{0}".format(current_record_id), tier_marker)].append(
                            poioapi.io.graf.Annotation(
                                "a{0}".format(current_id), line_content))

                    current_id += 1

        self.input_stream.seek(0)
Helper method to parse the input file and store intermediate information
dataset/ETHPy150Open cidles/poio-api/src/poioapi/io/toolbox.py/Parser._build_annotations