from typing import Dict
from typing import List
from pathlib import Path
import string


def load_aligner_phones_lower(aligner_phone_path:str)->Dict[str,List[str]]:
    """Returns a dict mapping example_id to lowercase phonemes based on the input path to the
    aligner's phonemes.

    Args:
        aligner_phone_path (str): path to file output by `extract_phonemes` function
    
    Returns:
        (dict)
    """   
    phone_path = Path(aligner_phone_path)

    aligner_phones = dict()
    for row in phone_path.read_text().split('\n'):
        row = row.strip().split()
        if len(row) < 2:
            print(f"row: {row} as no phonemes")
            continue 
        
        file_id, phones = row[0], row[1:]
        # remove the digit and lower case
        phones = [phone.rstrip(string.digits).lower() for phone in phones]
        aligner_phones[file_id] = phones
    
    return aligner_phones