Support streaming
#2
by
albertvillanova
HF Staff
- opened
- bionlp_st_2013_pc.py +21 -18
- data/devel.zip +3 -0
- data/test.zip +3 -0
- data/train.zip +3 -0
bionlp_st_2013_pc.py
CHANGED
|
@@ -14,7 +14,7 @@
|
|
| 14 |
# limitations under the License.
|
| 15 |
|
| 16 |
from pathlib import Path
|
| 17 |
-
from typing import Dict, List
|
| 18 |
|
| 19 |
import datasets
|
| 20 |
|
|
@@ -70,7 +70,9 @@ _HOMEPAGE = "https://github.com/openbiocorpora/bionlp-st-2013-pc"
|
|
| 70 |
_LICENSE = 'GENIA Project License for Annotated Corpora'
|
| 71 |
|
| 72 |
_URLs = {
|
| 73 |
-
"
|
|
|
|
|
|
|
| 74 |
}
|
| 75 |
|
| 76 |
_SUPPORTED_TASKS = [
|
|
@@ -224,26 +226,19 @@ class bionlp_st_2013_pc(datasets.GeneratorBasedBuilder):
|
|
| 224 |
def _split_generators(
|
| 225 |
self, dl_manager: datasets.DownloadManager
|
| 226 |
) -> List[datasets.SplitGenerator]:
|
| 227 |
-
|
| 228 |
-
data_dir = Path(dl_manager.download_and_extract(my_urls))
|
| 229 |
-
data_files = {
|
| 230 |
-
"train": data_dir / f"bionlp-st-2013-pc-master" / "original-data" / "train",
|
| 231 |
-
"dev": data_dir / f"bionlp-st-2013-pc-master" / "original-data" / "devel",
|
| 232 |
-
"test": data_dir / f"bionlp-st-2013-pc-master" / "original-data" / "test",
|
| 233 |
-
}
|
| 234 |
-
|
| 235 |
return [
|
| 236 |
datasets.SplitGenerator(
|
| 237 |
name=datasets.Split.TRAIN,
|
| 238 |
-
gen_kwargs={"data_files": data_files["train"]},
|
| 239 |
),
|
| 240 |
datasets.SplitGenerator(
|
| 241 |
name=datasets.Split.VALIDATION,
|
| 242 |
-
gen_kwargs={"data_files": data_files["
|
| 243 |
),
|
| 244 |
datasets.SplitGenerator(
|
| 245 |
name=datasets.Split.TEST,
|
| 246 |
-
gen_kwargs={"data_files": data_files["test"]},
|
| 247 |
),
|
| 248 |
]
|
| 249 |
|
|
@@ -256,21 +251,29 @@ class bionlp_st_2013_pc(datasets.GeneratorBasedBuilder):
|
|
| 256 |
|
| 257 |
return kb_example
|
| 258 |
|
| 259 |
-
def _generate_examples(self, data_files:
|
| 260 |
if self.config.schema == "source":
|
| 261 |
-
|
| 262 |
-
for
|
|
|
|
|
|
|
|
|
|
| 263 |
example = parse_brat_file(txt_file)
|
| 264 |
example["id"] = str(guid)
|
| 265 |
yield guid, example
|
|
|
|
| 266 |
elif self.config.schema == "bigbio_kb":
|
| 267 |
-
|
| 268 |
-
for
|
|
|
|
|
|
|
|
|
|
| 269 |
example = brat_parse_to_bigbio_kb(
|
| 270 |
parse_brat_file(txt_file)
|
| 271 |
)
|
| 272 |
example = self._standardize_arguments_roles(example)
|
| 273 |
example["id"] = str(guid)
|
| 274 |
yield guid, example
|
|
|
|
| 275 |
else:
|
| 276 |
raise ValueError(f"Invalid config: {self.config.name}")
|
|
|
|
| 14 |
# limitations under the License.
|
| 15 |
|
| 16 |
from pathlib import Path
|
| 17 |
+
from typing import Dict, Iterable, List
|
| 18 |
|
| 19 |
import datasets
|
| 20 |
|
|
|
|
| 70 |
_LICENSE = 'GENIA Project License for Annotated Corpora'
|
| 71 |
|
| 72 |
_URLs = {
|
| 73 |
+
"train": "data/train.zip",
|
| 74 |
+
"validation": "data/devel.zip",
|
| 75 |
+
"test": "data/test.zip",
|
| 76 |
}
|
| 77 |
|
| 78 |
_SUPPORTED_TASKS = [
|
|
|
|
| 226 |
def _split_generators(
|
| 227 |
self, dl_manager: datasets.DownloadManager
|
| 228 |
) -> List[datasets.SplitGenerator]:
|
| 229 |
+
data_files = dl_manager.download_and_extract(_URLs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
return [
|
| 231 |
datasets.SplitGenerator(
|
| 232 |
name=datasets.Split.TRAIN,
|
| 233 |
+
gen_kwargs={"data_files": dl_manager.iter_files(data_files["train"])},
|
| 234 |
),
|
| 235 |
datasets.SplitGenerator(
|
| 236 |
name=datasets.Split.VALIDATION,
|
| 237 |
+
gen_kwargs={"data_files": dl_manager.iter_files(data_files["validation"])},
|
| 238 |
),
|
| 239 |
datasets.SplitGenerator(
|
| 240 |
name=datasets.Split.TEST,
|
| 241 |
+
gen_kwargs={"data_files": dl_manager.iter_files(data_files["test"])},
|
| 242 |
),
|
| 243 |
]
|
| 244 |
|
|
|
|
| 251 |
|
| 252 |
return kb_example
|
| 253 |
|
| 254 |
+
def _generate_examples(self, data_files: Iterable[str]):
|
| 255 |
if self.config.schema == "source":
|
| 256 |
+
guid = 0
|
| 257 |
+
for data_file in data_files:
|
| 258 |
+
txt_file = Path(data_file)
|
| 259 |
+
if txt_file.suffix != ".txt":
|
| 260 |
+
continue
|
| 261 |
example = parse_brat_file(txt_file)
|
| 262 |
example["id"] = str(guid)
|
| 263 |
yield guid, example
|
| 264 |
+
guid += 1
|
| 265 |
elif self.config.schema == "bigbio_kb":
|
| 266 |
+
guid = 0
|
| 267 |
+
for data_file in data_files:
|
| 268 |
+
txt_file = Path(data_file)
|
| 269 |
+
if txt_file.suffix != ".txt":
|
| 270 |
+
continue
|
| 271 |
example = brat_parse_to_bigbio_kb(
|
| 272 |
parse_brat_file(txt_file)
|
| 273 |
)
|
| 274 |
example = self._standardize_arguments_roles(example)
|
| 275 |
example["id"] = str(guid)
|
| 276 |
yield guid, example
|
| 277 |
+
guid += 1
|
| 278 |
else:
|
| 279 |
raise ValueError(f"Invalid config: {self.config.name}")
|
data/devel.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7d960658be6c8baf12924aa3fe08da392002c11353791b4867554a89adf050f0
|
| 3 |
+
size 202006
|
data/test.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:760f575d41bbd17f37375f2c694ee50bc2441571ea734a45ef75e40654641ea9
|
| 3 |
+
size 260734
|
data/train.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d3b6b85373d120b97f76489af9e68da0132eef6ac8617bafe0453d4f2385432a
|
| 3 |
+
size 578917
|