Datasets:
Tasks:
Text Classification
Formats:
parquet
Languages:
Ancient Greek (to 1453)
Size:
100K - 1M
License:
Validate all CoNLL-U with official loader
Browse files- README.md +7 -1
- data/prose_1/test-00000-of-00001.parquet +2 -2
- data/prose_1/train-00000-of-00001.parquet +2 -2
- data/prose_1/validation-00000-of-00001.parquet +2 -2
- data/prose_10/test-00000-of-00001.parquet +2 -2
- data/prose_10/train-00000-of-00001.parquet +2 -2
- data/prose_10/validation-00000-of-00001.parquet +2 -2
- data/prose_100/test-00000-of-00001.parquet +2 -2
- data/prose_100/train-00000-of-00001.parquet +2 -2
- data/prose_100/validation-00000-of-00001.parquet +2 -2
- data/verse_metre_1/test-00000-of-00001.parquet +2 -2
- data/verse_metre_1/train-00000-of-00001.parquet +2 -2
- data/verse_metre_1/validation-00000-of-00001.parquet +2 -2
- data/verse_metre_10/test-00000-of-00001.parquet +2 -2
- data/verse_metre_10/train-00000-of-00001.parquet +2 -2
- data/verse_metre_10/validation-00000-of-00001.parquet +2 -2
- data/verse_metre_100/test-00000-of-00001.parquet +2 -2
- data/verse_metre_100/train-00000-of-00001.parquet +2 -2
- data/verse_metre_100/validation-00000-of-00001.parquet +2 -2
- data/verse_sentence_1/test-00000-of-00001.parquet +2 -2
- data/verse_sentence_1/train-00000-of-00001.parquet +2 -2
- data/verse_sentence_1/validation-00000-of-00001.parquet +2 -2
- data/verse_sentence_10/test-00000-of-00001.parquet +2 -2
- data/verse_sentence_10/train-00000-of-00001.parquet +2 -2
- data/verse_sentence_10/validation-00000-of-00001.parquet +2 -2
- data/verse_sentence_100/test-00000-of-00001.parquet +2 -2
- data/verse_sentence_100/train-00000-of-00001.parquet +2 -2
- data/verse_sentence_100/validation-00000-of-00001.parquet +2 -2
- metadata/build_report.json +2 -0
- scripts/build_dataset.py +20 -3
- scripts/dataset_variants.py +1 -1
- scripts/validate_dataset.py +36 -1
- scripts/vendor/conll18_ud_eval.py +203 -0
- tests/test_conllu_well_formed.py +40 -0
README.md
CHANGED
|
@@ -90,7 +90,7 @@ configs:
|
|
| 90 |
# Sphragis
|
| 91 |
|
| 92 |
Sphragis is a benchmark for Ancient Greek authorship
|
| 93 |
-
attribution. Beta 0.4.
|
| 94 |
and the metrically annotated [Hypotactic](https://hypotactic.com/)(Chamberlain 2023)
|
| 95 |
corpus. It supplies fixed train, validation and test splits.
|
| 96 |
|
|
@@ -222,6 +222,12 @@ incompatible source-specific tags are reconstructed from UPOS and FEATS, with
|
|
| 222 |
unavailable distinctions represented by `-`. UPOS and FEATS remain the
|
| 223 |
canonical UD fields.
|
| 224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
## Deduplication
|
| 226 |
|
| 227 |
Raw prose input comprised 72,336 sentences. Authorship curation retained
|
|
|
|
| 90 |
# Sphragis
|
| 91 |
|
| 92 |
Sphragis is a benchmark for Ancient Greek authorship
|
| 93 |
+
attribution. Beta 0.4.1 combines licensed, human-annotated dependency treebanks[1]
|
| 94 |
and the metrically annotated [Hypotactic](https://hypotactic.com/)(Chamberlain 2023)
|
| 95 |
corpus. It supplies fixed train, validation and test splits.
|
| 96 |
|
|
|
|
| 222 |
unavailable distinctions represented by `-`. UPOS and FEATS remain the
|
| 223 |
canonical UD fields.
|
| 224 |
|
| 225 |
+
Every distinct published `conllu` document is loaded during testing with the
|
| 226 |
+
[official CoNLL 2018 shared-task `load_conllu` parser](https://github.com/CoNLL-UD-2018/UDPipe-Future/blob/master/conll18_ud_eval.py).
|
| 227 |
+
This checks sentence
|
| 228 |
+
termination, ten-column structure, token IDs, heads, roots and dependency
|
| 229 |
+
cycles across all nine configurations.
|
| 230 |
+
|
| 231 |
## Deduplication
|
| 232 |
|
| 233 |
Raw prose input comprised 72,336 sentences. Authorship curation retained
|
data/prose_1/test-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2f3554227d439dcecff393a3cb48e221b6493bba0b2736cdb283403721aee367
|
| 3 |
+
size 1980714
|
data/prose_1/train-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:698fff1cff621b2c0de6277bc0ac31db9b8997f00e41ab76531e8691fba551c5
|
| 3 |
+
size 15629296
|
data/prose_1/validation-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0874552ac52826109722381fa457d9d5a999f9801774c6f74993f8d81d16ff18
|
| 3 |
+
size 1988996
|
data/prose_10/test-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:88cb1a7e347f6cb1136675a5a6279bad3d7583d8dd082ccfcab9cdaf71e0f537
|
| 3 |
+
size 1624165
|
data/prose_10/train-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:26b317b51ff8c1f82cf4f1c40be179a830e2be1801573ecdfc6d176e88088eb1
|
| 3 |
+
size 16747242
|
data/prose_10/validation-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b51210cad429999ffef983930153825fc3b5f68ea9ea6be4334b5e654c783896
|
| 3 |
+
size 1637038
|
data/prose_100/test-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:32c1eac79ca6762733b1da74a349a6bd4970859542558fb973ea2c9c62ae44c2
|
| 3 |
+
size 1109778
|
data/prose_100/train-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1f8ea005c0094d41ba88ffd835481ab4a1e1ae205b0161d44605245c23fb4329
|
| 3 |
+
size 12950032
|
data/prose_100/validation-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:733c0d19d165141d5a007d5d08c81ad8be036d2d5d5cf6fc983da2f18d169e9e
|
| 3 |
+
size 1110554
|
data/verse_metre_1/test-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b94a6506fe839d15401e96622e7750b8ccdf6078d818a3aab6f08f4dbe311894
|
| 3 |
+
size 1392577
|
data/verse_metre_1/train-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:15d808c053df82e8a1a0e75614a4e38a6b338eeecabd5afd55b22ccc7ee39651
|
| 3 |
+
size 6978445
|
data/verse_metre_1/validation-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f5022ffcac0817824f3462af8cac71a5dd63da8650775e2ad546e92f8933d5fc
|
| 3 |
+
size 1404481
|
data/verse_metre_10/test-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:89e3bd097f6de102f2c0c804b0024d84b5f5aa604d7eae17ddae98b019d16eb2
|
| 3 |
+
size 1243932
|
data/verse_metre_10/train-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6ade24c09c35212b177a580ced44b83ef5bec5d2842f0ca5c0d89a638380e3e5
|
| 3 |
+
size 7736840
|
data/verse_metre_10/validation-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1a9a53657bac81f47a1e2c12590e469611c94235db2eaa67fc1f82b3fc973b0c
|
| 3 |
+
size 1244984
|
data/verse_metre_100/test-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7d13e026a6880144ac54ff6667d6770af08057ae22eaad23eadaa55ad2991dfc
|
| 3 |
+
size 1105208
|
data/verse_metre_100/train-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8e1f8dacfca0dd540f898f06f1aef6b893937baf75562257cd7a7e7df35047d1
|
| 3 |
+
size 7396134
|
data/verse_metre_100/validation-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:89f568e83a3ccc0fe8e5aece955ea0ea311a51667c4d4482f0c1c47bedd4f2df
|
| 3 |
+
size 1111127
|
data/verse_sentence_1/test-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6d85a321fd454bf40f80042b6ed740f2d563e3f8f491097f31f16a1f4bea247c
|
| 3 |
+
size 983173
|
data/verse_sentence_1/train-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:14fb7c585b694c767a45e137a86dff43a2f10f25734d3259924ffd74972de868
|
| 3 |
+
size 7021255
|
data/verse_sentence_1/validation-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:eba2a593c9be9cfa16275f78ef6681402488e0b1613d49a31a7f6f0204f014cc
|
| 3 |
+
size 992115
|
data/verse_sentence_10/test-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ab1c60bb7134f82080e454944ab70ddb134d6b56b4c2ab0aa9f0d71eed5b9702
|
| 3 |
+
size 888272
|
data/verse_sentence_10/train-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:892c417d5138b16fad888cca918affd2f681546139d825bfb1d447777368e45b
|
| 3 |
+
size 7418314
|
data/verse_sentence_10/validation-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:269355558aeababb8b92c50e4f7d3502321727d88d4cf0d939f192fa78d5b709
|
| 3 |
+
size 881989
|
data/verse_sentence_100/test-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4acc7d892efefe91e247c9d777aecf6786831bfc3a45e8ee367875c6daff805e
|
| 3 |
+
size 785299
|
data/verse_sentence_100/train-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:618069a03f4d1ab7ea306ff0edb0c593b47ff733da786ddf81b4e127c5dba8e8
|
| 3 |
+
size 7084097
|
data/verse_sentence_100/validation-00000-of-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4ee94cba3f6996fa6f407d787ebe86f02d1d5259a0bd62e0af3a07e9634d926d
|
| 3 |
+
size 779883
|
metadata/build_report.json
CHANGED
|
@@ -940,7 +940,9 @@
|
|
| 940 |
"validation": {
|
| 941 |
"checks": {
|
| 942 |
"fixed_exact_evaluation_chunks": true,
|
|
|
|
| 943 |
"prose_exact_text_unique": true,
|
|
|
|
| 944 |
"unique_ids": true,
|
| 945 |
"verse_component_exact_coverage": true
|
| 946 |
},
|
|
|
|
| 940 |
"validation": {
|
| 941 |
"checks": {
|
| 942 |
"fixed_exact_evaluation_chunks": true,
|
| 943 |
+
"official_conll18_loader": true,
|
| 944 |
"prose_exact_text_unique": true,
|
| 945 |
+
"unique_conllu_documents_checked": 62713,
|
| 946 |
"unique_ids": true,
|
| 947 |
"verse_component_exact_coverage": true
|
| 948 |
},
|
scripts/build_dataset.py
CHANGED
|
@@ -11,6 +11,7 @@ from __future__ import annotations
|
|
| 11 |
import argparse
|
| 12 |
import hashlib
|
| 13 |
import html
|
|
|
|
| 14 |
import json
|
| 15 |
import random
|
| 16 |
import re
|
|
@@ -29,8 +30,10 @@ import pyarrow.parquet as pq
|
|
| 29 |
|
| 30 |
try:
|
| 31 |
from scripts.dataset_variants import make_dataset_variants, variant_schema
|
|
|
|
| 32 |
except ModuleNotFoundError: # Direct execution from the scripts directory.
|
| 33 |
from dataset_variants import make_dataset_variants, variant_schema
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
RANDOM_SEED = 776
|
|
@@ -338,7 +341,7 @@ def canonicalize_conllu_xpos(conllu: str) -> str:
|
|
| 338 |
columns[4] = canonical_xpos(columns[3], columns[4], columns[5])
|
| 339 |
line = "\t".join(columns)
|
| 340 |
lines.append(line)
|
| 341 |
-
return "\n".join(lines) + "\n"
|
| 342 |
|
| 343 |
|
| 344 |
def canonical_native_deprel(relation: str, child_upos: str, head: int) -> str:
|
|
@@ -679,7 +682,7 @@ def xml_sentence_to_conllu(sentence: ET.Element, metadata: dict[str, str]) -> tu
|
|
| 679 |
}),
|
| 680 |
]
|
| 681 |
lines.append("\t".join(row))
|
| 682 |
-
return text, "\n".join(lines) + "\n", cites
|
| 683 |
|
| 684 |
|
| 685 |
def parse_agdt(root: Path, revisions: dict[str, str]) -> tuple[list[Sentence], list[Sentence]]:
|
|
@@ -1212,7 +1215,7 @@ def align_verse_blocks(
|
|
| 1212 |
"id": line_ids[line_index], "parent_sentence_ids": parent_ids,
|
| 1213 |
"author": parents[0].author, "work": parents[0].work, "work_id": parents[0].work_id,
|
| 1214 |
"genre": "verse_metre", "text": line["text"],
|
| 1215 |
-
"conllu": "\n\n".join(parent.conllu.strip() for parent in parents) + "\n",
|
| 1216 |
"cts_urn": parents[0].cts_urn,
|
| 1217 |
"passage": " | ".join(dict.fromkeys(parent.passage for parent in parents if parent.passage)),
|
| 1218 |
"alignment_component_id": component_id,
|
|
@@ -1387,6 +1390,7 @@ def write_parquet(
|
|
| 1387 |
|
| 1388 |
def validate(rows_by_config: dict[str, list[dict]]) -> dict:
|
| 1389 |
report = {}
|
|
|
|
| 1390 |
for config, rows in rows_by_config.items():
|
| 1391 |
ids = [row["id"] for row in rows]
|
| 1392 |
dedup = [row["dedup_key"] for row in rows]
|
|
@@ -1406,6 +1410,17 @@ def validate(rows_by_config: dict[str, list[dict]]) -> dict:
|
|
| 1406 |
assert all(len(row["constituent_ids"]) == row["chunk_size"] for row in rows)
|
| 1407 |
if base_config == "prose":
|
| 1408 |
assert len(dedup) == len(set(dedup)), "prose exact-text deduplication failed"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1409 |
report[config] = {
|
| 1410 |
"rows": len(rows),
|
| 1411 |
"authors": len({row["author"] for row in rows}),
|
|
@@ -1429,6 +1444,8 @@ def validate(rows_by_config: dict[str, list[dict]]) -> dict:
|
|
| 1429 |
"unique_ids": True, "prose_exact_text_unique": True,
|
| 1430 |
"verse_component_exact_coverage": True,
|
| 1431 |
"fixed_exact_evaluation_chunks": True,
|
|
|
|
|
|
|
| 1432 |
}
|
| 1433 |
return report
|
| 1434 |
|
|
|
|
| 11 |
import argparse
|
| 12 |
import hashlib
|
| 13 |
import html
|
| 14 |
+
import io
|
| 15 |
import json
|
| 16 |
import random
|
| 17 |
import re
|
|
|
|
| 30 |
|
| 31 |
try:
|
| 32 |
from scripts.dataset_variants import make_dataset_variants, variant_schema
|
| 33 |
+
from scripts.vendor.conll18_ud_eval import UDError, load_conllu
|
| 34 |
except ModuleNotFoundError: # Direct execution from the scripts directory.
|
| 35 |
from dataset_variants import make_dataset_variants, variant_schema
|
| 36 |
+
from vendor.conll18_ud_eval import UDError, load_conllu
|
| 37 |
|
| 38 |
|
| 39 |
RANDOM_SEED = 776
|
|
|
|
| 341 |
columns[4] = canonical_xpos(columns[3], columns[4], columns[5])
|
| 342 |
line = "\t".join(columns)
|
| 343 |
lines.append(line)
|
| 344 |
+
return "\n".join(lines).rstrip("\n") + "\n\n"
|
| 345 |
|
| 346 |
|
| 347 |
def canonical_native_deprel(relation: str, child_upos: str, head: int) -> str:
|
|
|
|
| 682 |
}),
|
| 683 |
]
|
| 684 |
lines.append("\t".join(row))
|
| 685 |
+
return text, "\n".join(lines) + "\n\n", cites
|
| 686 |
|
| 687 |
|
| 688 |
def parse_agdt(root: Path, revisions: dict[str, str]) -> tuple[list[Sentence], list[Sentence]]:
|
|
|
|
| 1215 |
"id": line_ids[line_index], "parent_sentence_ids": parent_ids,
|
| 1216 |
"author": parents[0].author, "work": parents[0].work, "work_id": parents[0].work_id,
|
| 1217 |
"genre": "verse_metre", "text": line["text"],
|
| 1218 |
+
"conllu": "\n\n".join(parent.conllu.strip() for parent in parents) + "\n\n",
|
| 1219 |
"cts_urn": parents[0].cts_urn,
|
| 1220 |
"passage": " | ".join(dict.fromkeys(parent.passage for parent in parents if parent.passage)),
|
| 1221 |
"alignment_component_id": component_id,
|
|
|
|
| 1390 |
|
| 1391 |
def validate(rows_by_config: dict[str, list[dict]]) -> dict:
|
| 1392 |
report = {}
|
| 1393 |
+
checked_conllu = set()
|
| 1394 |
for config, rows in rows_by_config.items():
|
| 1395 |
ids = [row["id"] for row in rows]
|
| 1396 |
dedup = [row["dedup_key"] for row in rows]
|
|
|
|
| 1410 |
assert all(len(row["constituent_ids"]) == row["chunk_size"] for row in rows)
|
| 1411 |
if base_config == "prose":
|
| 1412 |
assert len(dedup) == len(set(dedup)), "prose exact-text deduplication failed"
|
| 1413 |
+
for row in rows:
|
| 1414 |
+
digest = hashlib.sha256(row["conllu"].encode("utf-8")).digest()
|
| 1415 |
+
if digest in checked_conllu:
|
| 1416 |
+
continue
|
| 1417 |
+
try:
|
| 1418 |
+
load_conllu(io.StringIO(row["conllu"]))
|
| 1419 |
+
except UDError as error:
|
| 1420 |
+
raise AssertionError(
|
| 1421 |
+
f"Malformed CoNLL-U in {config}, row {row['id']}: {error}"
|
| 1422 |
+
) from error
|
| 1423 |
+
checked_conllu.add(digest)
|
| 1424 |
report[config] = {
|
| 1425 |
"rows": len(rows),
|
| 1426 |
"authors": len({row["author"] for row in rows}),
|
|
|
|
| 1444 |
"unique_ids": True, "prose_exact_text_unique": True,
|
| 1445 |
"verse_component_exact_coverage": True,
|
| 1446 |
"fixed_exact_evaluation_chunks": True,
|
| 1447 |
+
"official_conll18_loader": True,
|
| 1448 |
+
"unique_conllu_documents_checked": len(checked_conllu),
|
| 1449 |
}
|
| 1450 |
return report
|
| 1451 |
|
scripts/dataset_variants.py
CHANGED
|
@@ -154,7 +154,7 @@ def _aggregate_chunk(base_config: str, rows: list[dict], target: int, split: str
|
|
| 154 |
"text": ("\n" if base_config == "verse_metre" else "\n\n").join(
|
| 155 |
row["text"].strip() for row in rows
|
| 156 |
),
|
| 157 |
-
"conllu": "\n\n".join(row["conllu"].strip() for row in rows) + "\n",
|
| 158 |
"cts_urn": rows[0]["cts_urn"] if len({row["cts_urn"] for row in rows}) == 1 else None,
|
| 159 |
"passage": (
|
| 160 |
rows[0]["passage"]
|
|
|
|
| 154 |
"text": ("\n" if base_config == "verse_metre" else "\n\n").join(
|
| 155 |
row["text"].strip() for row in rows
|
| 156 |
),
|
| 157 |
+
"conllu": "\n\n".join(row["conllu"].strip() for row in rows) + "\n\n",
|
| 158 |
"cts_urn": rows[0]["cts_urn"] if len({row["cts_urn"] for row in rows}) == 1 else None,
|
| 159 |
"passage": (
|
| 160 |
rows[0]["passage"]
|
scripts/validate_dataset.py
CHANGED
|
@@ -4,6 +4,8 @@
|
|
| 4 |
from __future__ import annotations
|
| 5 |
|
| 6 |
import argparse
|
|
|
|
|
|
|
| 7 |
import json
|
| 8 |
import re
|
| 9 |
import unicodedata
|
|
@@ -12,6 +14,11 @@ from pathlib import Path
|
|
| 12 |
|
| 13 |
import pyarrow.parquet as pq
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
try:
|
| 16 |
from scripts.dataset_variants import (
|
| 17 |
actual_order_key,
|
|
@@ -381,12 +388,38 @@ def validate_combined_conllu(root: Path, parent_conllu: dict[str, str]) -> int:
|
|
| 381 |
parquet = pq.ParquetFile(path)
|
| 382 |
for batch in parquet.iter_batches(columns=["parent_sentence_ids", "conllu"], batch_size=256, use_threads=False):
|
| 383 |
for row in batch.to_pylist():
|
| 384 |
-
expected = "\n\n".join(
|
|
|
|
|
|
|
|
|
|
| 385 |
assert row["conllu"] == expected
|
| 386 |
checked += 1
|
| 387 |
return checked
|
| 388 |
|
| 389 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 390 |
def main() -> None:
|
| 391 |
parser = argparse.ArgumentParser()
|
| 392 |
parser.add_argument("--data", type=Path, default=Path("data"))
|
|
@@ -410,10 +443,12 @@ def main() -> None:
|
|
| 410 |
checked_lines = validate_provenance_and_verse(args.data)
|
| 411 |
checked, parent_conllu = validate_conllu(args.data)
|
| 412 |
checked_combined = validate_combined_conllu(args.data, parent_conllu)
|
|
|
|
| 413 |
print("validated aligned metrical lines", checked_lines)
|
| 414 |
print("validated cross-sentence metrical lines", crossing_lines)
|
| 415 |
print("validated CoNLL-U sentences", checked)
|
| 416 |
print("validated combined metrical CoNLL-U documents", checked_combined)
|
|
|
|
| 417 |
print("all checks passed")
|
| 418 |
|
| 419 |
|
|
|
|
| 4 |
from __future__ import annotations
|
| 5 |
|
| 6 |
import argparse
|
| 7 |
+
import hashlib
|
| 8 |
+
import io
|
| 9 |
import json
|
| 10 |
import re
|
| 11 |
import unicodedata
|
|
|
|
| 14 |
|
| 15 |
import pyarrow.parquet as pq
|
| 16 |
|
| 17 |
+
try:
|
| 18 |
+
from scripts.vendor.conll18_ud_eval import UDError, load_conllu
|
| 19 |
+
except ModuleNotFoundError: # Direct execution from the scripts directory.
|
| 20 |
+
from vendor.conll18_ud_eval import UDError, load_conllu
|
| 21 |
+
|
| 22 |
try:
|
| 23 |
from scripts.dataset_variants import (
|
| 24 |
actual_order_key,
|
|
|
|
| 388 |
parquet = pq.ParquetFile(path)
|
| 389 |
for batch in parquet.iter_batches(columns=["parent_sentence_ids", "conllu"], batch_size=256, use_threads=False):
|
| 390 |
for row in batch.to_pylist():
|
| 391 |
+
expected = "\n\n".join(
|
| 392 |
+
parent_conllu[parent_id].strip()
|
| 393 |
+
for parent_id in row["parent_sentence_ids"]
|
| 394 |
+
) + "\n\n"
|
| 395 |
assert row["conllu"] == expected
|
| 396 |
checked += 1
|
| 397 |
return checked
|
| 398 |
|
| 399 |
|
| 400 |
+
def validate_conllu_with_official_loader(root: Path) -> int:
|
| 401 |
+
checked = set()
|
| 402 |
+
for config in CONFIGS:
|
| 403 |
+
for split in SPLITS:
|
| 404 |
+
path = root / config / f"{split}-00000-of-00001.parquet"
|
| 405 |
+
parquet = pq.ParquetFile(path)
|
| 406 |
+
for batch in parquet.iter_batches(
|
| 407 |
+
columns=["id", "conllu"], batch_size=256, use_threads=False,
|
| 408 |
+
):
|
| 409 |
+
for row in batch.to_pylist():
|
| 410 |
+
digest = hashlib.sha256(row["conllu"].encode("utf-8")).digest()
|
| 411 |
+
if digest in checked:
|
| 412 |
+
continue
|
| 413 |
+
try:
|
| 414 |
+
load_conllu(io.StringIO(row["conllu"]))
|
| 415 |
+
except UDError as error:
|
| 416 |
+
raise AssertionError(
|
| 417 |
+
f"Malformed CoNLL-U in {config}/{split}, row {row['id']}: {error}"
|
| 418 |
+
) from error
|
| 419 |
+
checked.add(digest)
|
| 420 |
+
return len(checked)
|
| 421 |
+
|
| 422 |
+
|
| 423 |
def main() -> None:
|
| 424 |
parser = argparse.ArgumentParser()
|
| 425 |
parser.add_argument("--data", type=Path, default=Path("data"))
|
|
|
|
| 443 |
checked_lines = validate_provenance_and_verse(args.data)
|
| 444 |
checked, parent_conllu = validate_conllu(args.data)
|
| 445 |
checked_combined = validate_combined_conllu(args.data, parent_conllu)
|
| 446 |
+
checked_official = validate_conllu_with_official_loader(args.data)
|
| 447 |
print("validated aligned metrical lines", checked_lines)
|
| 448 |
print("validated cross-sentence metrical lines", crossing_lines)
|
| 449 |
print("validated CoNLL-U sentences", checked)
|
| 450 |
print("validated combined metrical CoNLL-U documents", checked_combined)
|
| 451 |
+
print("validated unique CoNLL-U documents with official CoNLL 2018 loader", checked_official)
|
| 452 |
print("all checks passed")
|
| 453 |
|
| 454 |
|
scripts/vendor/conll18_ud_eval.py
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
|
| 3 |
+
# Compatible with Python 2.7 and 3.2+, can be used either as a module
|
| 4 |
+
# or a standalone executable.
|
| 5 |
+
#
|
| 6 |
+
# Copyright 2017, 2018 Institute of Formal and Applied Linguistics (UFAL),
|
| 7 |
+
# Faculty of Mathematics and Physics, Charles University, Czech Republic.
|
| 8 |
+
#
|
| 9 |
+
# This Source Code Form is subject to the terms of the Mozilla Public
|
| 10 |
+
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
| 11 |
+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 12 |
+
#
|
| 13 |
+
# Authors: Milan Straka, Martin Popel <surname@ufal.mff.cuni.cz>
|
| 14 |
+
#
|
| 15 |
+
# This file extracts the load_conllu portion of conll18_ud_eval.py from
|
| 16 |
+
# https://github.com/CoNLL-UD-2018/UDPipe-Future (version 1.1), with formatting
|
| 17 |
+
# changes only and without the unrelated scoring and command-line code.
|
| 18 |
+
|
| 19 |
+
from __future__ import division
|
| 20 |
+
from __future__ import print_function
|
| 21 |
+
|
| 22 |
+
import sys
|
| 23 |
+
import unicodedata
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# CoNLL-U column names
|
| 27 |
+
ID, FORM, LEMMA, UPOS, XPOS, FEATS, HEAD, DEPREL, DEPS, MISC = range(10)
|
| 28 |
+
|
| 29 |
+
# Content and functional relations
|
| 30 |
+
CONTENT_DEPRELS = {
|
| 31 |
+
"nsubj", "obj", "iobj", "csubj", "ccomp", "xcomp", "obl", "vocative",
|
| 32 |
+
"expl", "dislocated", "advcl", "advmod", "discourse", "nmod", "appos",
|
| 33 |
+
"nummod", "acl", "amod", "conj", "fixed", "flat", "compound", "list",
|
| 34 |
+
"parataxis", "orphan", "goeswith", "reparandum", "root", "dep"
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
FUNCTIONAL_DEPRELS = {
|
| 38 |
+
"aux", "cop", "mark", "det", "clf", "case", "cc"
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
UNIVERSAL_FEATURES = {
|
| 42 |
+
"PronType", "NumType", "Poss", "Reflex", "Foreign", "Abbr", "Gender",
|
| 43 |
+
"Animacy", "Number", "Case", "Definite", "Degree", "VerbForm", "Mood",
|
| 44 |
+
"Tense", "Aspect", "Voice", "Evident", "Polarity", "Person", "Polite"
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
# UD Error is used when raising exceptions in this module
|
| 49 |
+
class UDError(Exception):
|
| 50 |
+
pass
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
# Load given CoNLL-U file into internal representation
|
| 54 |
+
def load_conllu(file):
|
| 55 |
+
# Internal representation classes
|
| 56 |
+
class UDRepresentation:
|
| 57 |
+
def __init__(self):
|
| 58 |
+
self.characters = []
|
| 59 |
+
self.tokens = []
|
| 60 |
+
self.words = []
|
| 61 |
+
self.sentences = []
|
| 62 |
+
|
| 63 |
+
class UDSpan:
|
| 64 |
+
def __init__(self, start, end):
|
| 65 |
+
self.start = start
|
| 66 |
+
self.end = end
|
| 67 |
+
|
| 68 |
+
class UDWord:
|
| 69 |
+
def __init__(self, span, columns, is_multiword):
|
| 70 |
+
self.span = span
|
| 71 |
+
self.columns = columns
|
| 72 |
+
self.is_multiword = is_multiword
|
| 73 |
+
self.parent = None
|
| 74 |
+
self.functional_children = []
|
| 75 |
+
self.columns[FEATS] = "|".join(sorted(
|
| 76 |
+
feat for feat in columns[FEATS].split("|")
|
| 77 |
+
if feat.split("=", 1)[0] in UNIVERSAL_FEATURES
|
| 78 |
+
))
|
| 79 |
+
self.columns[DEPREL] = columns[DEPREL].split(":")[0]
|
| 80 |
+
self.is_content_deprel = self.columns[DEPREL] in CONTENT_DEPRELS
|
| 81 |
+
self.is_functional_deprel = self.columns[DEPREL] in FUNCTIONAL_DEPRELS
|
| 82 |
+
|
| 83 |
+
ud = UDRepresentation()
|
| 84 |
+
|
| 85 |
+
# Load the CoNLL-U file
|
| 86 |
+
index, sentence_start = 0, None
|
| 87 |
+
while True:
|
| 88 |
+
line = file.readline()
|
| 89 |
+
if not line:
|
| 90 |
+
break
|
| 91 |
+
line = line.rstrip("\r\n")
|
| 92 |
+
|
| 93 |
+
# Handle sentence start boundaries
|
| 94 |
+
if sentence_start is None:
|
| 95 |
+
# Skip comments
|
| 96 |
+
if line.startswith("#"):
|
| 97 |
+
continue
|
| 98 |
+
# Start a new sentence
|
| 99 |
+
ud.sentences.append(UDSpan(index, 0))
|
| 100 |
+
sentence_start = len(ud.words)
|
| 101 |
+
if not line:
|
| 102 |
+
# Add parent and children UDWord links and check there are no cycles
|
| 103 |
+
def process_word(word):
|
| 104 |
+
if word.parent == "remapping":
|
| 105 |
+
raise UDError("There is a cycle in a sentence")
|
| 106 |
+
if word.parent is None:
|
| 107 |
+
head = int(word.columns[HEAD])
|
| 108 |
+
if head < 0 or head > len(ud.words) - sentence_start:
|
| 109 |
+
raise UDError("HEAD '{}' points outside of the sentence".format(word.columns[HEAD]))
|
| 110 |
+
if head:
|
| 111 |
+
parent = ud.words[sentence_start + head - 1]
|
| 112 |
+
word.parent = "remapping"
|
| 113 |
+
process_word(parent)
|
| 114 |
+
word.parent = parent
|
| 115 |
+
|
| 116 |
+
for word in ud.words[sentence_start:]:
|
| 117 |
+
process_word(word)
|
| 118 |
+
# func_children cannot be assigned within process_word because it is
|
| 119 |
+
# called recursively and may result in adding one child twice.
|
| 120 |
+
for word in ud.words[sentence_start:]:
|
| 121 |
+
if word.parent and word.is_functional_deprel:
|
| 122 |
+
word.parent.functional_children.append(word)
|
| 123 |
+
|
| 124 |
+
# Check there is a single root node
|
| 125 |
+
if len([word for word in ud.words[sentence_start:] if word.parent is None]) != 1:
|
| 126 |
+
raise UDError("There are multiple roots in a sentence")
|
| 127 |
+
|
| 128 |
+
# End the sentence
|
| 129 |
+
ud.sentences[-1].end = index
|
| 130 |
+
sentence_start = None
|
| 131 |
+
continue
|
| 132 |
+
|
| 133 |
+
# Read next token/word
|
| 134 |
+
columns = line.split("\t")
|
| 135 |
+
if len(columns) != 10:
|
| 136 |
+
raise UDError(
|
| 137 |
+
"The CoNLL-U line does not contain 10 tab-separated columns: '{}'".format(line)
|
| 138 |
+
)
|
| 139 |
+
|
| 140 |
+
# Skip empty nodes
|
| 141 |
+
if "." in columns[ID]:
|
| 142 |
+
continue
|
| 143 |
+
|
| 144 |
+
# Delete spaces from FORM, so gold.characters == system.characters even
|
| 145 |
+
# if one of them tokenizes the space. Use Unicode category Zs.
|
| 146 |
+
if sys.version_info < (3, 0) and isinstance(line, str):
|
| 147 |
+
columns[FORM] = columns[FORM].decode("utf-8")
|
| 148 |
+
columns[FORM] = "".join(filter(
|
| 149 |
+
lambda c: unicodedata.category(c) != "Zs", columns[FORM]
|
| 150 |
+
))
|
| 151 |
+
if sys.version_info < (3, 0) and isinstance(line, str):
|
| 152 |
+
columns[FORM] = columns[FORM].encode("utf-8")
|
| 153 |
+
if not columns[FORM]:
|
| 154 |
+
raise UDError("There is an empty FORM in the CoNLL-U file")
|
| 155 |
+
|
| 156 |
+
# Save token
|
| 157 |
+
ud.characters.extend(columns[FORM])
|
| 158 |
+
ud.tokens.append(UDSpan(index, index + len(columns[FORM])))
|
| 159 |
+
index += len(columns[FORM])
|
| 160 |
+
|
| 161 |
+
# Handle multi-word tokens to save word(s)
|
| 162 |
+
if "-" in columns[ID]:
|
| 163 |
+
try:
|
| 164 |
+
start, end = map(int, columns[ID].split("-"))
|
| 165 |
+
except:
|
| 166 |
+
raise UDError("Cannot parse multi-word token ID '{}'".format(columns[ID]))
|
| 167 |
+
|
| 168 |
+
for _ in range(start, end + 1):
|
| 169 |
+
word_line = file.readline().rstrip("\r\n")
|
| 170 |
+
word_columns = word_line.split("\t")
|
| 171 |
+
if len(word_columns) != 10:
|
| 172 |
+
raise UDError(
|
| 173 |
+
"The CoNLL-U line does not contain 10 tab-separated columns: '{}'".format(
|
| 174 |
+
word_line
|
| 175 |
+
)
|
| 176 |
+
)
|
| 177 |
+
ud.words.append(UDWord(ud.tokens[-1], word_columns, is_multiword=True))
|
| 178 |
+
# Basic tokens/words
|
| 179 |
+
else:
|
| 180 |
+
try:
|
| 181 |
+
word_id = int(columns[ID])
|
| 182 |
+
except:
|
| 183 |
+
raise UDError("Cannot parse word ID '{}'".format(columns[ID]))
|
| 184 |
+
if word_id != len(ud.words) - sentence_start + 1:
|
| 185 |
+
raise UDError(
|
| 186 |
+
"Incorrect word ID '{}' for word '{}', expected '{}'".format(
|
| 187 |
+
columns[ID], columns[FORM], len(ud.words) - sentence_start + 1
|
| 188 |
+
)
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
try:
|
| 192 |
+
head_id = int(columns[HEAD])
|
| 193 |
+
except:
|
| 194 |
+
raise UDError("Cannot parse HEAD '{}'".format(columns[HEAD]))
|
| 195 |
+
if head_id < 0:
|
| 196 |
+
raise UDError("HEAD cannot be negative")
|
| 197 |
+
|
| 198 |
+
ud.words.append(UDWord(ud.tokens[-1], columns, is_multiword=False))
|
| 199 |
+
|
| 200 |
+
if sentence_start is not None:
|
| 201 |
+
raise UDError("The CoNLL-U file does not end with empty line")
|
| 202 |
+
|
| 203 |
+
return ud
|
tests/test_conllu_well_formed.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import hashlib
|
| 2 |
+
import io
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
import pyarrow.parquet as pq
|
| 6 |
+
|
| 7 |
+
from scripts.vendor.conll18_ud_eval import UDError, load_conllu
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
DATA_ROOT = Path(__file__).resolve().parents[1] / "data"
|
| 11 |
+
CONFIGS = tuple(
|
| 12 |
+
f"{base}_{suffix}"
|
| 13 |
+
for base in ("prose", "verse_sentence", "verse_metre")
|
| 14 |
+
for suffix in ("1", "10", "100")
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def test_all_conllu_documents_load_with_official_conll18_parser() -> None:
|
| 19 |
+
"""Require every distinct published treebank document to parse as CoNLL-U."""
|
| 20 |
+
checked = set()
|
| 21 |
+
for config in CONFIGS:
|
| 22 |
+
for split in ("train", "validation", "test"):
|
| 23 |
+
path = DATA_ROOT / config / f"{split}-00000-of-00001.parquet"
|
| 24 |
+
parquet = pq.ParquetFile(path)
|
| 25 |
+
for batch in parquet.iter_batches(
|
| 26 |
+
columns=["id", "conllu"], batch_size=256, use_threads=False,
|
| 27 |
+
):
|
| 28 |
+
for row in batch.to_pylist():
|
| 29 |
+
digest = hashlib.sha256(row["conllu"].encode("utf-8")).digest()
|
| 30 |
+
if digest in checked:
|
| 31 |
+
continue
|
| 32 |
+
try:
|
| 33 |
+
load_conllu(io.StringIO(row["conllu"]))
|
| 34 |
+
except UDError as error:
|
| 35 |
+
raise AssertionError(
|
| 36 |
+
f"Malformed CoNLL-U in {config}/{split}, row {row['id']}: {error}"
|
| 37 |
+
) from error
|
| 38 |
+
checked.add(digest)
|
| 39 |
+
|
| 40 |
+
assert checked
|