def parse_phrase_book(fname):
    phrases = []
    current_phrase = None
    for line_number, line in enumerate(open(fname).readlines()):
        line = line.strip()
        if line.startswith('#'):
            # Ignore lines with comments.
            continue
        elif len(line) == 0:
            # Empty lines reset the phrase.
            current_phrase = None
        elif line.startswith('- '):
            # Phrases are prefixed with "- ".
            if current_phrase is None:
                raise ValueError("%s: line without a key." % line_number)
            else:
                current_phrase['values'].append(line[2:].strip())
        elif line.endswith(':'):
            # Keys end with ":"
            current_phrase = {'key': line[:-1], 'values': []}
            phrases.append(current_phrase)
        else:
            raise ValueError('%s: do not know what to do with line "%s".' % (line_number, line))
    phrase_book = {}
    for phrase in phrases:
        phrase_book[phrase['key']] = phrase['values']
    return phrase_book
dataset/ETHPy150Open fdb/choicewords/choicewords.py/parse_phrase_book/original