def read_lexiconp(filename):
    "Reads the lexiconp.txt file in 'filename', with lines like 'word pron p1 p2 ...'.\n    Returns a list of tuples (word, pron_prob, pron), where 'word' is a string,\n   'pron_prob', a float, is the pronunciation probability (which must be >0.0\n    and would normally be <=1.0),  and 'pron' is a list of strings representing phones.\n    An element in the returned list might be ('hello', 1.0, ['h', 'eh', 'l', 'ow']).\n    "
    ans = []
    found_empty_prons = False
    found_large_pronprobs = False
    with open(filename, 'r', encoding='latin-1') as f:
        whitespace = re.compile('[ \t]+')
        for line in f:
            a = whitespace.split(line.strip(' \t\r\n'))
            if (len(a) < 2):
                print("{0}: error: found bad line '{1}' in lexicon file {2} ".format(sys.argv[0], line.strip(' \t\r\n'), filename), file=sys.stderr)
                sys.exit(1)
            word = a[0]
            if (word == '<eps>'):
                print('{0}: error: found <eps> as a word in lexicon file {1}'.format(line.strip(' \t\r\n'), filename), file=sys.stderr)
                sys.exit(1)
            try:
                pron_prob = float(a[1])
            except:
                print("{0}: error: found bad line '{1}' in lexicon file {2}, 2nd field should be pron-prob".format(sys.argv[0], line.strip(' \t\r\n'), filename), file=sys.stderr)
                sys.exit(1)
            prons = a[2:]
            if (pron_prob <= 0.0):
                print("{0}: error: invalid pron-prob in line '{1}' of lexicon file {1} ".format(sys.argv[0], line.strip(' \t\r\n'), filename), file=sys.stderr)
                sys.exit(1)
            if (len(prons) == 0):
                found_empty_prons = True
            ans.append((word, pron_prob, prons))
            if (pron_prob > 1.0):
                found_large_pronprobs = True
    if found_empty_prons:
        print('{0}: warning: found at least one word with an empty pronunciation in lexicon file {1}.'.format(sys.argv[0], filename), file=sys.stderr)
    if found_large_pronprobs:
        print('{0}: warning: found at least one word with pron-prob >1.0 in {1}'.format(sys.argv[0], filename), file=sys.stderr)
    if (len(ans) == 0):
        print('{0}: error: found no pronunciations in lexicon file {1}'.format(sys.argv[0], filename), file=sys.stderr)
        sys.exit(1)
    return ans
Reads the lexiconp.txt file in 'filename', with lines like 'word pron p1 p2 ...'.
 Returns a list of tuples (word, pron_prob, pron), where 'word' is a string,
'pron_prob', a float, is the pronunciation probability (which must be >0.0
 and would normally be <=1.0),  and 'pron' is a list of strings representing phones.
 An element in the returned list might be ('hello', 1.0, ['h', 'eh', 'l', 'ow']).
def read_lexiconp(filename):
    "Reads the lexiconp.txt file in 'filename', with lines like 'word pron p1 p2 ...'.\n    Returns a list of tuples (word, pron_prob, pron), where 'word' is a string,\n   'pron_prob', a float, is the pronunciation probability (which must be >0.0\n    and would normally be <=1.0),  and 'pron' is a list of strings representing phones.\n    An element in the returned list might be ('hello', 1.0, ['h', 'eh', 'l', 'ow']).\n    "
    ans = []
    found_empty_prons = False
    found_large_pronprobs = False
    with open(filename, 'r', encoding='latin-1') as f:
        whitespace = re.compile('[ \t]+')
        for line in f:
            a = whitespace.split(line.strip(' \t\r\n'))
            if (len(a) < 2):
                print("{0}: error: found bad line '{1}' in lexicon file {2} ".format(sys.argv[0], line.strip(' \t\r\n'), filename), file=sys.stderr)
                sys.exit(1)
            word = a[0]
            if (word == '<eps>'):
                print('{0}: error: found <eps> as a word in lexicon file {1}'.format(line.strip(' \t\r\n'), filename), file=sys.stderr)
                sys.exit(1)
            try:
                pron_prob = float(a[1])
            except:
                print("{0}: error: found bad line '{1}' in lexicon file {2}, 2nd field should be pron-prob".format(sys.argv[0], line.strip(' \t\r\n'), filename), file=sys.stderr)
                sys.exit(1)
            prons = a[2:]
            if (pron_prob <= 0.0):
                print("{0}: error: invalid pron-prob in line '{1}' of lexicon file {1} ".format(sys.argv[0], line.strip(' \t\r\n'), filename), file=sys.stderr)
                sys.exit(1)
            if (len(prons) == 0):
                found_empty_prons = True
            ans.append((word, pron_prob, prons))
            if (pron_prob > 1.0):
                found_large_pronprobs = True
    if found_empty_prons:
        print('{0}: warning: found at least one word with an empty pronunciation in lexicon file {1}.'.format(sys.argv[0], filename), file=sys.stderr)
    if found_large_pronprobs:
        print('{0}: warning: found at least one word with pron-prob >1.0 in {1}'.format(sys.argv[0], filename), file=sys.stderr)
    if (len(ans) == 0):
        print('{0}: error: found no pronunciations in lexicon file {1}'.format(sys.argv[0], filename), file=sys.stderr)
        sys.exit(1)
    return ans