Datasets:
CZLC
/

Modalities:
Text
Formats:
json
Languages:
Czech
Libraries:
Datasets
pandas
License:
CNC_fictree / convert_FICTREE.py
mfajcik's picture
Update convert_FICTREE.py
b3f512a verified
# Author: Martin Fajčík
"""
The corpus is provided in a vertical format, where sentence boundaries are marked with
a blank line. Every word form is written on a separate line, followed by five tab-separated
attributes: lemma, tag, ID (word index in the sentence), head and deprel (analytical function,
afun in the PDT formalism). The texts are shuffled in random chunks of maximum 100 words
(respecting sentence boundaries). Each chunk is provided as a separate file, with the suggested
division into train, dev and test sets written as file prefix.
Korpus FicTree se skládá z osmi prozaických děl z žánru beletrie vydaných v České republice mezi
lety 1991 a 2007. Šest z těchto literárních děl se (dle klasifikace textů podle žánrů používané
v ČNK do r. 2015) považuje za „čistou“ beletrii, jedno dílo se řadí k memoárům, jedno dílo spadá
do žánru „literatura pro děti a mládež“. Pět textů (80% tokenů) jsou původní české texty, dva texty
jsou překlady z němčiny, jeden je překlad ze slovenštiny.
"""
import os
import re
from jsonlines import jsonlines
documents = {
"train": [],
"dev": [],
"test": []
}
# read all vert files
FOLDER = ".data/FICTREE_1.0/FicTree/"
ws_before_punct = re.compile(r'\s+([.,!?])')
for file in os.listdir(FOLDER):
if file.endswith(".vert"):
with open(os.path.join(FOLDER, file), "r") as f:
if file.startswith("train"):
documents["train"].append(f.read())
elif file.startswith("dev"):
documents["dev"].append(f.read())
elif file.startswith("test"):
documents["test"].append(f.read())
for split, docs in list(documents.items()):
new_docs = []
for doc in docs:
new_doc = []
for line in doc.splitlines():
token = line.split("\t")[0].strip()
if token != "":
new_doc.append(token)
text = " ".join(new_doc)
new_doc = re.sub(ws_before_punct, r'\1', text)
new_docs.append(new_doc)
documents[split] = new_docs
# write all splits into same json file in .data/hf_dataset/cnc_fictree/test.jsonl
OF = ".data/hf_dataset/cnc_fictree/test.jsonl"
os.makedirs(os.path.dirname(OF), exist_ok=True)
with jsonlines.open(OF, "w") as writer:
for split, docs in list(documents.items()):
for doc in docs:
writer.write({"text": doc, "orig_split": split})