MCPcopy Create free account
hub / github.com/FlyingFeather/DEA-SQL / Evaluator

Class Evaluator

single_eval.py:357–433  ·  view source on GitHub ↗

A simple evaluator

Source from the content-addressed store, hash-verified

355
356
357class Evaluator:
358 """A simple evaluator"""
359
360 def __init__(self):
361 self.partial_scores = None
362
363 def eval_hardness(self, sql):
364 count_comp1_ = count_component1(sql)
365 count_comp2_ = count_component2(sql)
366 count_others_ = count_others(sql)
367
368 if count_comp1_ <= 1 and count_others_ == 0 and count_comp2_ == 0:
369 return "easy"
370 elif (count_others_ <= 2 and count_comp1_ <= 1 and count_comp2_ == 0) or \
371 (count_comp1_ <= 2 and count_others_ < 2 and count_comp2_ == 0):
372 return "medium"
373 elif (count_others_ > 2 and count_comp1_ <= 2 and count_comp2_ == 0) or \
374 (2 < count_comp1_ <= 3 and count_others_ <= 2 and count_comp2_ == 0) or \
375 (count_comp1_ <= 1 and count_others_ == 0 and count_comp2_ <= 1):
376 return "hard"
377 else:
378 return "extra"
379
380 def eval_exact_match(self, pred, label):
381 partial_scores = self.eval_partial_match(pred, label)
382 self.partial_scores = partial_scores
383
384 for key, score in partial_scores.items():
385 if score['f1'] != 1:
386 return 0
387
388 if len(label['from']['table_units']) > 0:
389 label_tables = sorted(label['from']['table_units'])
390 pred_tables = sorted(pred['from']['table_units'])
391 return label_tables == pred_tables
392 return 1
393
394 def eval_partial_match(self, pred, label):
395 res = {}
396
397 label_total, pred_total, cnt, cnt_wo_agg = eval_sel(pred, label)
398 acc, rec, f1 = get_scores(cnt, pred_total, label_total)
399 res['select'] = {'acc': acc, 'rec': rec, 'f1': f1, 'label_total': label_total, 'pred_total': pred_total}
400 acc, rec, f1 = get_scores(cnt_wo_agg, pred_total, label_total)
401 res['select(no AGG)'] = {'acc': acc, 'rec': rec, 'f1': f1, 'label_total': label_total, 'pred_total': pred_total}
402
403 label_total, pred_total, cnt, cnt_wo_agg = eval_where(pred, label)
404 acc, rec, f1 = get_scores(cnt, pred_total, label_total)
405 res['where'] = {'acc': acc, 'rec': rec, 'f1': f1, 'label_total': label_total, 'pred_total': pred_total}
406 acc, rec, f1 = get_scores(cnt_wo_agg, pred_total, label_total)
407 res['where(no OP)'] = {'acc': acc, 'rec': rec, 'f1': f1, 'label_total': label_total, 'pred_total': pred_total}
408
409 label_total, pred_total, cnt = eval_group(pred, label)
410 acc, rec, f1 = get_scores(cnt, pred_total, label_total)
411 res['group(no Having)'] = {'acc': acc, 'rec': rec, 'f1': f1, 'label_total': label_total, 'pred_total': pred_total}
412
413 label_total, pred_total, cnt = eval_having(pred, label)
414 acc, rec, f1 = get_scores(cnt, pred_total, label_total)

Callers 2

eval_nestedFunction · 0.70
evaluateFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected