import re


def read_words(path):
    """
    Get all word info from a BAS partitur file

    Parameters
    ----------
    path : str
        a path to the file
    Returns
    -------
    dict
        dictionary of words and their indexes
    """
    words = {}
    with open(path, 'r', encoding='utf8') as f:
        lines = f.readlines()
    for line in lines:
        splitline = re.split("\s", line)
        if splitline[0] == 'ORT:':
            try:
                words[splitline[1]][0] = splitline[2]
            except KeyError:
                words[splitline[1]] = [None, None]
                words[splitline[1]][0] = splitline[2]
                # words.update({splitline[1].strip():splitline[2].strip()})
        if splitline[0] == 'KAN:':
            try:
                words[splitline[1]][-1] = splitline[2]
            except KeyError:
                words[splitline[1]] = [None, None]
                words[splitline[1]][-1] = splitline[2]
    return words