dacy-data / scripts /dane.py
Kenneth Enevoldsen
Use whole documents with a document-level split (v2.10.0)
2cca161 unverified
Raw History Blame Contribute Delete
1.01 kB
"""Add the named entities from DaNE to the DDT sentences.
DaNE annotates the DDT sentences, so its entities are copied onto the sentences from
ddt.py.
Inputs ``build/ddt.spacy`` (from ddt.py). Outputs ``build/dane.spacy``.
"""
from spacy.tokens import Span
from utils import BUILD, SPLITS, download_zip, read_conllu, read_docbin, write_docbin
DANE_URL = "http://danlp-downloads.alexandra.dk/datasets/ddt.zip"
def main() -> None:
folder = download_zip(DANE_URL, "dane")
dane = [doc for split in SPLITS for doc in read_conllu(folder / f"ddt.{split}.conllu")]
docs = read_docbin(BUILD / "ddt.spacy")
assert len(docs) == len(dane)
for doc, dane_doc in zip(docs, dane, strict=True):
assert doc._.sent_id == dane_doc._.sent_id
assert [t.text for t in doc] == [t.text for t in dane_doc], doc._.sent_id
doc.ents = [Span(doc, e.start, e.end, label=e.label_) for e in dane_doc.ents]
write_docbin(docs, BUILD / "dane.spacy")
if __name__ == "__main__":
main()