Albert Villanova del Moral
commited on
Commit
•
cff04b2
1
Parent(s):
de237a5
Join baseline and incremental paths
Browse files- open_access.py +8 -38
open_access.py
CHANGED
@@ -112,8 +112,7 @@ class OpenAccess(datasets.GeneratorBasedBuilder):
|
|
112 |
|
113 |
def _split_generators(self, dl_manager):
|
114 |
|
115 |
-
|
116 |
-
incremental_paths = []
|
117 |
for subset in self.config.subsets:
|
118 |
url = _URL.format(subset=_SUBSETS[subset])
|
119 |
basename = f"{_SUBSETS[subset]}_txt."
|
@@ -123,7 +122,6 @@ class OpenAccess(datasets.GeneratorBasedBuilder):
|
|
123 |
(f"{url}{basename}{baseline}.filelist.csv", f"{url}{basename}{baseline}.tar.gz")
|
124 |
for baseline in baselines
|
125 |
]
|
126 |
-
baseline_paths += dl_manager.download(baseline_urls)
|
127 |
# Incremental
|
128 |
date_delta = datetime.date.today() - datetime.date.fromisoformat(_BASELINE_DATE)
|
129 |
incremental_dates = [
|
@@ -135,29 +133,23 @@ class OpenAccess(datasets.GeneratorBasedBuilder):
|
|
135 |
(f"{url}{basename}{incremental}.filelist.csv", f"{url}{basename}{incremental}.tar.gz")
|
136 |
for incremental in incrementals
|
137 |
]
|
138 |
-
|
139 |
|
140 |
return [
|
141 |
datasets.SplitGenerator(
|
142 |
name=datasets.Split.TRAIN,
|
143 |
gen_kwargs={
|
144 |
-
"
|
145 |
-
(file_list, dl_manager.iter_archive(archive)) for file_list, archive in baseline_paths
|
146 |
-
],
|
147 |
-
"incremental_paths": [
|
148 |
-
(file_list, dl_manager.iter_archive(archive)) for file_list, archive in incremental_paths
|
149 |
-
],
|
150 |
},
|
151 |
),
|
152 |
]
|
153 |
|
154 |
-
def _generate_examples(self,
|
155 |
key = 0
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
data = baselines.pop(path)
|
161 |
content = file.read()
|
162 |
try:
|
163 |
text = content.decode("utf-8").strip()
|
@@ -174,25 +166,3 @@ class OpenAccess(datasets.GeneratorBasedBuilder):
|
|
174 |
}
|
175 |
yield key, data
|
176 |
key += 1
|
177 |
-
# Incrementals
|
178 |
-
if incremental_paths:
|
179 |
-
for incremental_file_list, incremental_archive in incremental_paths:
|
180 |
-
incrementals = pd.read_csv(incremental_file_list, index_col="Article File").to_dict(orient="index")
|
181 |
-
for path, file in incremental_archive:
|
182 |
-
data = incrementals.pop(path)
|
183 |
-
content = file.read()
|
184 |
-
try:
|
185 |
-
text = content.decode("utf-8").strip()
|
186 |
-
except UnicodeDecodeError as e:
|
187 |
-
text = content.decode("latin-1").strip()
|
188 |
-
data = {
|
189 |
-
"text": text,
|
190 |
-
"pmid": data["PMID"],
|
191 |
-
"accession_id": data["AccessionID"],
|
192 |
-
"license": data["License"],
|
193 |
-
"last_updated": data["LastUpdated (YYYY-MM-DD HH:MM:SS)"],
|
194 |
-
"retracted": data["Retracted"],
|
195 |
-
"citation": data["Article Citation"],
|
196 |
-
}
|
197 |
-
yield key, data
|
198 |
-
key += 1
|
|
|
112 |
|
113 |
def _split_generators(self, dl_manager):
|
114 |
|
115 |
+
paths = []
|
|
|
116 |
for subset in self.config.subsets:
|
117 |
url = _URL.format(subset=_SUBSETS[subset])
|
118 |
basename = f"{_SUBSETS[subset]}_txt."
|
|
|
122 |
(f"{url}{basename}{baseline}.filelist.csv", f"{url}{basename}{baseline}.tar.gz")
|
123 |
for baseline in baselines
|
124 |
]
|
|
|
125 |
# Incremental
|
126 |
date_delta = datetime.date.today() - datetime.date.fromisoformat(_BASELINE_DATE)
|
127 |
incremental_dates = [
|
|
|
133 |
(f"{url}{basename}{incremental}.filelist.csv", f"{url}{basename}{incremental}.tar.gz")
|
134 |
for incremental in incrementals
|
135 |
]
|
136 |
+
paths += dl_manager.download(baseline_urls + incremental_urls)
|
137 |
|
138 |
return [
|
139 |
datasets.SplitGenerator(
|
140 |
name=datasets.Split.TRAIN,
|
141 |
gen_kwargs={
|
142 |
+
"paths": [(file_list, dl_manager.iter_archive(archive)) for file_list, archive in paths],
|
|
|
|
|
|
|
|
|
|
|
143 |
},
|
144 |
),
|
145 |
]
|
146 |
|
147 |
+
def _generate_examples(self, paths):
|
148 |
key = 0
|
149 |
+
for file_list, archive in paths:
|
150 |
+
file_list_data = pd.read_csv(file_list, index_col="Article File").to_dict(orient="index")
|
151 |
+
for path, file in archive:
|
152 |
+
data = file_list_data.pop(path)
|
|
|
153 |
content = file.read()
|
154 |
try:
|
155 |
text = content.decode("utf-8").strip()
|
|
|
166 |
}
|
167 |
yield key, data
|
168 |
key += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|