Skip to content

Commit d714281

Browse files
Siedlerchrcalixtuskopporsubhramit
authored
Pubmed api key support (#13899)
* fix git modules requires and uses * add pubmed api url * test * Support Medline APi Key * Support Medline APi Key * Support Medline APi Key * add default value and env variable * checkstyle * Typo * remove * add to fetchers * remove binaries * fix * Fix typo in decision document title * add a space --------- Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Co-authored-by: Oliver Kopp <kopp.dev@gmail.com> Co-authored-by: Subhramit Basu <subhramit.bb@live.in>
1 parent d1f33a9 commit d714281

File tree

11 files changed

+47
-9
lines changed

11 files changed

+47
-9
lines changed

.github/workflows/tests-code-fetchers.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ env:
3232
SpringerNatureAPIKey: ${{ secrets.SPRINGERNATUREAPIKEY_FOR_TESTS }}
3333
AstrophysicsDataSystemAPIKey: ${{ secrets.AstrophysicsDataSystemAPIKey_FOR_TESTS }}
3434
IEEEAPIKey: ${{ secrets.IEEEAPIKey_FOR_TESTS }}
35-
BiodiversityHeritageApiKey: ${{ secrets.BiodiversityHeritageApiKey_FOR_TESTS}}
35+
BiodiversityHeritageApiKey: ${{ secrets.BiodiversityHeritageApiKey_FOR_TESTS }}
36+
MedlineApiKey: ${{ secrets.MedlineApiKey_FOR_TESTS }}
3637

3738
concurrency:
3839
group: "${{ github.workflow }}-${{ github.head_ref || github.ref }}"

.github/workflows/tests-code.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ env:
1414
BiodiversityHeritageApiKey: ${{ secrets.BiodiversityHeritageApiKey_FOR_TESTS}}
1515
IEEEAPIKey: ${{ secrets.IEEEAPIKey_FOR_TESTS }}
1616
SpringerNatureAPIKey: ${{ secrets.SPRINGERNATUREAPIKEY_FOR_TESTS }}
17+
MedlineAPiKey: ${{ secrets.MedlineApiKey_FOR_TESTS }}
1718
GRADLE_OPTS: -Xmx4g
1819
JAVA_OPTS: -Xmx4g
1920

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
4040
- We added BibLaTeX datamodel validation support in order to improve error message quality in entries' fields validation. [#13318](https://github.com/JabRef/jabref/issues/13318)
4141
- We added more supported formats of CAYW endpoint of HTTP server. [#13578](https://github.com/JabRef/jabref/issues/13578)
4242
- We added chronological navigation for entries in each library. [#6352](https://github.com/JabRef/jabref/issues/6352)
43+
- We added support for using Medline/Pubmed fetcher with an API key. [#11296](https://github.com/JabRef/jabref/issues/11296#issuecomment-3289005011)
4344

4445
### Changed
4546

docs/code-howtos/fetchers.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ Fetchers are the implementation of the [search using online services](https://do
77

88
| Service | Key Source | Environment Variable | Rate Limit |
99
|:--------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------|--------------------------------|----------------------------------|
10+
| [Biodiversity Heritage Library](https://www.biodiversitylibrary.org/) | [Biodiversitylibrary](https://about.biodiversitylibrary.org/tools-and-services/developer-and-data-tools/#APIs) | `BiodiversityHeritageApiKey` | - |
1011
| [IEEEXplore](https://docs.jabref.org/collect/import-using-online-bibliographic-database#ieeexplore) | [IEEE Xplore API portal](https://developer.ieee.org) | `IEEEAPIKey` | 200 calls/day |
12+
| [Medline/Pubmed](https://pubmed.ncbi.nlm.nih.gov/) | [NCBI User account](https://account.ncbi.nlm.nih.gov/settings/) | `medlineApiKey` | 10 requests/seconds |
1113
| [MathSciNet](http://www.ams.org/mathscinet) | (none) | (none) | Depending on the current network |
1214
| [SAO/NASA Astrophysics Data System](https://docs.jabref.org/collect/import-using-online-bibliographic-database#sao-nasa-astrophysics-data-system) | [ADS UI](https://ui.adsabs.harvard.edu/user/settings/token) | `AstrophysicsDataSystemAPIKey` | 5000 calls/day |
1315
| [ScienceDirect](https://www.sciencedirect.com) | | `ScienceDirectApiKey` | |
1416
| [SemanticScholar](https://www.semanticscholar.org/) | <https://www.semanticscholar.org/product/api#api-key-form> | `SemanticScholarApiKey` | |
15-
| [Springer Nature](https://docs.jabref.org/collect/import-using-online-bibliographic-database#springer) | [Springer Nature API Portal](https://dev.springernature.com). Use the "Meta API" API key. | `SpringerNatureAPIKey` | 5000 calls/day |
17+
| [Springer Nature](https://docs.jabref.org/collect/import-using-online-bibliographic-database#springer) | [Springer Nature API portal](https://dev.springernature.com). Use the "Meta API" API key. | `SpringerNatureAPIKey` | 5000 calls/day |
1618
| [Zentralblatt Math](https://www.zbmath.org) | (none) | (none) | Depending on the current network |
17-
| [Biodiversity Heritage Library](https://www.biodiversitylibrary.org/) | [Biodiversitylibrary](https://about.biodiversitylibrary.org/tools-and-services/developer-and-data-tools/#APIs) | `BiodiversityHeritageApiKey` | - |
1819

1920
"Depending on the current network" means that it depends on whether your request is routed through a network having paid access. For instance, some universities have subscriptions to MathSciNet.
2021

docs/decisions/0012-handle-different-bibEntry-formats-of-fetchers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ All fetchers (except IDFetchers) in JabRef return BibEntries when fetching entri
1010
Some fetchers directly receive BibTeX entries from their API, the other fetchers receive their entries in some kind of exchange format such as JSON or XML and then parse this into BibEntries.
1111
Currently, all fetchers either return BibEntries in BibTeX or BibLaTeX format.
1212
This can lead to importing BibEntries of one format in a database of the other format.
13-
How can this inconsistency between fetchers, and their used formats be addressed?
13+
How can this inconsistency between fetchers and their used formats be addressed?
1414

1515
## Considered Options
1616

jablib/build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ val ieeeAPIKey = providers.environmentVariable("IEEEAPIKey").orElse("")
352352
val scienceDirectApiKey = providers.environmentVariable("SCIENCEDIRECTAPIKEY").orElse("")
353353
val biodiversityHeritageApiKey = providers.environmentVariable("BiodiversityHeritageApiKey").orElse("")
354354
val semanticScholarApiKey = providers.environmentVariable("SemanticScholarApiKey").orElse("")
355+
val medlineApiKey = providers.environmentVariable("MedlineApiKey").orElse("")
355356

356357
tasks.named<ProcessResources>("processResources") {
357358
dependsOn(extractMaintainers)
@@ -370,6 +371,7 @@ tasks.named<ProcessResources>("processResources") {
370371
inputs.property("scienceDirectApiKey", scienceDirectApiKey)
371372
inputs.property("biodiversityHeritageApiKey", biodiversityHeritageApiKey)
372373
inputs.property("semanticScholarApiKey", semanticScholarApiKey)
374+
inputs.property("medlineApiKey", medlineApiKey)
373375

374376
filesMatching("build.properties") {
375377
expand(
@@ -383,7 +385,8 @@ tasks.named<ProcessResources>("processResources") {
383385
"ieeeAPIKey" to inputs.properties["ieeeAPIKey"],
384386
"scienceDirectApiKey" to inputs.properties["scienceDirectApiKey"],
385387
"biodiversityHeritageApiKey" to inputs.properties["biodiversityHeritageApiKey"],
386-
"semanticScholarApiKey" to inputs.properties["semanticScholarApiKey"]
388+
"semanticScholarApiKey" to inputs.properties["semanticScholarApiKey"],
389+
"medlineApiKey" to inputs.properties["medlineApiKey"]
387390
)
388391
)
389392
}

jablib/src/main/java/org/jabref/logic/importer/WebFetchers.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public static SortedSet<SearchBasedFetcher> getSearchBasedFetchers(ImportFormatP
112112
set.add(new INSPIREFetcher(importFormatPreferences));
113113
set.add(new GvkFetcher(importFormatPreferences));
114114
set.add(new BvbFetcher());
115-
set.add(new MedlineFetcher());
115+
set.add(new MedlineFetcher(importerPreferences));
116116
set.add(new AstrophysicsDataSystem(importFormatPreferences, importerPreferences));
117117
set.add(new MathSciNet(importFormatPreferences));
118118
set.add(new ZbMATH(importFormatPreferences));
@@ -150,7 +150,7 @@ public static SortedSet<IdBasedFetcher> getIdBasedFetchers(ImportFormatPreferenc
150150
set.add(new DiVA(importFormatPreferences));
151151
set.add(new DoiFetcher(importFormatPreferences));
152152
set.add(new EuropePmcFetcher());
153-
set.add(new MedlineFetcher());
153+
set.add(new MedlineFetcher(importerPreferences));
154154
set.add(new TitleFetcher(importFormatPreferences));
155155
set.add(new MathSciNet(importFormatPreferences));
156156
set.add(new ZbMATH(importFormatPreferences));
@@ -237,6 +237,7 @@ public static Set<CustomizableKeyFetcher> getCustomizableKeyFetchers(ImportForma
237237
fetchers.add(new ScienceDirect(importerPreferences));
238238
fetchers.add(new AstrophysicsDataSystem(importFormatPreferences, importerPreferences));
239239
fetchers.add(new BiodiversityLibrary(importerPreferences));
240+
fetchers.add(new MedlineFetcher(importerPreferences));
240241
return fetchers;
241242
}
242243
}

jablib/src/main/java/org/jabref/logic/importer/fetcher/MedlineFetcher.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.jabref.logic.help.HelpFile;
2525
import org.jabref.logic.importer.FetcherException;
2626
import org.jabref.logic.importer.IdBasedParserFetcher;
27+
import org.jabref.logic.importer.ImporterPreferences;
2728
import org.jabref.logic.importer.Parser;
2829
import org.jabref.logic.importer.ParserResult;
2930
import org.jabref.logic.importer.SearchBasedFetcher;
@@ -44,15 +45,23 @@
4445
* The MedlineFetcher fetches the entries from the PubMed database.
4546
* See <a href="https://docs.jabref.org/collect/import-using-online-bibliographic-database#medline-pubmed">docs.jabref.org</a> for a detailed documentation of the available fields.
4647
*/
47-
public class MedlineFetcher implements IdBasedParserFetcher, SearchBasedFetcher {
48+
public class MedlineFetcher implements IdBasedParserFetcher, SearchBasedFetcher, CustomizableKeyFetcher {
49+
public static final String FETCHER_NAME = "Medline/PubMed";
50+
4851
private static final Logger LOGGER = LoggerFactory.getLogger(MedlineFetcher.class);
4952

5053
private static final int NUMBER_TO_FETCH = 50;
5154
private static final String ID_URL = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi";
5255
private static final String SEARCH_URL = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi";
56+
private static final String TEST_URL_WITHOUT_API_KEY = "https://www.ncbi.nlm.nih.gov/entrez/eutils/einfo.fcgi?db=pubmed&api_key=";
5357

58+
private final ImporterPreferences importerPreferences;
5459
private int numberOfResultsFound;
5560

61+
public MedlineFetcher(ImporterPreferences importerPreferences) {
62+
this.importerPreferences = importerPreferences;
63+
}
64+
5665
/**
5766
* When using 'esearch.fcgi?db=&lt;database>&term=&lt;query>' we will get a list of IDs matching the query.
5867
* Input: Any text query (&term)
@@ -130,6 +139,7 @@ public URL getUrlForIdentifier(String identifier) throws URISyntaxException, Mal
130139
uriBuilder.addParameter("db", "pubmed");
131140
uriBuilder.addParameter("retmode", "xml");
132141
uriBuilder.addParameter("id", identifier);
142+
importerPreferences.getApiKey(FETCHER_NAME).ifPresent(apiKey -> uriBuilder.addParameter("api_key", apiKey));
133143
return uriBuilder.build().toURL();
134144
}
135145

@@ -154,6 +164,7 @@ private URL createSearchUrl(String query) throws URISyntaxException, MalformedUR
154164
uriBuilder.addParameter("sort", "relevance");
155165
uriBuilder.addParameter("retmax", String.valueOf(NUMBER_TO_FETCH));
156166
uriBuilder.addParameter("term", query); // already lucene query
167+
importerPreferences.getApiKey(FETCHER_NAME).ifPresent(apiKey -> uriBuilder.addParameter("api_key", apiKey));
157168
return uriBuilder.build().toURL();
158169
}
159170

@@ -212,4 +223,9 @@ public List<BibEntry> performSearch(BaseQueryNode queryNode) throws FetcherExcep
212223
return entryList;
213224
}
214225
}
226+
227+
@Override
228+
public String getTestUrl() {
229+
return TEST_URL_WITHOUT_API_KEY;
230+
}
215231
}

jablib/src/main/java/org/jabref/logic/util/BuildInfo.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public final class BuildInfo {
4343
public final String scienceDirectApiKey;
4444
public final String semanticScholarApiKey;
4545
public final String springerNatureAPIKey;
46+
public final String medlineApiKey;
4647

4748
public BuildInfo() {
4849
this("/build.properties");
@@ -71,6 +72,7 @@ public BuildInfo(String path) {
7172
scienceDirectApiKey = BuildInfo.getValue(properties, "scienceDirectApiKey", "fb82f2e692b3c72dafe5f4f1fa0ac00b");
7273
semanticScholarApiKey = BuildInfo.getValue(properties, "semanticScholarApiKey", "");
7374
springerNatureAPIKey = BuildInfo.getValue(properties, "springerNatureAPIKey", "118d90a519d0fc2a01ee9715400054d4");
75+
medlineApiKey = BuildInfo.getValue(properties, "medlineApiKey", "");
7476
}
7577

7678
private static String getValue(Properties properties, String key, String defaultValue) {

jablib/src/main/resources/build.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ astrophysicsDataSystemAPIKey=${astrophysicsDataSystemAPIKey}
77
ieeeAPIKey=${ieeeAPIKey}
88
biodiversityHeritageApiKey=${biodiversityHeritageApiKey}
99
semanticScholarApiKey=${semanticScholarApiKey}
10+
medlineApiKey=${medlineApiKey}

0 commit comments

Comments
 (0)