File size: 1,293 Bytes
8a3de9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

def clear_text():
    """
    好像不需要
    """
    import json
    from tqdm import tqdm

    # dev_manifest = f"{YOUR_DATA_ROOT}/validation/validation_mozilla-foundation_common_voice_11_0_manifest.json"
    # test_manifest = f"{YOUR_DATA_ROOT}/test/test_mozilla-foundation_common_voice_11_0_manifest.json"
    train_manifest = f"data/common_voice_11_0/ja/train/train_common_voice_11_0_manifest.json"

    def compute_char_counts(manifest):
        char_counts = {}
        with open(manifest, 'r') as fn_in:
            for line in tqdm(fn_in, desc="Compute counts.."):
                line = line.replace("\n", "")
                data = json.loads(line)
                text = data["text"]
                for word in text.split():
                    for char in word:
                        if char not in char_counts:
                            char_counts[char] = 1
                        else:
                            char_counts[char] += 1
        return char_counts

    char_counts = compute_char_counts(train_manifest)

    threshold = 10
    trash_char_list = []

    for char in char_counts:
        if char_counts[char] <= threshold:
            trash_char_list.append(char)
    
    print(trash_char_list)

if __name__ == "__main__":
    # clear_text()
    pass