Skip to content

Commit be8d0e1

Browse files
committed
added transformation class that contains each step transformations
1 parent 31b5cca commit be8d0e1

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

models.py

+1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ def __init__(self, table, type='user_table'):
2121
'B': ['B0', 'B1', 'B2'],
2222
'id': ['K0', 'K1', 'K3']
2323
}))
24+
2425
}
2526

transformation_functions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pandas as pd
2-
from models import loaded_table_dict as table_dict
2+
from models import loaded_table_dict as table_dict, TableObj
33
import nlp_helpers
44
from models import join_types
55

@@ -25,7 +25,7 @@ def join(table_a, table_b):
2525

2626

2727
joined_table = pd.merge(table_a.table, table_b.table, how=TypeofJoin, left_on=matched_keys_left, right_on=matched_keys_right)
28-
return joined_table
28+
return TableObj(joined_table, 'tx_table')
2929

3030

3131
def union(table_a, table_b):

transformations.py

+24-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,36 @@
33
from transformation_functions import transformations_dict
44

55

6-
7-
86
# Class to contain a step and the transformation associated with that step
97
class TransformData:
108
def __init__(self, query):
119
language_token = helpers.ProcessLanguageTokens(query=query)
12-
table_list = models.loaded_table_dict.keys()
13-
transformation_list = transformations_dict.keys()
10+
table_list = list(models.loaded_table_dict.keys())
11+
transformation_list = list(transformations_dict.keys())
1412
self.matched_table = language_token.get_matches(table_list, threshold=94)
1513
self.matched_transformation = language_token.get_matches(transformation_list, threshold=90)[0]
1614
tx_fn = transformations_dict.get(self.matched_transformation)
1715
if not tx_fn:
1816
raise NotImplemented('This Transformation is not implemented yet!')
19-
self.transformation_function = tx_fn
17+
self.transformation_function = tx_fn
18+
19+
def load_table(self, table_name):
20+
table_a = models.loaded_table_dict.get(self.matched_table[0])
21+
table_b = models.loaded_table_dict.get(self.matched_table[1])
22+
if not table_a or not table_b:
23+
raise ValueError('Could Not Find Tables in loaded table list')
24+
models.loaded_table_dict[table_name] = self.transformation_function(table_a, table_b)
25+
26+
27+
# ----------------------- DEBUGGING -----------------------------------------
28+
29+
if __name__ == '__main__':
30+
i = 0
31+
query = ""
32+
list_of_transformations = []
33+
while query != 'end!':
34+
i += 1
35+
query = input('Enter Query. end! to stop\n-->')
36+
transformation = TransformData(query)
37+
transformation.load_table('step' + str(i))
38+
list_of_transformations.append(transformation)

0 commit comments

Comments
 (0)