Upload 4 files
Browse files- README.md +7 -0
- kgr10-2-jsonl-converter.py +41 -0
- kgr10.jsonl.gz +3 -0
- kgr10.py +54 -0
README.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1 |
---
|
2 |
license: cc-by-4.0
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: cc-by-4.0
|
3 |
+
language:
|
4 |
+
- pl
|
5 |
---
|
6 |
+
|
7 |
+
KGR10 corpora converted to jsonl format.
|
8 |
+
|
9 |
+
Thanks for [clarin-knext](https://huggingface.co/clarin-knext) for kgr10 in [raw txt files](https://huggingface.co/datasets/clarin-knext/kgr10_pl).
|
10 |
+
|
kgr10-2-jsonl-converter.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
import random
|
4 |
+
|
5 |
+
FILES = {
|
6 |
+
'CEN': './kgr10/CEN',
|
7 |
+
'openbooks': './kgr10/openbooks',
|
8 |
+
'open_science': './kgr10/open_science',
|
9 |
+
'wikisources-pl': './kgr10/wikisources-pl',
|
10 |
+
'sejm': './kgr10/sejm/',
|
11 |
+
}
|
12 |
+
|
13 |
+
|
14 |
+
def main():
|
15 |
+
idnum = 0
|
16 |
+
kgr10 = []
|
17 |
+
for sname, spath in FILES.items():
|
18 |
+
for fname in os.listdir(spath):
|
19 |
+
with open(os.path.join(spath, fname), 'rt') as fin:
|
20 |
+
content = fin.readlines()
|
21 |
+
content = "\n".join(content).strip()
|
22 |
+
kgr10.append(
|
23 |
+
json.dumps(
|
24 |
+
{
|
25 |
+
'id': idnum,
|
26 |
+
'corpora': sname.strip(),
|
27 |
+
'filename': fname.strip(),
|
28 |
+
'text': content
|
29 |
+
}
|
30 |
+
)
|
31 |
+
)
|
32 |
+
idnum += 1
|
33 |
+
|
34 |
+
random.shuffle(kgr10)
|
35 |
+
|
36 |
+
with open('./kgr10.jsonl', 'wt') as fout:
|
37 |
+
for kgr10_item in kgr10:
|
38 |
+
fout.write(kgr10_item + "\n")
|
39 |
+
|
40 |
+
if __name__ == '__main__':
|
41 |
+
main()
|
kgr10.jsonl.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:154efb69c7f621511d5028c32dc669a6f1497d60238d31e8955e9df4045a9a79
|
3 |
+
size 158280477
|
kgr10.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import csv
|
3 |
+
import os
|
4 |
+
import datasets
|
5 |
+
|
6 |
+
logger = datasets.logging.get_logger(__name__)
|
7 |
+
|
8 |
+
_DESCRIPTION = """
|
9 |
+
This is the KGR10 corpora converted to jsonl format
|
10 |
+
"""
|
11 |
+
_SPLITS = ["corpus"]
|
12 |
+
|
13 |
+
_URLs = {
|
14 |
+
"corpus": "kgr10.jsonl.gz"
|
15 |
+
}
|
16 |
+
|
17 |
+
class KGR10(datasets.GeneratorBasedBuilder):
|
18 |
+
BUILDER_CONFIGS = [
|
19 |
+
datasets.BuilderConfig(
|
20 |
+
name="corpus",
|
21 |
+
description=_DESCRIPTION
|
22 |
+
)
|
23 |
+
]
|
24 |
+
|
25 |
+
def _info(self):
|
26 |
+
return datasets.DatasetInfo(
|
27 |
+
description=_DESCRIPTION,
|
28 |
+
features=datasets.Features({
|
29 |
+
"id": datasets.Value("string"),
|
30 |
+
"corpora": datasets.Value("string"),
|
31 |
+
"filename": datasets.Value("string"),
|
32 |
+
"text": datasets.Value("string"),
|
33 |
+
}),
|
34 |
+
supervised_keys=None,
|
35 |
+
)
|
36 |
+
|
37 |
+
def _split_generators(self, dl_manager):
|
38 |
+
my_urls = _URLs[self.config.name]
|
39 |
+
data_dir = dl_manager.download_and_extract(my_urls)
|
40 |
+
|
41 |
+
return [
|
42 |
+
datasets.SplitGenerator(
|
43 |
+
name=self.config.name,
|
44 |
+
gen_kwargs={"filepath": data_dir},
|
45 |
+
),
|
46 |
+
]
|
47 |
+
|
48 |
+
def _generate_examples(self, filepath):
|
49 |
+
with open(filepath, encoding="utf-8") as f:
|
50 |
+
texts = f.readlines()
|
51 |
+
|
52 |
+
for i, text in enumerate(texts):
|
53 |
+
text = json.loads(text)
|
54 |
+
yield i, text
|