File size: 1,426 Bytes
003505d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
48
from bs4 import BeautifulSoup

if __name__ == "__main__":
    f = open("./amitaro.htm", "r")
    txt = f.read()
    soup = BeautifulSoup(txt)

    import json
    f = open('amitaro.json')
    file_list = json.load(f)

    td = soup.find_all('td')
    for i, val in enumerate(td):
        if len(val.contents) == 0:
            continue
        key = val.contents[0]
        if key in file_list:
            #print(td[i-1].contents[0])
            if len(td[i-1].contents) > 0:
                #print(td[i-1].contents[0])
                temp = BeautifulSoup(str(td[i-1].contents[0]))
                a = temp.find_all('a')
                print(a[0].contents[0])
                file_list[key]["kana"] = str(a[0].contents[0])
                
    for key, val in file_list.items():
        val["path"] = "./amitaro/" + val["path"]

    with open("./amitaro_with_kana.json", "w") as outfile:
        outfile.write(json.dumps(file_list, indent=4,ensure_ascii=False))
        
    file = []
    for key, val in file_list.items():
        if len(val['kana']) == 0:
            continue
        if val['kana'].find("(") != -1:
            continue
        file.append(f"{val['path']}|0|{val['kana']}")
        
    amitaro_train = []
    amitaro_val = []
    for val in file:
        amitaro_train.append(val)
        
    f = open("amitaro_train.txt", "w")
    for val in amitaro_train:
        f.write(f"{val}\n")
    f.close()