예제 #1
0
 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))
예제 #2
0
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)
예제 #3
0
 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)
예제 #5
0
    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)
예제 #6
0
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)
예제 #7
0
 def evaluate_predict(sentence, target_parse, cyk_module: cyk.CYKParser, scorer: evalscorer.Scorer) -> evalscorer.Result:
     predicted_string = cyk_module.cyk_parse(sentence)
     pred_tree = evalparser.create_from_bracket_string(predicted_string)
     gold_tree = evalparser.create_from_bracket_string(target_parse)
     if "Failure" in predicted_string:
         result = evalscorer.Result()
         result.state = 2
     else:
         result = scorer.score_trees(gold_tree, pred_tree)
     return result, predicted_string
예제 #8
0
def test_table():
    scorer = Scorer()
    scorer.evalb(GOLD_PATH, TEST_PATH, RESULT_PATH)