# Path: swbd/labels/fisher/fix_trans.py
# def fix_transcript(transcript):
# 
#     # Replace with special symbols
#     transcript = re.sub(r'\[laughter\]', LAUGHTER, transcript)
#     transcript = re.sub(r'\[laugh\]', LAUGHTER, transcript)
#     transcript = re.sub(r'\[noise\]', NOISE, transcript)
#     transcript = re.sub(r'\[sigh\]', NOISE, transcript)
#     transcript = re.sub(r'\[cough\]', NOISE, transcript)
#     transcript = re.sub(r'\[mn\]', NOISE, transcript)
#     transcript = re.sub(r'\[breath\]', NOISE, transcript)
#     transcript = re.sub(r'\[lipsmack\]', NOISE, transcript)
#     transcript = re.sub(r'\[sneeze\]', NOISE, transcript)
#     transcript = re.sub('&', ' and ', transcript)
# 
#     # Remove
#     transcript = re.sub(r'\[pause\]', '', transcript)
#     transcript = re.sub(r'\[\[skip\]\]', '', transcript)
#     transcript = re.sub(r'\?', '', transcript)
#     transcript = re.sub(r'\*', '', transcript)
#     transcript = re.sub(r'~', '', transcript)
#     transcript = re.sub(r'\,', '', transcript)
#     transcript = re.sub(r'\.', '', transcript)
# 
#     # Remove sentences which include german words
#     german = re.match(r'(.*)<german (.+)>(.*)', transcript)
#     if german is not None:
#         transcript = ''
# 
#     # Remove ((  ))
#     transcript = re.sub(r'\(\([\s]+\)\)', '', transcript)
#     kakko_expr = re.compile(r'(.*)\(\( ([^(]+) \)\)(.*)')
#     while re.match(kakko_expr, transcript) is not None:
#         kakko = re.match(kakko_expr, transcript)
#         transcript = kakko.group(1) + kakko.group(2) + kakko.group(3)
# 
#     # remove "/"
#     # transcript = re.sub('/', '', transcript)
# 
#     # Remove double spaces
#     while '  ' in transcript:
#         transcript = re.sub(r'[\s]+', ' ', transcript)
# 
#     return transcript


from os.path import basename
from tqdm import tqdm
from collections import OrderedDict
from swbd.labels.fisher.fix_trans import fix_transcript
import re
        char_set (set):
        char_capital_set (set):
        word_count_dict (dict):
            key => word
            value => the number of words in Fisher corpus
    """
    print('=====> Processing target labels...')
    speaker_dict = OrderedDict()
    char_set, char_capital_set = set([]), set([])
    word_count_dict = {}
    vocab_set = set([])

    for label_path in tqdm(label_paths):
        utterance_dict = OrderedDict()
        with open(label_path, 'r') as f:
            utt_index = 0
            session = basename(label_path).split('.')[0]
            for line in f:
                line = line.strip().split(' ')
                if line[0] in ['#', '']:
                    continue
                start_frame = int(float(line[0]) * 100 + 0.05)
                end_frame = int(float(line[1]) * 100 + 0.05)
                which_speaker = line[2].replace(':', '')
                if which_speaker != target_speaker:
                    continue
                speaker = session + '-' + which_speaker

                # Clean transcript
                transcript_original = ' '.join(line[3:]).lower()

# Path: swbd/labels/fisher/fix_trans.py
# def fix_transcript(transcript):
# 
#     # Replace with special symbols
#     transcript = re.sub(r'\[laughter\]', LAUGHTER, transcript)
#     transcript = re.sub(r'\[laugh\]', LAUGHTER, transcript)
#     transcript = re.sub(r'\[noise\]', NOISE, transcript)
#     transcript = re.sub(r'\[sigh\]', NOISE, transcript)
#     transcript = re.sub(r'\[cough\]', NOISE, transcript)
#     transcript = re.sub(r'\[mn\]', NOISE, transcript)
#     transcript = re.sub(r'\[breath\]', NOISE, transcript)
#     transcript = re.sub(r'\[lipsmack\]', NOISE, transcript)
#     transcript = re.sub(r'\[sneeze\]', NOISE, transcript)
#     transcript = re.sub('&', ' and ', transcript)
# 
#     # Remove
#     transcript = re.sub(r'\[pause\]', '', transcript)
#     transcript = re.sub(r'\[\[skip\]\]', '', transcript)
#     transcript = re.sub(r'\?', '', transcript)
#     transcript = re.sub(r'\*', '', transcript)
#     transcript = re.sub(r'~', '', transcript)
#     transcript = re.sub(r'\,', '', transcript)
#     transcript = re.sub(r'\.', '', transcript)
# 
#     # Remove sentences which include german words
#     german = re.match(r'(.*)<german (.+)>(.*)', transcript)
#     if german is not None:
#         transcript = ''
# 
#     # Remove ((  ))
#     transcript = re.sub(r'\(\([\s]+\)\)', '', transcript)
#     kakko_expr = re.compile(r'(.*)\(\( ([^(]+) \)\)(.*)')
#     while re.match(kakko_expr, transcript) is not None:
#         kakko = re.match(kakko_expr, transcript)
#         transcript = kakko.group(1) + kakko.group(2) + kakko.group(3)
# 
#     # remove "/"
#     # transcript = re.sub('/', '', transcript)
# 
#     # Remove double spaces
#     while '  ' in transcript:
#         transcript = re.sub(r'[\s]+', ' ', transcript)
# 
#     return transcript


# Path: swbd/labels/fisher/character.py
from os.path import basename
from tqdm import tqdm
from collections import OrderedDict
from swbd.labels.fisher.fix_trans import fix_transcript
import re

        char_set (set):
        char_capital_set (set):
        word_count_dict (dict):
            key => word
            value => the number of words in Fisher corpus
    """
    print('=====> Processing target labels...')
    speaker_dict = OrderedDict()
    char_set, char_capital_set = set([]), set([])
    word_count_dict = {}
    vocab_set = set([])

    for label_path in tqdm(label_paths):
        utterance_dict = OrderedDict()
        with open(label_path, 'r') as f:
            utt_index = 0
            session = basename(label_path).split('.')[0]
            for line in f:
                line = line.strip().split(' ')
                if line[0] in ['#', '']:
                    continue
                start_frame = int(float(line[0]) * 100 + 0.05)
                end_frame = int(float(line[1]) * 100 + 0.05)
                which_speaker = line[2].replace(':', '')
                if which_speaker != target_speaker:
                    continue
                speaker = session + '-' + which_speaker

                # Clean transcript
                transcript_original = ' '.join(line[3:]).lower()

                transcript = fix_transcript(transcript_original)