Update pubmed25_debug.py
Browse files- pubmed25_debug.py +21 -3
pubmed25_debug.py
CHANGED
|
@@ -20,7 +20,7 @@ import gzip
|
|
| 20 |
import xml.etree.ElementTree as ET # Using standard ElementTree
|
| 21 |
|
| 22 |
import datasets
|
| 23 |
-
|
| 24 |
|
| 25 |
logger = datasets.logging.get_logger(__name__)
|
| 26 |
|
|
@@ -40,9 +40,27 @@ _HOMEPAGE = "https://www.nlm.nih.gov/databases/download/pubmed_medline.html"
|
|
| 40 |
|
| 41 |
_LICENSE = "" # Assuming standard NLM terms apply, check source for specifics
|
| 42 |
|
| 43 |
-
#
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
|
|
|
|
|
|
| 46 |
|
| 47 |
# Copyright Ferry Boender, released under the MIT license.
|
| 48 |
# Modified by @Narsil to handle more oddities
|
|
|
|
| 20 |
import xml.etree.ElementTree as ET # Using standard ElementTree
|
| 21 |
|
| 22 |
import datasets
|
| 23 |
+
import random
|
| 24 |
|
| 25 |
logger = datasets.logging.get_logger(__name__)
|
| 26 |
|
|
|
|
| 40 |
|
| 41 |
_LICENSE = "" # Assuming standard NLM terms apply, check source for specifics
|
| 42 |
|
| 43 |
+
# Parameters
|
| 44 |
+
total_files = 1274
|
| 45 |
+
num_bins = 50
|
| 46 |
+
total_urls = 20
|
| 47 |
+
|
| 48 |
+
# Compute bin size
|
| 49 |
+
bin_size = total_files // num_bins
|
| 50 |
+
|
| 51 |
+
# Sample one random file from each bin
|
| 52 |
+
selected_indices = []
|
| 53 |
+
for b in range(num_bins):
|
| 54 |
+
start = b * bin_size + 1
|
| 55 |
+
end = min((b + 1) * bin_size + 1, total_files + 1)
|
| 56 |
+
if start < end:
|
| 57 |
+
selected_indices.append(random.randint(start, end - 1))
|
| 58 |
+
|
| 59 |
+
# Ensure we only keep 20 URLs total (in case rounding leads to more)
|
| 60 |
+
selected_indices = sorted(random.sample(selected_indices, total_urls))
|
| 61 |
|
| 62 |
+
# Create URLs
|
| 63 |
+
_URLs = [f"https://ftp.ncbi.nlm.nih.gov/pubmed/baseline/pubmed25n{i:04d}.xml.gz" for i in selected_indices]
|
| 64 |
|
| 65 |
# Copyright Ferry Boender, released under the MIT license.
|
| 66 |
# Modified by @Narsil to handle more oddities
|