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

Function alignment

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

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.70

Calls 2

compute_ensemble_scoreFunction · 0.70
get_c_goodnessFunction · 0.70

Tested by

no test coverage detected