-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_new.py
94 lines (63 loc) · 2.57 KB
/
init_new.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#Open configuration file and load correct dictionaries with database schema
#Write the configuration file
import sqlite3
from sqlite3 import OperationalError
import pickle
from global_vars import get_sql_path, get_dict_path, get_model_path
from data_init import constructTokenToInputDict, createCleanTables
def loadConfig():
dbName=""
tableList = []
columnDict = {}
# file = open("config_mimic.txt", 'r') #todo:define file_path
file = open("config.txt", 'r') #todo:define file_path
lines = file.readlines() #todo:check readlines fucntion
for line in lines:
line = line.strip()
lineSplit = line.split(' = ')
if lineSplit[0] == 'db_name':
dbName = lineSplit[1] #Todo: add removing trailing and leading zeros
elif lineSplit[0] == 'tables_name':
tableList = lineSplit[1].split(', ')
elif lineSplit[0] == 'columns_header':
colList = lineSplit[1].split(', ')
for col in colList:
colSplit = col.split(":")
tabName = colSplit[0]
colName = colSplit[1]
if tabName not in columnDict:
columnDict[tabName] = []
columnDict[tabName].append(colName)
#todo: load the inputIdsMatrix from the file stored by data_init after construction
#tokenToInputIdDict=pickle.load(open("entity_dict.pkl","rb"))
print("DBName: "+dbName)
return dbName, tableList,columnDict
#db, tableList, colHeaderList = loadConfig()
#print(db)
#print(str(tableList))
#print(str(colHeaderList.values()))
# called once to construct the tokenToInputIds map
#constructTokenToInputDict(colHeaderList)
#Load the input ids dictionary -- tokenToInputIdDict
def getTokenInputIds(colHeaderDict):
tokenIdsDict = {}
inputIdsMatrix = pickle.load(open("entity_dict.pkl","rb"))
for table in colHeaderDict:
for col in colHeaderDict[table]:
tokenIdsDict[table+"."+col] = inputIdsMatrix[table+"."+col]
tokenIdsDict[table+"."+col]['<MASK>'] = len(tokenIdsDict[table+"."+col])
tokenIdsDict['table'] = inputIdsMatrix['table']
tokenIdsDict['spec'] = inputIdsMatrix['spec']
return tokenIdsDict
def newGetTokenInputIds(colHeaderList):
tokenIdsDict = {}
dict_path= get_dict_path()
inputIdsMatrix = pickle.load(open(dict_path+"entity_dict.pkl","rb"))
print(str(inputIdsMatrix.keys()))
for key in colHeaderList:
if ((key != 'spec') and (key != 'table') and (key != 'en')):
tokenIdsDict[key] = inputIdsMatrix[key]
tokenIdsDict[key]['<MASK>'] = len(tokenIdsDict[key])
tokenIdsDict['table'] = inputIdsMatrix['table']
tokenIdsDict['spec'] = inputIdsMatrix['spec']
return tokenIdsDict