-
Notifications
You must be signed in to change notification settings - Fork 0
/
csv_table2VecE_star_sp.py
64 lines (48 loc) · 1.31 KB
/
csv_table2VecE_star_sp.py
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
61
62
63
import json
import os
from os.path import isfile,join
def process_file(inputfile,fw):
fr = open(inputfile,'r')
readline = fr.read()
#print(readline)
loadjson = json.loads(readline)
#print(loadjson)
#get the level 1 keys of json (level 1 keys are table name)
keys = loadjson.keys()
#print(keys)
for key in keys:
#print(key)
#print(loadjson[key])
col = int(loadjson[key]['numCols'])
#print(col)
row = int(loadjson[key]['numDataRows'])
#print(row)
# [ all table cells column wise]
#data = str(key+"\t")
data = ""
for i in range(min(1,col)):
for j in range(row):
ij = loadjson[key]['data'][j][0]
#print(loadjson[key]['data'][j][i])
jj = ij.replace("\n"," ")
jj = jj.replace("\t"," ")
#jj = jj.replace(" ","_")
data = data + str(jj) + " "
data = str(key+"\t")+data
fw.write(data+"\n")
#print(data)
#break
#close the open files
fr.close()
# open the folder and read the files and folder in that folder
folder = input("Enter the folder loaction of the corpus : ")
file_list = os.listdir(folder)
outputfile = input("Enter the file name to write : ")
fw = open(outputfile,'w')
for files in file_list:
# check if it is a file
if isfile(join(folder,files)):
process_file(join(folder,files),fw)
print(files," : is processed")
#break
fw.close()