biomarkit 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. biomarkit-1.0.0/.gitignore +20 -0
  2. biomarkit-1.0.0/.python-version +1 -0
  3. biomarkit-1.0.0/LICENSE +21 -0
  4. biomarkit-1.0.0/PKG-INFO +185 -0
  5. biomarkit-1.0.0/README.md +140 -0
  6. biomarkit-1.0.0/biomarkit/__init__.py +3 -0
  7. biomarkit-1.0.0/biomarkit/config.py +85 -0
  8. biomarkit-1.0.0/biomarkit/main.py +303 -0
  9. biomarkit-1.0.0/biomarkit/standardisation/__init__.py +0 -0
  10. biomarkit-1.0.0/biomarkit/standardisation/content_list/__init__.py +0 -0
  11. biomarkit-1.0.0/biomarkit/standardisation/content_list/filters.py +108 -0
  12. biomarkit-1.0.0/biomarkit/standardisation/content_list/renderer.py +118 -0
  13. biomarkit-1.0.0/biomarkit/standardisation/content_list/schema.py +225 -0
  14. biomarkit-1.0.0/biomarkit/standardisation/generics.py +45 -0
  15. biomarkit-1.0.0/biomarkit/standardisation/llms/__init__.py +0 -0
  16. biomarkit-1.0.0/biomarkit/standardisation/llms/llm_classifier.py +115 -0
  17. biomarkit-1.0.0/biomarkit/standardisation/llms/prompts.py +137 -0
  18. biomarkit-1.0.0/biomarkit/standardisation/llms/providers/__init__.py +0 -0
  19. biomarkit-1.0.0/biomarkit/standardisation/text_cleaning/__init__.py +0 -0
  20. biomarkit-1.0.0/biomarkit/standardisation/text_cleaning/cleaner.py +389 -0
  21. biomarkit-1.0.0/biomarkit/text_download/__init__.py +0 -0
  22. biomarkit-1.0.0/biomarkit/text_download/apis/__init__.py +0 -0
  23. biomarkit-1.0.0/biomarkit/text_download/apis/abc/__init__.py +0 -0
  24. biomarkit-1.0.0/biomarkit/text_download/apis/abc/playwright_publisher_api.py +200 -0
  25. biomarkit-1.0.0/biomarkit/text_download/apis/abc/publisher_api.py +272 -0
  26. biomarkit-1.0.0/biomarkit/text_download/apis/clients/__init__.py +0 -0
  27. biomarkit-1.0.0/biomarkit/text_download/apis/clients/am_phyto_soc.py +50 -0
  28. biomarkit-1.0.0/biomarkit/text_download/apis/clients/copernicus.py +74 -0
  29. biomarkit-1.0.0/biomarkit/text_download/apis/clients/elsevier.py +55 -0
  30. biomarkit-1.0.0/biomarkit/text_download/apis/clients/frontiers.py +71 -0
  31. biomarkit-1.0.0/biomarkit/text_download/apis/clients/mdpi.py +48 -0
  32. biomarkit-1.0.0/biomarkit/text_download/apis/clients/opensource.py +229 -0
  33. biomarkit-1.0.0/biomarkit/text_download/apis/clients/springer.py +55 -0
  34. biomarkit-1.0.0/biomarkit/text_download/apis/clients/taylor_and_francis.py +49 -0
  35. biomarkit-1.0.0/biomarkit/text_download/apis/clients/wiley.py +89 -0
  36. biomarkit-1.0.0/biomarkit/text_download/apis/map.py +22 -0
  37. biomarkit-1.0.0/biomarkit/text_download/apis/router.py +238 -0
  38. biomarkit-1.0.0/biomarkit/text_download/apis/strings.py +11 -0
  39. biomarkit-1.0.0/biomarkit/text_download/basemodels/__init__.py +0 -0
  40. biomarkit-1.0.0/biomarkit/text_download/basemodels/publication.py +67 -0
  41. biomarkit-1.0.0/biomarkit/text_download/controller/__init__.py +0 -0
  42. biomarkit-1.0.0/biomarkit/text_download/controller/controller.py +124 -0
  43. biomarkit-1.0.0/biomarkit/text_download/database/__init__.py +0 -0
  44. biomarkit-1.0.0/biomarkit/text_download/database/database.py +127 -0
  45. biomarkit-1.0.0/biomarkit/text_download/filter/__init__.py +0 -0
  46. biomarkit-1.0.0/biomarkit/text_download/filter/filter_scopus_csv.py +103 -0
  47. biomarkit-1.0.0/biomarkit/text_download/filter/publisher_map.py +108 -0
  48. biomarkit-1.0.0/biomarkit/text_download/logging/__init__.py +0 -0
  49. biomarkit-1.0.0/biomarkit/text_download/logging/logger.py +0 -0
  50. biomarkit-1.0.0/biomarkit/text_download/utils/__init__.py +0 -0
  51. biomarkit-1.0.0/biomarkit/text_download/utils/generics.py +455 -0
  52. biomarkit-1.0.0/biomarkit/text_download/visualisation/__init__.py +0 -0
  53. biomarkit-1.0.0/biomarkit/text_download/visualisation/download_report.py +186 -0
  54. biomarkit-1.0.0/biomarkit/text_download/visualisation/scopus_query_report.py +148 -0
  55. biomarkit-1.0.0/biomarkit/text_download/visualisation/text_extraction_report.py +133 -0
  56. biomarkit-1.0.0/biomarkit/text_transformation/__init__.py +0 -0
  57. biomarkit-1.0.0/biomarkit/text_transformation/controller/__init__.py +0 -0
  58. biomarkit-1.0.0/biomarkit/text_transformation/controller/controller.py +123 -0
  59. biomarkit-1.0.0/biomarkit/text_transformation/converters/ABC/__init__.py +0 -0
  60. biomarkit-1.0.0/biomarkit/text_transformation/converters/ABC/transformer.py +123 -0
  61. biomarkit-1.0.0/biomarkit/text_transformation/converters/__init__.py +0 -0
  62. biomarkit-1.0.0/biomarkit/text_transformation/converters/elsevier2json.py +1089 -0
  63. biomarkit-1.0.0/biomarkit/text_transformation/converters/mineru_pdf_to_md.py +237 -0
  64. biomarkit-1.0.0/biomarkit/text_transformation/utils/__init__.py +0 -0
  65. biomarkit-1.0.0/biomarkit/text_transformation/utils/generics.py +180 -0
  66. biomarkit-1.0.0/biomarkit/text_transformation/visualisation/__init__.py +0 -0
  67. biomarkit-1.0.0/biomarkit/text_transformation/visualisation/conversion_report.py +254 -0
  68. biomarkit-1.0.0/docs/devs/customisation.md +137 -0
  69. biomarkit-1.0.0/docs/general/general.md +218 -0
  70. biomarkit-1.0.0/docs/statics/1.png +0 -0
  71. biomarkit-1.0.0/docs/statics/2.png +0 -0
  72. biomarkit-1.0.0/docs/statics/F1.png +0 -0
  73. biomarkit-1.0.0/pyproject.toml +64 -0
  74. biomarkit-1.0.0/pytest.ini +2 -0
  75. biomarkit-1.0.0/secrets.env.example +16 -0
  76. biomarkit-1.0.0/tests/__init__.py +0 -0
  77. biomarkit-1.0.0/tests/conftest.py +30 -0
  78. biomarkit-1.0.0/tests/standardisation/__init__.py +0 -0
  79. biomarkit-1.0.0/tests/standardisation/content_list/__init__.py +0 -0
  80. biomarkit-1.0.0/tests/standardisation/content_list/test_filters.py +273 -0
  81. biomarkit-1.0.0/tests/standardisation/content_list/test_renderer.py +242 -0
  82. biomarkit-1.0.0/tests/standardisation/llms/__init__.py +0 -0
  83. biomarkit-1.0.0/tests/standardisation/llms/test_llm_classifier.py +183 -0
  84. biomarkit-1.0.0/tests/standardisation/text_cleaning/__init__.py +0 -0
  85. biomarkit-1.0.0/tests/standardisation/text_cleaning/test_cleaner.py +557 -0
  86. biomarkit-1.0.0/tests/test_data/scopus_test_query.csv +101 -0
  87. biomarkit-1.0.0/tests/test_main.py +101 -0
  88. biomarkit-1.0.0/tests/text_download/__init__.py +0 -0
  89. biomarkit-1.0.0/tests/text_download/apis/__init__.py +0 -0
  90. biomarkit-1.0.0/tests/text_download/apis/abc/test_playwright_publisher_api.py +181 -0
  91. biomarkit-1.0.0/tests/text_download/apis/abc/test_publisher_api.py +206 -0
  92. biomarkit-1.0.0/tests/text_download/apis/clients/test_am_phyto_soc.py +58 -0
  93. biomarkit-1.0.0/tests/text_download/apis/clients/test_elsevier.py +49 -0
  94. biomarkit-1.0.0/tests/text_download/apis/clients/test_frontiers.py +78 -0
  95. biomarkit-1.0.0/tests/text_download/apis/clients/test_mdpi.py +49 -0
  96. biomarkit-1.0.0/tests/text_download/apis/clients/test_opensource.py +300 -0
  97. biomarkit-1.0.0/tests/text_download/apis/clients/test_springer.py +40 -0
  98. biomarkit-1.0.0/tests/text_download/apis/clients/test_taylor_and_francis.py +58 -0
  99. biomarkit-1.0.0/tests/text_download/apis/clients/test_wiley.py +100 -0
  100. biomarkit-1.0.0/tests/text_download/apis/test_router.py +303 -0
  101. biomarkit-1.0.0/tests/text_download/basemodels/__init__.py +0 -0
  102. biomarkit-1.0.0/tests/text_download/basemodels/test_publication.py +149 -0
  103. biomarkit-1.0.0/tests/text_download/controller/__init__.py +0 -0
  104. biomarkit-1.0.0/tests/text_download/controller/test_controller.py +77 -0
  105. biomarkit-1.0.0/tests/text_download/database/__init__ +0 -0
  106. biomarkit-1.0.0/tests/text_download/database/test_database.py +91 -0
  107. biomarkit-1.0.0/tests/text_download/filter/test_filter_scopus_csv.py +50 -0
  108. biomarkit-1.0.0/tests/text_download/utils/__init__.py +0 -0
  109. biomarkit-1.0.0/tests/text_download/utils/test_generics.py +209 -0
  110. biomarkit-1.0.0/tests/text_transformation/__init__.py +0 -0
  111. biomarkit-1.0.0/tests/text_transformation/controller/__init__.py +0 -0
  112. biomarkit-1.0.0/tests/text_transformation/controller/test_controller.py +334 -0
  113. biomarkit-1.0.0/tests/text_transformation/converters/ABC/__init__.py +0 -0
  114. biomarkit-1.0.0/tests/text_transformation/converters/ABC/test_converter.py +215 -0
  115. biomarkit-1.0.0/tests/text_transformation/converters/__init__.py +0 -0
  116. biomarkit-1.0.0/tests/text_transformation/converters/test_elsevier2json.py +564 -0
  117. biomarkit-1.0.0/tests/text_transformation/converters/test_mineru_pdf_to_md.py +528 -0
  118. biomarkit-1.0.0/tests/text_transformation/generics/__init__.py +0 -0
  119. biomarkit-1.0.0/tests/text_transformation/utils/__init__.py +0 -0
  120. biomarkit-1.0.0/tests/text_transformation/utils/test_generics.py +312 -0
  121. biomarkit-1.0.0/tests/text_transformation/visualisation/__init__.py +0 -0
  122. biomarkit-1.0.0/tests/text_transformation/visualisation/test_conversion_report.py +215 -0
  123. biomarkit-1.0.0/uv.lock +2065 -0
@@ -0,0 +1,20 @@
1
+ __pycache__*
2
+ _data*
3
+ corpora/
4
+ .idea/
5
+ *.xml
6
+ htmlcov/
7
+ secrets.env
8
+ .coverage
9
+ *.sqlite
10
+ /logs
11
+ tmp/
12
+ .venv/
13
+ .pytest_cache/
14
+ .claude/
15
+ .worktrees/
16
+ llm_response.txt
17
+ text_download/apis/clients/am_phyto_soc.py
18
+ text_download/apis/clients/copernicus.py
19
+ evals/
20
+ download_results.xlsx
@@ -0,0 +1 @@
1
+ 3.12
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Jack Bruton
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,185 @@
1
+ Metadata-Version: 2.5
2
+ Name: biomarkit
3
+ Version: 1.0.0
4
+ Summary: Downloads full-text scientific publications from a Scopus query and converts them into standardised Markdown.
5
+ Author-email: Jack Bruton <jack.bruton@hotmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Jack Bruton
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ License-File: LICENSE
28
+ Requires-Python: <3.14,>=3.12
29
+ Requires-Dist: mineru[pipeline]>=3.4.0
30
+ Requires-Dist: openai>=1.0.0
31
+ Requires-Dist: pandas>=2.3.3
32
+ Requires-Dist: playwright>=1.56.0
33
+ Requires-Dist: plotly>=6.5.0
34
+ Requires-Dist: pydantic>=2.12.0
35
+ Requires-Dist: python-dotenv>=1.0.0
36
+ Requires-Dist: requests>=2.32.5
37
+ Requires-Dist: torch==2.9.1
38
+ Requires-Dist: torchvision==0.24.1
39
+ Requires-Dist: tqdm>=4.67.0
40
+ Requires-Dist: wiley-tdm>=1.0.0
41
+ Provides-Extra: dev
42
+ Requires-Dist: coverage>=7.11.0; extra == 'dev'
43
+ Requires-Dist: pytest>=8.4.2; extra == 'dev'
44
+ Description-Content-Type: text/markdown
45
+
46
+ # Biomarkit
47
+
48
+ A Python package for automated publisher-agnostic corpus download and structured Markdown file conversion
49
+ for full-text scientific publications.
50
+
51
+ ---
52
+
53
+ ## Overview
54
+ ### Full-text manuscript download from major publishers with `download_corpus()`.
55
+ Attempt download of full-text PDFs and XML files for all publications listed in a Scopus query CSV file by DOI.
56
+ Download is attempted first via open-access routes including arXiv, bioRxiv and Unpaywall. On failure, download is
57
+ attempted using specific publisher APIs including Elsevier, Wiley, Springer, MDPI, Frontiers.
58
+
59
+ **API keys are required for publishers that do not support fully automated text-mining**
60
+
61
+ ### Derive JSON manuscript structures from PDF and XML files with `transform_text()`.
62
+ Converts downloaded PDFs and XML files into a single, structured JSON format. XMLs are parsed directly, and PDFs are
63
+ converted locally via MinerU (GPU can be used here for performance improvements – See [MinerU](https://github.com/opendatalab/mineru)).
64
+ Captures other outputs including raw texts and figures.
65
+
66
+
67
+ ### Convert all manuscripts to a customisable Markdown format with `standardise_text()`.
68
+ Converts JSON-structured text into a standardised Markdown format. A single Markdown file is generated for each
69
+ document. Supports parameters for toggling inclusion of manuscript sections: figures, tables, references, and Latex
70
+ equations.
71
+
72
+ The "force_imrad_structure" parameter will force each output Markdown file to contain marked sections for "Introduction"
73
+ "Methods", "Results" and "Discussion" (can be omitted).
74
+
75
+ ---
76
+
77
+ ## Example:
78
+ ### Complete a full download and generate markdown files for each DOI in a given Scopus query:
79
+
80
+ ```python
81
+ import biomarkit
82
+
83
+ # Make a new corpus and set it as active (writes CORPUS_NAME to secrets.env)
84
+ biomarkit.build_new_corpus(name="my_corpus", scopus_file="path/to/scopus.csv", set_active=True)
85
+
86
+ # Attempt download for all DOIs:
87
+ publications = biomarkit.download_corpus(check_opensource=True, generate_report=True)
88
+
89
+ # Run OCR and XML parser to generate JSON document structures:
90
+ publications = biomarkit.transform_text(publications)
91
+
92
+ # Build final markdown files:
93
+ biomarkit.standardise_text(publications, keep_figures=False, keep_tables=True, keep_latex=True, force_imrad_structure=True)
94
+ ```
95
+
96
+ ### Publications as Python objects:
97
+ `Publication` Python objects are returned at each step and are useful for integrating the package within larger
98
+ Python workflows. For example, storing each publication as a Python object makes it easy to query metadata and filepaths:
99
+
100
+ ```python
101
+ import biomarkit
102
+
103
+ publications = biomarkit.download_corpus(check_opensource=True)
104
+
105
+ # Query metadata for all DOIs in the active corpus:
106
+ for pub in publications:
107
+ print(pub.doi,
108
+ pub.title,
109
+ pub.abstract,
110
+ pub.publisher,
111
+ pub.document_type,
112
+ pub.publication_filepath,
113
+ pub.final_md_filepath
114
+ )
115
+ ```
116
+
117
+ ---
118
+ ## Configuration
119
+
120
+ ### Workspace directory
121
+
122
+ By default, biomarkit creates a `corpora/` folder in your **current working directory**. To use a different location, set the `BIOMARKIT_DIR` environment variable before running:
123
+
124
+ ```bash
125
+ # Linux/macOS
126
+ export BIOMARKIT_DIR=/path/to/my/workspace
127
+
128
+ # Windows (PowerShell)
129
+ $env:BIOMARKIT_DIR = "C:\path\to\my\workspace"
130
+ ```
131
+
132
+ Biomarkit also looks for `secrets.env` inside this directory.
133
+
134
+ ### API keys and settings
135
+
136
+ All user-facing settings live in `secrets.env` (copy from [`secrets.env.example`](secrets.env.example) and place it in your workspace directory):
137
+
138
+ | Setting | Description |
139
+ |---|---|
140
+ | `CORPUS_NAME` | Name of the active corpus folder under `corpora/` |
141
+ | `USER_EMAIL` | Your email address (required by some publisher APIs) |
142
+ | `WILEY_TDM_TOKEN` | Wiley TDM API token (optional) |
143
+ | `SPRINGER_API_KEY` | Springer API key (optional) |
144
+ | `ELSEVIER_API_KEY` | Elsevier API key (optional) |
145
+ | `LLM_BASE_URL` | OpenAI-compatible endpoint for the fallback section classifier (defaults to local [Ollama](https://ollama.com)) |
146
+ | `LLM_MODEL_NAME` | Model used by the fallback classifier (default `gemma3:12b`) |
147
+
148
+ ### The corpus folder structure
149
+
150
+ All inputs and outputs for a Scopus query live under `corpora/<corpus_name>/` inside your workspace directory. The active corpus is selected by setting `CORPUS_NAME` in `secrets.env`. Each corpus folder has the following structure:
151
+
152
+ ```
153
+ corpora/
154
+ └── <corpus_name>/
155
+ ├── scopus.csv # Scopus query export (input)
156
+ ├── manuscripts/ # Downloaded full-text PDFs/XMLs — output of `download_corpus()`
157
+ ├── intermediates/ # MinerU output files and JSON structures — output of `transform_text()`
158
+ ├── results/ # Final standardised Markdown files — output of `standardise_text()`
159
+ ├── reports/ # All HTML output reports
160
+ ├── logs/ # Run logs
161
+ └── sqlite.db # SQLite cache for this corpus
162
+ ```
163
+ Everything except `scopus.csv` is created automatically. Create a new corpus with `build_new_corpus(name="my_corpus", scopus_file="path/to/scopus.csv")`.
164
+
165
+ ---
166
+
167
+ ## Dependencies
168
+ - Python 3.12–3.13:
169
+ - Optional: A CUDA-capable GPU (big speedup for PDF conversion via MinerU) + `torch` (CUDA 12.8)
170
+ - Optional: [Ollama](https://ollama.com/download) running `gemma3:12b` (~8 GB), used as an LLM fallback to classify
171
+ ambiguous section headings. Without it, the pipeline runs, but accuracy in removing paper boilerplate is decreased.
172
+
173
+ Core dependencies: `pandas`, `pydantic`, `requests`, `playwright`, `plotly`, `openai`, `wiley-tdm`, `mineru[pipeline]`, `torch`
174
+
175
+ ## Installation
176
+ Install with [uv](https://github.com/astral-sh/uv):
177
+
178
+ ```bash
179
+ uv pip install biomarkit
180
+ ```
181
+
182
+ Or with pip:
183
+ ```python
184
+ pip install biomarkit
185
+ ```
@@ -0,0 +1,140 @@
1
+ # Biomarkit
2
+
3
+ A Python package for automated publisher-agnostic corpus download and structured Markdown file conversion
4
+ for full-text scientific publications.
5
+
6
+ ---
7
+
8
+ ## Overview
9
+ ### Full-text manuscript download from major publishers with `download_corpus()`.
10
+ Attempt download of full-text PDFs and XML files for all publications listed in a Scopus query CSV file by DOI.
11
+ Download is attempted first via open-access routes including arXiv, bioRxiv and Unpaywall. On failure, download is
12
+ attempted using specific publisher APIs including Elsevier, Wiley, Springer, MDPI, Frontiers.
13
+
14
+ **API keys are required for publishers that do not support fully automated text-mining**
15
+
16
+ ### Derive JSON manuscript structures from PDF and XML files with `transform_text()`.
17
+ Converts downloaded PDFs and XML files into a single, structured JSON format. XMLs are parsed directly, and PDFs are
18
+ converted locally via MinerU (GPU can be used here for performance improvements – See [MinerU](https://github.com/opendatalab/mineru)).
19
+ Captures other outputs including raw texts and figures.
20
+
21
+
22
+ ### Convert all manuscripts to a customisable Markdown format with `standardise_text()`.
23
+ Converts JSON-structured text into a standardised Markdown format. A single Markdown file is generated for each
24
+ document. Supports parameters for toggling inclusion of manuscript sections: figures, tables, references, and Latex
25
+ equations.
26
+
27
+ The "force_imrad_structure" parameter will force each output Markdown file to contain marked sections for "Introduction"
28
+ "Methods", "Results" and "Discussion" (can be omitted).
29
+
30
+ ---
31
+
32
+ ## Example:
33
+ ### Complete a full download and generate markdown files for each DOI in a given Scopus query:
34
+
35
+ ```python
36
+ import biomarkit
37
+
38
+ # Make a new corpus and set it as active (writes CORPUS_NAME to secrets.env)
39
+ biomarkit.build_new_corpus(name="my_corpus", scopus_file="path/to/scopus.csv", set_active=True)
40
+
41
+ # Attempt download for all DOIs:
42
+ publications = biomarkit.download_corpus(check_opensource=True, generate_report=True)
43
+
44
+ # Run OCR and XML parser to generate JSON document structures:
45
+ publications = biomarkit.transform_text(publications)
46
+
47
+ # Build final markdown files:
48
+ biomarkit.standardise_text(publications, keep_figures=False, keep_tables=True, keep_latex=True, force_imrad_structure=True)
49
+ ```
50
+
51
+ ### Publications as Python objects:
52
+ `Publication` Python objects are returned at each step and are useful for integrating the package within larger
53
+ Python workflows. For example, storing each publication as a Python object makes it easy to query metadata and filepaths:
54
+
55
+ ```python
56
+ import biomarkit
57
+
58
+ publications = biomarkit.download_corpus(check_opensource=True)
59
+
60
+ # Query metadata for all DOIs in the active corpus:
61
+ for pub in publications:
62
+ print(pub.doi,
63
+ pub.title,
64
+ pub.abstract,
65
+ pub.publisher,
66
+ pub.document_type,
67
+ pub.publication_filepath,
68
+ pub.final_md_filepath
69
+ )
70
+ ```
71
+
72
+ ---
73
+ ## Configuration
74
+
75
+ ### Workspace directory
76
+
77
+ By default, biomarkit creates a `corpora/` folder in your **current working directory**. To use a different location, set the `BIOMARKIT_DIR` environment variable before running:
78
+
79
+ ```bash
80
+ # Linux/macOS
81
+ export BIOMARKIT_DIR=/path/to/my/workspace
82
+
83
+ # Windows (PowerShell)
84
+ $env:BIOMARKIT_DIR = "C:\path\to\my\workspace"
85
+ ```
86
+
87
+ Biomarkit also looks for `secrets.env` inside this directory.
88
+
89
+ ### API keys and settings
90
+
91
+ All user-facing settings live in `secrets.env` (copy from [`secrets.env.example`](secrets.env.example) and place it in your workspace directory):
92
+
93
+ | Setting | Description |
94
+ |---|---|
95
+ | `CORPUS_NAME` | Name of the active corpus folder under `corpora/` |
96
+ | `USER_EMAIL` | Your email address (required by some publisher APIs) |
97
+ | `WILEY_TDM_TOKEN` | Wiley TDM API token (optional) |
98
+ | `SPRINGER_API_KEY` | Springer API key (optional) |
99
+ | `ELSEVIER_API_KEY` | Elsevier API key (optional) |
100
+ | `LLM_BASE_URL` | OpenAI-compatible endpoint for the fallback section classifier (defaults to local [Ollama](https://ollama.com)) |
101
+ | `LLM_MODEL_NAME` | Model used by the fallback classifier (default `gemma3:12b`) |
102
+
103
+ ### The corpus folder structure
104
+
105
+ All inputs and outputs for a Scopus query live under `corpora/<corpus_name>/` inside your workspace directory. The active corpus is selected by setting `CORPUS_NAME` in `secrets.env`. Each corpus folder has the following structure:
106
+
107
+ ```
108
+ corpora/
109
+ └── <corpus_name>/
110
+ ├── scopus.csv # Scopus query export (input)
111
+ ├── manuscripts/ # Downloaded full-text PDFs/XMLs — output of `download_corpus()`
112
+ ├── intermediates/ # MinerU output files and JSON structures — output of `transform_text()`
113
+ ├── results/ # Final standardised Markdown files — output of `standardise_text()`
114
+ ├── reports/ # All HTML output reports
115
+ ├── logs/ # Run logs
116
+ └── sqlite.db # SQLite cache for this corpus
117
+ ```
118
+ Everything except `scopus.csv` is created automatically. Create a new corpus with `build_new_corpus(name="my_corpus", scopus_file="path/to/scopus.csv")`.
119
+
120
+ ---
121
+
122
+ ## Dependencies
123
+ - Python 3.12–3.13:
124
+ - Optional: A CUDA-capable GPU (big speedup for PDF conversion via MinerU) + `torch` (CUDA 12.8)
125
+ - Optional: [Ollama](https://ollama.com/download) running `gemma3:12b` (~8 GB), used as an LLM fallback to classify
126
+ ambiguous section headings. Without it, the pipeline runs, but accuracy in removing paper boilerplate is decreased.
127
+
128
+ Core dependencies: `pandas`, `pydantic`, `requests`, `playwright`, `plotly`, `openai`, `wiley-tdm`, `mineru[pipeline]`, `torch`
129
+
130
+ ## Installation
131
+ Install with [uv](https://github.com/astral-sh/uv):
132
+
133
+ ```bash
134
+ uv pip install biomarkit
135
+ ```
136
+
137
+ Or with pip:
138
+ ```python
139
+ pip install biomarkit
140
+ ```
@@ -0,0 +1,3 @@
1
+ from biomarkit.main import build_new_corpus, download_corpus, transform_text, standardise_text
2
+
3
+ __all__ = ["build_new_corpus", "download_corpus", "transform_text", "standardise_text"]
@@ -0,0 +1,85 @@
1
+ from pathlib import Path
2
+ from dotenv import load_dotenv
3
+ from os import getenv
4
+
5
+ # Workspace root: users set BIOMARKIT_DIR to their preferred storage location;
6
+ # falls back to the current working directory if unset.
7
+ BASE_DIR = Path(getenv("BIOMARKIT_DIR", ".")).resolve()
8
+
9
+ # Filepath for secrets.env — lives alongside the corpora in the workspace root.
10
+ SECRETS_FILE = BASE_DIR / "secrets.env"
11
+
12
+ # Load secrets before reading any values.
13
+ load_dotenv(dotenv_path=SECRETS_FILE)
14
+
15
+ # Corpus selection — set CORPUS_NAME in secrets.env to choose the active corpus.
16
+ CORPUS_NAME = getenv("CORPUS_NAME", "default")
17
+
18
+ # Corpus folder layout.
19
+ CORPORA_DIR = BASE_DIR / "corpora"
20
+ CORPUS_DIR = CORPORA_DIR / CORPUS_NAME
21
+ SCOPUS_INPUT_CSV_NAME = CORPUS_DIR / "scopus.csv"
22
+ DB_CACHE_FILE_NAME = CORPUS_DIR / "sqlite.db"
23
+ DOWNLOAD_DIR = CORPUS_DIR / "manuscripts"
24
+ JSON_STRUCT_DIR = CORPUS_DIR / "intermediates"
25
+ FINAL_MARKDOWN_DIR = CORPUS_DIR / "results"
26
+ REPORT_DIR = CORPUS_DIR / "reports"
27
+ LOG_DIR = CORPUS_DIR / "logs"
28
+
29
+ # Shared scratch space (not corpus-specific).
30
+ TMP_DIR = BASE_DIR / "tmp"
31
+
32
+ # Client Parameters.
33
+ USER_EMAIL = getenv("USER_EMAIL")
34
+ WILEY_TDM_TOKEN = getenv("WILEY_TDM_TOKEN")
35
+ SPRINGER_API_KEY = getenv("SPRINGER_API_KEY")
36
+ ELSEVIER_API_KEY = getenv("ELSEVIER_API_KEY")
37
+
38
+ # LLM Settings - fallback section classifier, served by a local Ollama instance by default.
39
+ # Any OpenAI-compatible endpoint can be substituted via secrets.env.
40
+ LLM_BASE_URL = getenv("LLM_BASE_URL", "http://localhost:11434/v1")
41
+ LLM_MODEL_NAME = getenv("LLM_MODEL_NAME", "gemma3:12b")
42
+
43
+ # MinerU settings (optional). Integer GB of GPU VRAM MinerU is allowed to budget for;
44
+ # overrides its auto-detection and raises inference batch sizes on larger GPUs.
45
+ # Set via secrets.env only if you know what you are doing; unset means auto-detect.
46
+ MINERU_VIRTUAL_VRAM_SIZE = getenv("MINERU_VIRTUAL_VRAM_SIZE")
47
+
48
+ # MinerU remote inference (optional). Both must be set in secrets.env when
49
+ # transform_text(mineru_endpoint="vllm") is used: the URL of a vLLM server hosting
50
+ # the MinerU VLM model, and the API key the server was started with.
51
+ MINERU_VLLM_ENDPOINT = getenv("MINERU_VLLM_ENDPOINT")
52
+ MINERU_API_KEY = getenv("MINERU_API_KEY")
53
+
54
+ # Program settings (don't touch these unless you know what you are doing).
55
+ MAX_THREADS = 10
56
+ PLOTLY_THEME = "plotly_white"
57
+
58
+ # MAPS.
59
+ API_URL_TO_NAME = {
60
+ # "opensource" is the open-source download client (preprint routes + Unpaywall fallback); its api_url is
61
+ # the Unpaywall endpoint. The "unpaywall" key is kept for clients that do their own Unpaywall lookups.
62
+ "opensource": "https://api.unpaywall.org/v2/",
63
+ "unpaywall": "https://api.unpaywall.org/v2/",
64
+ "wiley": "https://api.wiley.com/onlinelibrary/tdm/v1/",
65
+ "springer": "https://link.springer.com",
66
+ "elsevier": "https://api.elsevier.com/",
67
+ "mdpi": "https://www.mdpi.com",
68
+ "frontiers": "https://www.frontiersin.org/journals",
69
+ "american_phytopathological_society": "https://apsjournals.apsnet.org",
70
+ "taylor_and_francis": "https://www.tandfonline.com",
71
+ "copernicus": "https://www.copernicus.org"
72
+ }
73
+
74
+ API_KEY_TO_NAME = {
75
+ "opensource": "",
76
+ "unpaywall": "",
77
+ "wiley": WILEY_TDM_TOKEN,
78
+ "springer": SPRINGER_API_KEY,
79
+ "elsevier": ELSEVIER_API_KEY,
80
+ "mdpi": "",
81
+ "frontiers": "",
82
+ "american_phytopathological_society": "",
83
+ "taylor_and_francis": "",
84
+ "copernicus": ""
85
+ }