Update files from the datasets library (from 1.16.0)
Browse filesRelease notes: https://github.com/huggingface/datasets/releases/tag/1.16.0
- README.md +1 -0
- wikicorpus.py +53 -54
README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
---
|
|
|
2 |
annotations_creators:
|
3 |
raw_ca:
|
4 |
- no-annotation
|
|
|
1 |
---
|
2 |
+
pretty_name: Wikicorpus
|
3 |
annotations_creators:
|
4 |
raw_ca:
|
5 |
- no-annotation
|
wikicorpus.py
CHANGED
@@ -15,7 +15,6 @@
|
|
15 |
"""Wikicorpus dataset."""
|
16 |
|
17 |
import re
|
18 |
-
from pathlib import Path
|
19 |
|
20 |
import datasets
|
21 |
|
@@ -111,69 +110,69 @@ class Wikicorpus(datasets.GeneratorBasedBuilder):
|
|
111 |
|
112 |
def _split_generators(self, dl_manager):
|
113 |
url_to_download = _URLs.format(form=self.config.form, language=self.config.language)
|
114 |
-
|
115 |
return [
|
116 |
datasets.SplitGenerator(
|
117 |
name=datasets.Split.TRAIN,
|
118 |
gen_kwargs={
|
119 |
-
"
|
120 |
},
|
121 |
),
|
122 |
]
|
123 |
|
124 |
-
def _generate_examples(self,
|
125 |
-
for file_idx,
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
yield f"{file_idx}_{row_idx}", {
|
145 |
"id": example["id"],
|
146 |
"title": example["title"],
|
147 |
-
"
|
|
|
|
|
|
|
148 |
}
|
|
|
|
|
|
|
|
|
|
|
149 |
example = {}
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
if row.startswith("<doc id"):
|
155 |
-
metadata_match = METADATA_PATTERN.match(row)
|
156 |
-
example["id"] = metadata_match.group("id") if metadata_match else ""
|
157 |
-
example["title"] = metadata_match.group("title") if metadata_match else ""
|
158 |
-
elif row.startswith("</doc>"):
|
159 |
-
pass
|
160 |
-
elif row.startswith("ENDOFARTICLE") or row.startswith("\n"):
|
161 |
-
if len(words) > 1: # some content besides only (. . Fp 0)
|
162 |
-
yield f"{file_idx}_{row_idx}", {
|
163 |
-
"id": example["id"],
|
164 |
-
"title": example["title"],
|
165 |
-
"sentence": words,
|
166 |
-
"lemmas": lemmas,
|
167 |
-
"pos_tags": pos_tags,
|
168 |
-
"wordnet_senses": wordnet_senses,
|
169 |
-
}
|
170 |
-
words = []
|
171 |
-
lemmas = []
|
172 |
-
pos_tags = []
|
173 |
-
wordnet_senses = []
|
174 |
-
if row.startswith("ENDOFARTICLE"):
|
175 |
-
example = {}
|
176 |
-
else:
|
177 |
-
splits = row.split()
|
178 |
-
for tag, tags in zip(splits, [words, lemmas, pos_tags, wordnet_senses]):
|
179 |
-
tags.append(tag)
|
|
|
15 |
"""Wikicorpus dataset."""
|
16 |
|
17 |
import re
|
|
|
18 |
|
19 |
import datasets
|
20 |
|
|
|
110 |
|
111 |
def _split_generators(self, dl_manager):
|
112 |
url_to_download = _URLs.format(form=self.config.form, language=self.config.language)
|
113 |
+
archive = dl_manager.download(url_to_download)
|
114 |
return [
|
115 |
datasets.SplitGenerator(
|
116 |
name=datasets.Split.TRAIN,
|
117 |
gen_kwargs={
|
118 |
+
"files": dl_manager.iter_archive(archive),
|
119 |
},
|
120 |
),
|
121 |
]
|
122 |
|
123 |
+
def _generate_examples(self, files):
|
124 |
+
for file_idx, (path, f) in enumerate(files):
|
125 |
+
example = {}
|
126 |
+
# raw
|
127 |
+
text = []
|
128 |
+
# tagged
|
129 |
+
words = []
|
130 |
+
lemmas = []
|
131 |
+
pos_tags = []
|
132 |
+
wordnet_senses = []
|
133 |
+
for row_idx, row in enumerate(f):
|
134 |
+
row = row.decode("latin-1")
|
135 |
+
if self.config.form == "raw":
|
136 |
+
if row.startswith("<doc id"):
|
137 |
+
metadata_match = METADATA_PATTERN.match(row)
|
138 |
+
example["id"] = metadata_match.group("id") if metadata_match else ""
|
139 |
+
example["title"] = metadata_match.group("title") if metadata_match else ""
|
140 |
+
elif row.startswith("</doc>"):
|
141 |
+
pass
|
142 |
+
elif row.startswith("ENDOFARTICLE"):
|
143 |
+
yield f"{file_idx}_{row_idx}", {
|
144 |
+
"id": example["id"],
|
145 |
+
"title": example["title"],
|
146 |
+
"text": "\n".join(text).strip(),
|
147 |
+
}
|
148 |
+
example = {}
|
149 |
+
text = []
|
150 |
+
else:
|
151 |
+
text.append(row)
|
152 |
+
elif self.config.form == "tagged":
|
153 |
+
if row.startswith("<doc id"):
|
154 |
+
metadata_match = METADATA_PATTERN.match(row)
|
155 |
+
example["id"] = metadata_match.group("id") if metadata_match else ""
|
156 |
+
example["title"] = metadata_match.group("title") if metadata_match else ""
|
157 |
+
elif row.startswith("</doc>"):
|
158 |
+
pass
|
159 |
+
elif row.startswith("ENDOFARTICLE") or row.startswith("\n"):
|
160 |
+
if len(words) > 1: # some content besides only (. . Fp 0)
|
161 |
yield f"{file_idx}_{row_idx}", {
|
162 |
"id": example["id"],
|
163 |
"title": example["title"],
|
164 |
+
"sentence": words,
|
165 |
+
"lemmas": lemmas,
|
166 |
+
"pos_tags": pos_tags,
|
167 |
+
"wordnet_senses": wordnet_senses,
|
168 |
}
|
169 |
+
words = []
|
170 |
+
lemmas = []
|
171 |
+
pos_tags = []
|
172 |
+
wordnet_senses = []
|
173 |
+
if row.startswith("ENDOFARTICLE"):
|
174 |
example = {}
|
175 |
+
else:
|
176 |
+
splits = row.split()
|
177 |
+
for tag, tags in zip(splits, [words, lemmas, pos_tags, wordnet_senses]):
|
178 |
+
tags.append(tag)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|