Update sci_lay.py
Browse files- sci_lay.py +17 -13
sci_lay.py
CHANGED
|
@@ -140,24 +140,28 @@ class SciLay(datasets.GeneratorBasedBuilder):
|
|
| 140 |
|
| 141 |
def _generate_examples(self, paths=None):
|
| 142 |
"""Yields examples."""
|
| 143 |
-
|
| 144 |
for paths_per_journal in paths:
|
| 145 |
for path in paths_per_journal:
|
| 146 |
with open(path, "rb") as fin:
|
| 147 |
for row in fin:
|
| 148 |
json_obj = json.loads(row)
|
| 149 |
doi = json_obj[_DOI]
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
|
|
|
|
| 140 |
|
| 141 |
def _generate_examples(self, paths=None):
|
| 142 |
"""Yields examples."""
|
| 143 |
+
dois_to_examples = {} # Dictionary to store examples by DOI
|
| 144 |
for paths_per_journal in paths:
|
| 145 |
for path in paths_per_journal:
|
| 146 |
with open(path, "rb") as fin:
|
| 147 |
for row in fin:
|
| 148 |
json_obj = json.loads(row)
|
| 149 |
doi = json_obj[_DOI]
|
| 150 |
+
example = {
|
| 151 |
+
_DOI: json_obj[_DOI],
|
| 152 |
+
_PMCID: json_obj[_PMCID],
|
| 153 |
+
_SUMMARY: json_obj[_SUMMARY],
|
| 154 |
+
_ABSTRACT: json_obj[_ABSTRACT],
|
| 155 |
+
_JOURNAL: json_obj[_JOURNAL],
|
| 156 |
+
_TOPICS: json_obj[_TOPICS],
|
| 157 |
+
_KEYWORDS: json_obj[_KEYWORDS]
|
| 158 |
+
}
|
| 159 |
+
if doi not in dois_to_examples:
|
| 160 |
+
dois_to_examples[doi] = []
|
| 161 |
+
dois_to_examples[doi].append(example)
|
| 162 |
+
|
| 163 |
+
for doi, examples in dois_to_examples.items():
|
| 164 |
+
yield doi, examples
|
| 165 |
+
|
| 166 |
|
| 167 |
|