File size: 1,427 Bytes
2c8dc05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
import os, shutil
from uparser import wordparse
from joblib import Parallel, delayed
from tqdm import tqdm

num_jobs = 20
infolder = 'Words'
outfolder = 'Outputs'

for fdr in [outfolder]:
    if os.path.exists(fdr):
        shutil.rmtree(fdr)
    os.mkdir(fdr)

langs = []
langwdmap = {}

flist = os.listdir(infolder)
for fname in flist:
    with open(f'{infolder}/{fname}', 'r') as f:
        cnts = f.readlines()

    i = 0
    
    words = []
    for l in cnts:
        l = l.strip().split('\t')
        words.append(l[0])
    
    lan = fname.split('.')[0]
    langs.append(lan)
    langwdmap[lan] = words

for opt in [0,1,2]:
    out_cur = outfolder + '/option-' + str(opt)
    os.mkdir(out_cur)
    anslist=[]
    for l in langs:
        words = langwdmap[l]
        print(words)
        print(len(words))
        print(l)
        if opt == 1:
            anslist = Parallel(n_jobs=num_jobs)(delayed(wordparse)(wd, 0, opt, 1) for wd in tqdm(words))
        else:
            anslist = Parallel(n_jobs=num_jobs)(delayed(wordparse)(wd, 0, opt, 0) for wd in tqdm(words))
        # for wd in range(len(words)):
        #     temp_ans=wordparse(words[wd], 0, 0, 0)
        #     print(wd)
        #     anslist.append(temp_ans)



        with open(f'{out_cur}/{l}.output', 'w') as f:
            for i in range(len(words)):
                f.write(f'{words[i]}\t{anslist[i]}\n')
        
        print(f'completed {l}')