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()
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()
def evaluate_conllu(*args, **kwargs): from semstr.evaluation import conllu return conllu.evaluate(*args, **kwargs)
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)
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))
def convert_and_evaluate(passage, ref): converted = to_conllu(passage) assert evaluate(converted, ref).average_f1() == pytest.approx(1, 0.1), format_lines(converted)
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)