MCPcopy Create free account
hub / github.com/PaddlePaddle/Research / search_values

Function search_values

NLP/Text2SQL-BASELINE/script/schema_linking.py:210–256  ·  view source on GitHub ↗

search cells of col_id Args: query (TYPE): NULL db (TYPE): NULL extra_values (TYPE): values from sql if is_train Returns: TODO Raises: NULL

(query, db, extra_values)

Source from the content-addressed store, hash-verified

208
209
210def search_values(query, db, extra_values):
211 """search cells of col_id
212
213 Args:
214 query (TYPE): NULL
215 db (TYPE): NULL
216 extra_values (TYPE): values from sql if is_train
217
218 Returns: TODO
219
220 Raises: NULL
221 """
222 lst_match_values = []
223 for column, cell_index in zip(db.columns, db.column_cells_index):
224 if column.id == 0:
225 lst_match_values.append([])
226 continue
227 col_id = column.id
228
229 candi_cnt = defaultdict(float)
230 query_chars = get_char_list(query.lower())
231 appear_set = set()
232 for pos in range(len(query_chars)):
233 unigram = query_chars[pos]
234 if len(unigram) > 2 and unigram not in appear_set and unigram in cell_index:
235 for cell, base in cell_index[unigram]:
236 candi_cnt[cell] += 1.0 / base
237 if pos == len(query_chars) - 1:
238 break
239
240 bigram = query_chars[pos: pos + 2]
241 if bigram not in cell_index:
242 continue
243 if bigram in appear_set:
244 continue
245 appear_set.add(bigram)
246 for cell, base in cell_index[bigram]:
247 candi_cnt[cell] += 1.0 / base
248
249 if extra_values is not None and column.id in extra_values:
250 gold_values = extra_values[column.id]
251 for gval in gold_values:
252 candi_cnt[str(gval)] += 2.0
253
254 lst_match_values.append(list(sorted(candi_cnt.items(), key=lambda x: x[1], reverse=True))[:10])
255
256 return lst_match_values
257
258
259if __name__ == "__main__":

Callers 1

schema_linking.pyFile · 0.85

Calls 4

get_char_listFunction · 0.85
itemsMethod · 0.80
appendMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected