<jupyter_start><jupyter_text>Extract phonemes from merlin lab files> "🤷 It came up"- toc: false- branch: master- hidden: false- categories: [lab, merlin]<jupyter_code>def break_phones(string):
    i = 0
    mark = 0
    toks = []
    pieces = {
        0: '^',
        1: '-',
        2: '+',
        3: '=',
        4: '@'
    }
    piece = 0
    while i <= len(string):
        if string[i:i+1] == pieces[piece]:
            if piece < 4:
                toks.append(string[mark:i])
            else:
                if string[i+1:i+2].isdigit():
                    toks.append(string[mark:i])
                else:
                    toks.append("@")
                break
            piece += 1
            mark = i + 1
        i += 1
    return toks
assert break_phones('nnj^ii-lj+sil=@@3_2/') == ['nnj', 'ii', 'lj', 'sil', '@']
assert break_phones("x^sil-nnj+ii=lj@1_4") == ['x', 'sil', 'nnj', 'ii', 'lj']
assert break_phones("oo^r-sil+x=x@1_1") == ['oo', 'r', 'sil', 'x', 'x']
def read_phonemes_lab(filename):
    phn_bits = []
    with open(filename, "r") as f:
        for line in f.readlines():
            _, _, phones = line.split(' ')
            phones = break_phones(phones)
            phn_bits.append(phones)
    return phn_bits        
# Dumb way of doing this, but it works
def check_len(phone_list):
    length = str(len(phone_list))
    return (length[-1] == "0" or length[-1] == "5")
def prune_phones(phone_list):
    if not check_len(phone_list):
        return []
    return [a[2] for a in phone_list[::5]]
lab_phonemes_raw = {a: read_phonemes_lab(b) for (a, b) in label_files.items()}
lab_phonemes = {a: prune_phones(b) for (a, b) in lab_phonemes_raw.items()}<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17016317016317017, 'fraction_numerical': 0.015734265734265736, 'mean_word_length': 2.239622641509434, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '639708', 'license': 'Apache-2.0', 'n_tokens_mistral': 641, 'n_tokens_neox': 623, 'n_words': 144, 'path': '_notebooks/2021-10-08-extract-phonemes-from-merlin-lab-files.ipynb', 'repo_name': 'jimregan/notes', 'size': '1716'}