hanaskitek
commited on
Commit
•
c0ebbe0
1
Parent(s):
75f7650
ginco version1
Browse files
ginco.py
ADDED
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
2 |
+
#
|
3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
# you may not use this file except in compliance with the License.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing, software
|
10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
# See the License for the specific language governing permissions and
|
13 |
+
# limitations under the License.
|
14 |
+
|
15 |
+
import csv
|
16 |
+
import json
|
17 |
+
import os
|
18 |
+
|
19 |
+
import datasets
|
20 |
+
|
21 |
+
_CITATION = """\
|
22 |
+
@misc{11356/1467,
|
23 |
+
title = {Slovene Web genre identification corpus {GINCO} 1.0},
|
24 |
+
author = {Kuzman, Taja and Brglez, Mojca and Rupnik, Peter and Ljube{\v s}i{\'c}, Nikola},
|
25 |
+
url = {http://hdl.handle.net/11356/1467},
|
26 |
+
note = {Slovenian language resource repository {CLARIN}.{SI}},
|
27 |
+
copyright = {Creative Commons - Attribution-{ShareAlike} 4.0 International ({CC} {BY}-{SA} 4.0)},
|
28 |
+
issn = {2820-4042},
|
29 |
+
year = {2021} }
|
30 |
+
"""
|
31 |
+
|
32 |
+
_DESCRIPTION = """\
|
33 |
+
The Slovene Web genre identification corpus GINCO 1.0 contains web texts, manually annotated with genre,
|
34 |
+
from two Slovene web corpora, the slWaC 2.0 corpus, crawled in 2014, and a web corpus, crawled in 2021 in the scope of the MaCoCu project.
|
35 |
+
The corpus allows for automated genre identification and genre analyses as well as other web corpora research, and comprises two parts:
|
36 |
+
- subcorpus of suitable texts, containing 1002 texts (478,969 words), manually annotated with 24 genre categories (News/Reporting, Announcement,
|
37 |
+
Research Article, Instruction, Recipe, Call (such as a Call for Papers), Legal/Regulation, Information/Explanation, Opinionated News, Review,
|
38 |
+
Opinion/Argumentation, Promotion of a Product, Promotion of Services, Invitation, Promotion, Interview, Forum, Correspondence, Script/Drama,
|
39 |
+
Prose, Lyrical, FAQ (Frequently Asked Questions), List of Summaries/Excerpts, and Other)
|
40 |
+
- subcorpus of unsuitable texts, containing 123 texts (173,778 words), discarded as not suitable for genre annotation due to reasons,
|
41 |
+
encoded by the labels (Machine Translation, Generated Text, Not Slovene, Encoding Issues, HTML Source Code, Boilerplate, Too Short/Incoherent,
|
42 |
+
Too Long (longer than 5,000 words), Non-Textual (no full sentences, e.g. tables, lists), and Multiple texts).
|
43 |
+
The texts in the suitable subset are annotated with up to three genre categories, where the primary label is the most prevalent,
|
44 |
+
and secondary and tertiary labels denote presence of additional genre(s). They are encoded in three levels of detail, allowing experiments
|
45 |
+
with the full set (24 labels), set of 21 labels (labels with less than 5 instances are merged with label Other) and set of 12 labels (similar labels
|
46 |
+
are merged). Additionally, the corpus contains some metadata about the text (e.g. url, domain, year) and its paragraphs (e.g. near-duplicates and their usefulness for the genre identification).
|
47 |
+
"""
|
48 |
+
|
49 |
+
_HOMEPAGE = "http://hdl.handle.net/11356/1467"
|
50 |
+
|
51 |
+
_LICENSE = "Creative Commons - Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)"
|
52 |
+
|
53 |
+
|
54 |
+
_URLS = {
|
55 |
+
"ginco": "https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1467/GINCO-1.0-suitable.json.zip?sequence=5&isAllowed=y",
|
56 |
+
}
|
57 |
+
|
58 |
+
|
59 |
+
class Ginco(datasets.GeneratorBasedBuilder):
|
60 |
+
"""Genre identification and genre analyses for Slovenian texts."""
|
61 |
+
|
62 |
+
VERSION = datasets.Version("1.1.0")
|
63 |
+
|
64 |
+
def _info(self):
|
65 |
+
|
66 |
+
features = datasets.Features(
|
67 |
+
{
|
68 |
+
"id": datasets.Value("string"),
|
69 |
+
"url": datasets.Value("string"),
|
70 |
+
"crawled": datasets.Value("string"),
|
71 |
+
"hard": datasets.Value("bool"),
|
72 |
+
"paragraphs": [
|
73 |
+
{
|
74 |
+
"text": datasets.Value("string"),
|
75 |
+
"duplicate": datasets.Value("bool"),
|
76 |
+
"keep": datasets.Value("bool"),
|
77 |
+
}
|
78 |
+
],
|
79 |
+
"primary_level_1": datasets.Value("string"),
|
80 |
+
"primary_level_2": datasets.Value("string"),
|
81 |
+
"primary_level_3": datasets.Value("string"),
|
82 |
+
"secondary_level_1": datasets.Value("string"),
|
83 |
+
"secondary_level_2": datasets.Value("string"),
|
84 |
+
"secondary_level_3": datasets.Value("string"),
|
85 |
+
"tertiary_level_1": datasets.Value("string"),
|
86 |
+
"tertiary_level_2": datasets.Value("string"),
|
87 |
+
"tertiary_level_3": datasets.Value("string"),
|
88 |
+
"split": datasets.Value("string"),
|
89 |
+
"domain": datasets.Value("string"),
|
90 |
+
}
|
91 |
+
)
|
92 |
+
|
93 |
+
return datasets.DatasetInfo(
|
94 |
+
description=_DESCRIPTION,
|
95 |
+
features=features,
|
96 |
+
homepage=_HOMEPAGE,
|
97 |
+
license=_LICENSE,
|
98 |
+
citation=_CITATION,
|
99 |
+
)
|
100 |
+
|
101 |
+
|
102 |
+
|
103 |
+
def _split_generators(self, dl_manager):
|
104 |
+
urls = _URLS["ginco"]
|
105 |
+
download_path = dl_manager.download_and_extract(urls)
|
106 |
+
download_path = os.path.join(download_path, "GINCO-1.0-suitable.json", "GINCO-1.0-suitable.json")
|
107 |
+
|
108 |
+
return [
|
109 |
+
datasets.SplitGenerator(
|
110 |
+
name=datasets.Split.TRAIN,
|
111 |
+
gen_kwargs={
|
112 |
+
"filepath": download_path,
|
113 |
+
"split": "train",
|
114 |
+
},
|
115 |
+
),
|
116 |
+
|
117 |
+
datasets.SplitGenerator(
|
118 |
+
name=datasets.Split.VALIDATION,
|
119 |
+
gen_kwargs={
|
120 |
+
"filepath": download_path,
|
121 |
+
"split": "dev",
|
122 |
+
},
|
123 |
+
),
|
124 |
+
|
125 |
+
datasets.SplitGenerator(
|
126 |
+
name=datasets.Split.TEST,
|
127 |
+
gen_kwargs={
|
128 |
+
"filepath": download_path,
|
129 |
+
"split": "test",
|
130 |
+
},
|
131 |
+
),
|
132 |
+
]
|
133 |
+
|
134 |
+
def _generate_examples(self, filepath, split):
|
135 |
+
|
136 |
+
with open(filepath, "r", encoding='utf-8') as file_obj:
|
137 |
+
data = json.load(file_obj)
|
138 |
+
|
139 |
+
if split == "train":
|
140 |
+
examples = [example for example in data if example["split"] == "train"]
|
141 |
+
elif split == "dev":
|
142 |
+
examples = [example for example in data if example["split"] == "dev"]
|
143 |
+
elif split == "test":
|
144 |
+
examples = [example for example in data if example["split"] == "test"]
|
145 |
+
|
146 |
+
for i, example in enumerate(examples):
|
147 |
+
yield i, {
|
148 |
+
"id": example["id"],
|
149 |
+
"url": example["url"],
|
150 |
+
"crawled": example["crawled"],
|
151 |
+
"hard": example["hard"],
|
152 |
+
"paragraphs": example["paragraphs"],
|
153 |
+
"primary_level_1": example["primary_level_1"],
|
154 |
+
"primary_level_2": example["primary_level_2"],
|
155 |
+
"primary_level_3": example["primary_level_3"],
|
156 |
+
"secondary_level_1": example["secondary_level_1"],
|
157 |
+
"secondary_level_2": example["secondary_level_2"],
|
158 |
+
"secondary_level_3": example["secondary_level_3"],
|
159 |
+
"tertiary_level_1": example["tertiary_level_1"],
|
160 |
+
"tertiary_level_2": example["tertiary_level_2"],
|
161 |
+
"tertiary_level_3": example["tertiary_level_3"],
|
162 |
+
"split": example["split"],
|
163 |
+
"domain": example["domain"],
|
164 |
+
}
|