コード例 #1
0
def main(args):
    for spec in read_specs(args, converters=CONVERTERS):
        scores = []
        sentences, to_parse = tee(
            (to_conllu_native(p),
             to_conllu_native(p, test=True, enhanced=False)
             ) if isinstance(p, core.Passage) else (p, strip_enhanced(p))
            for p in spec.passages)
        t = tqdm(zip((x for x, _ in sentences),
                     split_by_empty_lines(
                         udpipe((x for _, x in to_parse), spec.udpipe,
                                args.verbose))),
                 unit=" sentences")
        for sentence, parsed in t:
            sentence = list(sentence)
            if args.write:
                i = next(find_ids(sentence))
                t.set_postfix(id=i)
                with open_out_file(spec, i) as f:
                    for line in parsed:
                        print(line, file=f)
            if args.evaluate:
                scores.append(
                    evaluate(parsed, sentence, verbose=args.verbose > 1))
        if scores:
            Scores(scores).print()
コード例 #2
0
def main(args):
    for spec in read_specs(args, converters=CONVERTERS):
        scores = []
        sentences1, sentences2 = tee(spec.passages)
        t = tqdm(zip(
            sentences1,
            split_by_empty_lines(udpipe(sentences2, spec.udpipe,
                                        args.verbose))),
                 unit=" sentences")
        for sentence, parsed in t:
            sentence = list(sentence)
            if args.write:
                i = next(find_ids(sentence))
                t.set_postfix(id=i)
                with open(os.path.join(spec.out_dir, i + ".conllu"),
                          "w",
                          encoding="utf-8") as f:
                    for line in parsed:
                        print(line, file=f)
            if args.evaluate:
                scores.append(
                    evaluate(parsed, sentence, verbose=args.verbose > 1))
        if scores:
            Scores(scores).print()
コード例 #3
0
def evaluate_conllu(*args, **kwargs):
    from semstr.evaluation import conllu
    return conllu.evaluate(*args, **kwargs)
コード例 #4
0
ファイル: test_conllu.py プロジェクト: zoharai/semstr
 def test_evaluate(self):
     """Test that comparing an Universal Dependencies graph against itself returns perfect LAS F1"""
     for _, ref, conllu_id in read_test_conllu():
         scores = evaluate(ref, ref)
         self.assertAlmostEqual(scores.average_f1(), 1)
コード例 #5
0
ファイル: test_conllu.py プロジェクト: zoharai/semstr
 def convert_and_evaluate(self, passage, ref):
     converted = to_conllu(passage)
     scores = evaluate(converted, ref)
     self.assertAlmostEqual(scores.average_f1(),
                            1,
                            msg="\n" + "\n".join(converted))
コード例 #6
0
ファイル: test_conllu.py プロジェクト: matanboaz/semstr
def convert_and_evaluate(passage, ref):
    converted = to_conllu(passage)
    assert evaluate(converted, ref).average_f1() == pytest.approx(1, 0.1), format_lines(converted)
コード例 #7
0
ファイル: test_conllu.py プロジェクト: matanboaz/semstr
def test_evaluate():
    """Test that comparing an Universal Dependencies graph against itself returns perfect LAS F1"""
    for _, ref, conllu_id in read_test_conllu():
        assert evaluate(ref, ref).average_f1() == pytest.approx(1, 0.1)