MCPcopy Create free account
hub / github.com/BIT-DataLab/LakeBench / alignment_process

Function alignment_process

union/TUS/run_c_alignment.py:125–190  ·  view source on GitHub ↗
(query, candiate, model, type = 'cal')

Source from the content-addressed store, hash-verified

123
124
125def alignment_process(query, candiate, model, type = 'cal'):
126 #query和candiate分别是两个表,然后需要提出他们的column当作节点
127 def compute_score(args):
128 s_name, t_name, s, t, s_sem, t_sem, m = args
129 logging.info(f"Processing: {s_name, t_name}")
130 score = compute_ensemble_score(s, t, s_sem, t_sem, m)
131 return s_name, t_name, score
132
133 df_query = pd.read_csv('benchmark/' + query)
134 df_cand = pd.read_csv('benchmark/' + candiate)
135 df_query_sem = pd.read_csv('UsemLshTest/' + query)
136 df_cand_sem = pd.read_csv('UsemLshTest/'+ candiate)
137 G = nx.Graph()
138 query_columns = list(df_query.columns)
139 query_columns = [query+' '+l for l in query_columns]
140 cand_columns = list(df_cand.columns)
141 cand_columns = [candiate+' '+l for l in cand_columns]
142 G.add_nodes_from(query_columns, bipartite=0)
143 G.add_nodes_from(cand_columns, bipartite=1)
144 max_c = min(len(query_columns), len(cand_columns))#最大的c
145
146 task_list = []
147 for attr_s in query_columns:
148 s_name = attr_s.split(maxsplit=1)[1]
149 s = df_query[s_name]
150 s_sem = df_query_sem[s_name]
151 for attr_t in cand_columns:
152 t_name = attr_t.split(maxsplit=1)[1]
153 t = df_cand[t_name]
154 t_sem = df_cand_sem[t_name]
155
156 task_list.append((attr_s, attr_t, s, t, s_sem, t_sem, model))
157
158 with ProcessPoolExecutor(max_workers = 4) as executor:
159 results = executor.map(compute_score, task_list)
160
161 for s_name, t_name, score in results:
162 G.add_edge(s_name, t_name, weight=score)
163
164 matching = {}
165 edges = sorted(G.edges(data=True), key=lambda x: x[2]['weight'], reverse=True)
166 max_c_scores = {}
167 c = 1
168 mul = 1
169 for u, v, d in edges:
170 if u in matching or v in matching.values():
171 continue
172 matching[u] = [v, d['weight']]
173 mul = mul * d['weight']
174 max_c_scores[c] = mul
175 c += 1
176 if len(matching) == max_c:
177 break
178 if type == 'distribution':
179 return max_c_scores
180
181 goodness_score = 0
182 best_c = 1

Callers 1

cal_max_c_alignmentFunction · 0.85

Calls 1

get_c_goodnessFunction · 0.70

Tested by

no test coverage detected