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

Function alignment

union/TUS/main.py:72–119  ·  view source on GitHub ↗
(query, candiate, type = 'cal')

Source from the content-addressed store, hash-verified

70
71
72def alignment(query, candiate, type = 'cal'):
73 #query和candiate分别是两个表,然后需要提出他们的column当作节点
74 df_query = pd.read_csv('benchmark/' + query)
75 df_cand = pd.read_csv('benchmark/' + candiate)
76 df_query_sem = pd.read_csv('UsemLshTest/' + query)
77 df_cand_sem = pd.read_csv('UsemLshTest/'+ candiate)
78 G = nx.Graph()
79 query_columns = list(df_query.columns)
80 query_columns = [query+' '+l for l in query_columns]
81 cand_columns = list(df_cand.columns)
82 cand_columns = [candiate+' '+l for l in cand_columns]
83 G.add_nodes_from(query_columns, bipartite=0)
84 G.add_nodes_from(cand_columns, bipartite=1)
85 max_c = min(len(query_columns), len(cand_columns))#最大的c
86 for attr_s in query_columns:
87 for attr_t in cand_columns:
88 s_name = attr_s.split(maxsplit=1)[1]
89 t_name = attr_t.split(maxsplit=1)[1]
90 score = compute_ensemble_score(df_query[s_name], df_cand[t_name], df_query_sem[s_name], df_cand_sem[t_name])
91 G.add_edge(attr_s, attr_t, weight=score)
92
93 matching = {}
94 edges = sorted(G.edges(data=True), key=lambda x: x[2]['weight'], reverse=True)
95 max_c_scores = {}
96 c = 1
97 mul = 1
98 for u, v, d in edges:
99 if u in matching or v in matching.values():
100 continue
101 matching[u] = [v, d['weight']]
102 mul = mul * d['weight']
103 max_c_scores[c] = mul
104 c += 1
105 if len(matching) == max_c:
106 break
107 if type == 'distribution':
108 return max_c_scores
109
110 goodness_score = 0
111 best_c = 1
112 for c, max_c_score in max_c_scores.items():
113 c_goodness = get_c_goodness(c, max_c_score)
114 if c_goodness >= goodness_score:
115 goodness_score = c_goodness
116 best_c = c
117 sorted_matching = sorted(matching.items(), key = lambda item : item[1][1], reverse=True)
118
119 return sorted_matching[:best_c], goodness_score
120
121
122def cal_max_c_alignment(folder_path = 'benchmark'):

Callers 2

cal_max_c_alignmentFunction · 0.70
mainFunction · 0.70

Calls 2

compute_ensemble_scoreFunction · 0.70
get_c_goodnessFunction · 0.70

Tested by

no test coverage detected