def test_score_trees(self): scorer = Scorer() with open(GOLD_PATH, encoding='utf8') as gold: with open(TEST_PATH, encoding='utf8') as test: results = scorer.score_corpus(gold, test) for ans, value in zip(self._true_results, results): assert_equals(str(ans), str(value))
def evaluate(goldtest): scorer = Scorer() for gold, test in goldtest: goldtree = parser.create_from_bracket_string(gold) testtree = parser.create_from_bracket_string(test) result = scorer.score_trees(gold_tree, test_tree) print(result)
def test_exception(self): scorer = Scorer() ans = Result() ans.state = 2 with open(ERROR_GOLD_PATH, encoding='utf8') as gold: with open(ERROR_TEST_PATH, encoding='utf8') as test: results = scorer.score_corpus(gold, test) for i, value in enumerate(results): ans.ID = i assert_equals(str(ans), str(value))
def compute_precision(prediction_train, grammars_train) : scorer = Scorer() tuple_to = [] for i in range(len(prediction_train)) : if prediction_train[i][1] == 1 : tuple_to.append((prediction_train[i][0], grammars_train[i])) precision = [scorer.score_trees(parser.create_from_bracket_string(pred), parser.create_from_bracket_string(real)).prec for\ (pred, real) in tuple_to] return np.sum(precision)/len(grammars_train)
def test_summary(self): scorer = Scorer() with open(GOLD_PATH, encoding='utf8') as gold: with open(TEST_PATH, encoding='utf8') as test: results = scorer.score_corpus(gold, test) value = summary.summary(results) value = summary._summary2string(value) ans = [] with open(SUMMARY_PATH, encoding='utf8') as f: ans = [float(line.strip().split('=')[-1]) for line in f] print(ans) ans = summary.Summary(*ans) ans = summary._summary2string(ans) assert_equals(ans, value)
def main(): parser = argparse.ArgumentParser() parser.add_argument('gold_path', help='The path of gold tree bank.', type=str) parser.add_argument('test_path', help='The path of test tree bank.', type=str) parser.add_argument('result_path', help='The path of result report.', type=str) args = parser.parse_args() scorer = Scorer() scorer.evalb(args.gold_path, args.test_path, args.result_path)
def test_table(): scorer = Scorer() scorer.evalb(GOLD_PATH, TEST_PATH, RESULT_PATH)