Datasets:
CZLC
/

Modalities:
Text
Formats:
json
Languages:
Czech
Libraries:
Datasets
pandas
License:
File size: 2,455 Bytes
a90baf6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b3f512a
a90baf6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 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})