Update sci_lay.py
Browse files- sci_lay.py +8 -3
sci_lay.py
CHANGED
|
@@ -3,6 +3,8 @@
|
|
| 3 |
import gzip
|
| 4 |
import json
|
| 5 |
import os
|
|
|
|
|
|
|
| 6 |
|
| 7 |
import datasets
|
| 8 |
|
|
@@ -143,9 +145,10 @@ class SciLay(datasets.GeneratorBasedBuilder):
|
|
| 143 |
for paths_per_journal in paths:
|
| 144 |
for path in paths_per_journal:
|
| 145 |
with open(path, "rb") as fin:
|
| 146 |
-
for
|
| 147 |
json_obj = json.loads(row)
|
| 148 |
-
|
|
|
|
| 149 |
_DOI: json_obj[_DOI],
|
| 150 |
_PMCID: json_obj[_PMCID],
|
| 151 |
_SUMMARY: json_obj[_SUMMARY],
|
|
@@ -156,4 +159,6 @@ class SciLay(datasets.GeneratorBasedBuilder):
|
|
| 156 |
}
|
| 157 |
|
| 158 |
|
| 159 |
-
|
|
|
|
|
|
|
|
|
| 3 |
import gzip
|
| 4 |
import json
|
| 5 |
import os
|
| 6 |
+
import random
|
| 7 |
+
import string
|
| 8 |
|
| 9 |
import datasets
|
| 10 |
|
|
|
|
| 145 |
for paths_per_journal in paths:
|
| 146 |
for path in paths_per_journal:
|
| 147 |
with open(path, "rb") as fin:
|
| 148 |
+
for row in fin:
|
| 149 |
json_obj = json.loads(row)
|
| 150 |
+
unique_key = f"{json_obj[_DOI]}_{generate_random_string()}"
|
| 151 |
+
yield unique_key, {
|
| 152 |
_DOI: json_obj[_DOI],
|
| 153 |
_PMCID: json_obj[_PMCID],
|
| 154 |
_SUMMARY: json_obj[_SUMMARY],
|
|
|
|
| 159 |
}
|
| 160 |
|
| 161 |
|
| 162 |
+
def generate_random_string(length=10):
|
| 163 |
+
letters = string.ascii_lowercase + string.ascii_uppercase
|
| 164 |
+
return ''.join(random.choice(letters) for _ in range(length))
|