system HF staff commited on
Commit
b82a70c
1 Parent(s): 85d70f9

Update files from the datasets library (from 1.16.0)

Browse files

Release notes: https://github.com/huggingface/datasets/releases/tag/1.16.0

Files changed (2) hide show
  1. README.md +1 -0
  2. 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
- downloaded_dir = dl_manager.download_and_extract(url_to_download)
115
  return [
116
  datasets.SplitGenerator(
117
  name=datasets.Split.TRAIN,
118
  gen_kwargs={
119
- "dirpath": downloaded_dir,
120
  },
121
  ),
122
  ]
123
 
124
- def _generate_examples(self, dirpath):
125
- for file_idx, filepath in enumerate(sorted(Path(dirpath).iterdir())):
126
- with open(filepath, encoding="latin-1") as f:
127
- example = {}
128
- # raw
129
- text = []
130
- # tagged
131
- words = []
132
- lemmas = []
133
- pos_tags = []
134
- wordnet_senses = []
135
- for row_idx, row in enumerate(f):
136
- if self.config.form == "raw":
137
- if row.startswith("<doc id"):
138
- metadata_match = METADATA_PATTERN.match(row)
139
- example["id"] = metadata_match.group("id") if metadata_match else ""
140
- example["title"] = metadata_match.group("title") if metadata_match else ""
141
- elif row.startswith("</doc>"):
142
- pass
143
- elif row.startswith("ENDOFARTICLE"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  yield f"{file_idx}_{row_idx}", {
145
  "id": example["id"],
146
  "title": example["title"],
147
- "text": "\n".join(text).strip(),
 
 
 
148
  }
 
 
 
 
 
149
  example = {}
150
- text = []
151
- else:
152
- text.append(row)
153
- elif self.config.form == "tagged":
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)