Upload 2 files
Browse files- convert_FICTREE.py +63 -0
- test.jsonl +0 -0
convert_FICTREE.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Author: Martin Fajčík
|
| 2 |
+
"""
|
| 3 |
+
The corpus is provided in a vertical format, where sentence boundaries are marked with
|
| 4 |
+
a blank line. Every word form is written on a separate line, followed by five tab-separated
|
| 5 |
+
attributes: lemma, tag, ID (word index in the sentence), head and deprel (analytical function,
|
| 6 |
+
afun in the PDT formalism). The texts are shuffled in random chunks of maximum 100 words
|
| 7 |
+
(respecting sentence boundaries). Each chunk is provided as a separate file, with the suggested
|
| 8 |
+
division into train, dev and test sets written as file prefix.
|
| 9 |
+
|
| 10 |
+
Korpus FicTree se skládá z osmi prozaických děl z žánru beletrie vydaných v České republice mezi
|
| 11 |
+
lety 1991 a 2007. Šest z těchto literárních děl se (dle klasifikace textů podle žánrů používané
|
| 12 |
+
v ČNK do r. 2015) považuje za „čistou“ beletrii, jedno dílo se řadí k memoárům, jedno dílo spadá
|
| 13 |
+
do žánru „literatura pro děti a mládež“. Pět textů (80% tokenů) jsou původní české texty, dva texty
|
| 14 |
+
jsou překlady z němčiny, jeden je překlad ze slovenštiny.
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
import os
|
| 18 |
+
import re
|
| 19 |
+
|
| 20 |
+
from jsonlines import jsonlines
|
| 21 |
+
|
| 22 |
+
"""
|
| 23 |
+
TODO: Convert FICTREE dataset
|
| 24 |
+
"""
|
| 25 |
+
documents = {
|
| 26 |
+
"train": [],
|
| 27 |
+
"dev": [],
|
| 28 |
+
"test": []
|
| 29 |
+
}
|
| 30 |
+
# read all vert files
|
| 31 |
+
FOLDER = ".data/FICTREE_1.0/FicTree/"
|
| 32 |
+
ws_before_punct = re.compile(r'\s+([.,!?])')
|
| 33 |
+
|
| 34 |
+
for file in os.listdir(FOLDER):
|
| 35 |
+
if file.endswith(".vert"):
|
| 36 |
+
with open(os.path.join(FOLDER, file), "r") as f:
|
| 37 |
+
if file.startswith("train"):
|
| 38 |
+
documents["train"].append(f.read())
|
| 39 |
+
elif file.startswith("dev"):
|
| 40 |
+
documents["dev"].append(f.read())
|
| 41 |
+
elif file.startswith("test"):
|
| 42 |
+
documents["test"].append(f.read())
|
| 43 |
+
|
| 44 |
+
for split, docs in list(documents.items()):
|
| 45 |
+
new_docs = []
|
| 46 |
+
for doc in docs:
|
| 47 |
+
new_doc = []
|
| 48 |
+
for line in doc.splitlines():
|
| 49 |
+
token = line.split("\t")[0].strip()
|
| 50 |
+
if token != "":
|
| 51 |
+
new_doc.append(token)
|
| 52 |
+
text = " ".join(new_doc)
|
| 53 |
+
new_doc = re.sub(ws_before_punct, r'\1', text)
|
| 54 |
+
new_docs.append(new_doc)
|
| 55 |
+
documents[split] = new_docs
|
| 56 |
+
|
| 57 |
+
# write all splits into same json file in .data/hf_dataset/cnc_fictree/test.jsonl
|
| 58 |
+
OF = ".data/hf_dataset/cnc_fictree/test.jsonl"
|
| 59 |
+
os.makedirs(os.path.dirname(OF), exist_ok=True)
|
| 60 |
+
with jsonlines.open(OF, "w") as writer:
|
| 61 |
+
for split, docs in list(documents.items()):
|
| 62 |
+
for doc in docs:
|
| 63 |
+
writer.write({"text": doc, "orig_split": split})
|
test.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|