Update clefip2011.py
Browse files- clefip2011.py +11 -16
clefip2011.py
CHANGED
|
@@ -15,19 +15,17 @@ class CLEFIP2011(datasets.GeneratorBasedBuilder):
|
|
| 15 |
"""Custom Dataset Loader"""
|
| 16 |
|
| 17 |
BUILDER_CONFIG_CLASS = CLEFIP2011Config
|
| 18 |
-
|
| 19 |
BUILDER_CONFIGS = [
|
| 20 |
CLEFIP2011Config(
|
| 21 |
name="bibliographic",
|
| 22 |
version=datasets.Version("1.0.0"),
|
| 23 |
description="CLEF-IP 2011 Bibliographic Data",
|
| 24 |
-
data_url="https://huggingface.co/datasets/amylonidis/PatClass2011/resolve/main/clefip2011_bibliographic_clean.tar.gz",
|
| 25 |
dataset_type="bibliographic",
|
| 26 |
),
|
| 27 |
]
|
| 28 |
|
| 29 |
def _info(self):
|
| 30 |
-
|
| 31 |
if self.config.dataset_type == "bibliographic":
|
| 32 |
features = datasets.Features(
|
| 33 |
{
|
|
@@ -65,13 +63,16 @@ class CLEFIP2011(datasets.GeneratorBasedBuilder):
|
|
| 65 |
)
|
| 66 |
|
| 67 |
def _split_generators(self, dl_manager):
|
| 68 |
-
|
| 69 |
archive_path = dl_manager.download_and_extract(
|
| 70 |
"https://huggingface.co/datasets/amylonidis/PatClass2011/resolve/main/clefip2011_bibliographic_clean.tar.gz"
|
| 71 |
)
|
| 72 |
|
| 73 |
bibliographic_file = os.path.join(archive_path, "clefip2011_bibliographic.csv")
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
return [
|
| 76 |
datasets.SplitGenerator(
|
| 77 |
name=datasets.Split.TRAIN,
|
|
@@ -83,11 +84,8 @@ class CLEFIP2011(datasets.GeneratorBasedBuilder):
|
|
| 83 |
]
|
| 84 |
|
| 85 |
def _generate_examples(self, filepaths, split):
|
| 86 |
-
|
| 87 |
for filepath in filepaths:
|
| 88 |
-
df = pd.read_csv(filepath,
|
| 89 |
-
|
| 90 |
-
column_names = [
|
| 91 |
"ucid",
|
| 92 |
"country",
|
| 93 |
"doc_number",
|
|
@@ -113,14 +111,10 @@ class CLEFIP2011(datasets.GeneratorBasedBuilder):
|
|
| 113 |
"claims_de_exist",
|
| 114 |
"claims_fr_exist",
|
| 115 |
"claims_en_exist",
|
| 116 |
-
]
|
| 117 |
-
df.columns = column_names
|
| 118 |
|
| 119 |
df["date"] = pd.to_datetime(df["date"], format="%Y%m%d").astype(str)
|
| 120 |
-
|
| 121 |
-
df["date_produced"] = pd.to_datetime(
|
| 122 |
-
df["date_produced"], format="%Y%m%d"
|
| 123 |
-
).astype(str)
|
| 124 |
|
| 125 |
boolean_columns = [
|
| 126 |
"abstract_de_exist",
|
|
@@ -136,5 +130,6 @@ class CLEFIP2011(datasets.GeneratorBasedBuilder):
|
|
| 136 |
for col in boolean_columns:
|
| 137 |
df[col] = df[col].astype(bool)
|
| 138 |
|
| 139 |
-
for idx, row in df.
|
| 140 |
-
yield idx, row
|
|
|
|
|
|
| 15 |
"""Custom Dataset Loader"""
|
| 16 |
|
| 17 |
BUILDER_CONFIG_CLASS = CLEFIP2011Config
|
| 18 |
+
|
| 19 |
BUILDER_CONFIGS = [
|
| 20 |
CLEFIP2011Config(
|
| 21 |
name="bibliographic",
|
| 22 |
version=datasets.Version("1.0.0"),
|
| 23 |
description="CLEF-IP 2011 Bibliographic Data",
|
|
|
|
| 24 |
dataset_type="bibliographic",
|
| 25 |
),
|
| 26 |
]
|
| 27 |
|
| 28 |
def _info(self):
|
|
|
|
| 29 |
if self.config.dataset_type == "bibliographic":
|
| 30 |
features = datasets.Features(
|
| 31 |
{
|
|
|
|
| 63 |
)
|
| 64 |
|
| 65 |
def _split_generators(self, dl_manager):
|
|
|
|
| 66 |
archive_path = dl_manager.download_and_extract(
|
| 67 |
"https://huggingface.co/datasets/amylonidis/PatClass2011/resolve/main/clefip2011_bibliographic_clean.tar.gz"
|
| 68 |
)
|
| 69 |
|
| 70 |
bibliographic_file = os.path.join(archive_path, "clefip2011_bibliographic.csv")
|
| 71 |
|
| 72 |
+
# Check if the file exists
|
| 73 |
+
if not os.path.isfile(bibliographic_file):
|
| 74 |
+
raise FileNotFoundError(f"{bibliographic_file} not found in the extracted archive.")
|
| 75 |
+
|
| 76 |
return [
|
| 77 |
datasets.SplitGenerator(
|
| 78 |
name=datasets.Split.TRAIN,
|
|
|
|
| 84 |
]
|
| 85 |
|
| 86 |
def _generate_examples(self, filepaths, split):
|
|
|
|
| 87 |
for filepath in filepaths:
|
| 88 |
+
df = pd.read_csv(filepath, names=[
|
|
|
|
|
|
|
| 89 |
"ucid",
|
| 90 |
"country",
|
| 91 |
"doc_number",
|
|
|
|
| 111 |
"claims_de_exist",
|
| 112 |
"claims_fr_exist",
|
| 113 |
"claims_en_exist",
|
| 114 |
+
], header=None)
|
|
|
|
| 115 |
|
| 116 |
df["date"] = pd.to_datetime(df["date"], format="%Y%m%d").astype(str)
|
| 117 |
+
df["date_produced"] = pd.to_datetime(df["date_produced"], format="%Y%m%d").astype(str)
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
boolean_columns = [
|
| 120 |
"abstract_de_exist",
|
|
|
|
| 130 |
for col in boolean_columns:
|
| 131 |
df[col] = df[col].astype(bool)
|
| 132 |
|
| 133 |
+
for idx, row in enumerate(df.to_dict(orient="records")):
|
| 134 |
+
yield idx, row
|
| 135 |
+
|