Verified Owner
Top Description Fields Constructors Methods
org.jabref.logic.importer.fetcher

public Class MedlineFetcher

extends Object
implements IdBasedParserFetcher, SearchBasedFetcher, CustomizableKeyFetcher
Class Inheritance
All Implemented Interfaces
org.jabref.logic.importer.fetcher.CustomizableKeyFetcher, org.jabref.logic.importer.WebFetcher, org.jabref.logic.importer.SearchBasedFetcher, org.jabref.logic.importer.IdBasedParserFetcher, org.jabref.logic.importer.ParserFetcher, org.jabref.logic.importer.IdBasedFetcher
Imports
java.io.BufferedReader, .IOException, .InputStreamReader, java.net.HttpURLConnection, .MalformedURLException, .URISyntaxException, .URL, .URLConnection, java.nio.charset.StandardCharsets, java.util.ArrayList, .List, .Optional, javax.xml.stream.XMLInputFactory, .XMLStreamConstants, .XMLStreamException, .XMLStreamReader, org.jabref.logic.cleanup.FieldFormatterCleanup, org.jabref.logic.formatter.bibtexfields.ClearFormatter, .NormalizeMonthFormatter, .NormalizeNamesFormatter, org.jabref.logic.help.HelpFile, org.jabref.logic.importer.FetcherException, .IdBasedParserFetcher, .ImporterPreferences, .Parser, .ParserResult, .SearchBasedFetcher, org.jabref.logic.importer.fetcher.transformers.MedlineQueryTransformer, org.jabref.logic.importer.fileformat.MedlineImporter, org.jabref.logic.l10n.Localization, org.jabref.logic.net.URLDownload, org.jabref.model.entry.BibEntry, org.jabref.model.entry.field.StandardField, .UnknownField, org.jabref.model.search.query.BaseQueryNode, kong.unirest.core.UnirestException, org.apache.hc.core5.net.URIBuilder, org.jspecify.annotations.NonNull, org.slf4j.Logger, .LoggerFactory

Fetch or search from PubMed www.ncbi.nlm.nih.gov The MedlineFetcher fetches the entries from the PubMed database. See docs.jabref.org for a detailed documentation of the available fields.

Field Summary

Modifier and TypeField and Description
public static final String
private static final String
private final ImporterPreferences
private static final Logger
private static final int
private int
private static final String

Constructor Summary

AccessConstructor and Description
public
MedlineFetcher(ImporterPreferences importerPreferences)

Method Summary

Modifier and TypeMethod and Description
private URL
public void
doPostCleanup(BibEntry entry)

Overrides default org.jabref.logic.importer.ParserFetcher.doPostCleanup.

Performs a cleanup of the fetched entry.

private List<BibEntry>

Returns:

Will return an empty list on error.
fetchMedline
(List<String>
A list of IDs to search for.
ids
)

Fetch and parse an medline item from eutils.ncbi.nlm.nih.gov.

public @NonNull Optional<HelpFile>
getHelpPage()

Overrides default org.jabref.logic.importer.WebFetcher.getHelpPage.

Returns the help page for this fetcher.

public String
getName()

Implements org.jabref.logic.importer.WebFetcher.getName.

Returns the localized name of this fetcher.

public Parser
getParser()

Implements org.jabref.logic.importer.IdBasedParserFetcher.getParser.

Returns the parser used to convert the response to a list of BibEntry.

private List<String>
getPubMedIdsFromQuery(String query)

When using 'esearch.fcgi?db=<database>&term=<query>' we will get a list of IDs matching the query.

private String
public URL
getUrlForIdentifier(String identifier)

Implements org.jabref.logic.importer.IdBasedParserFetcher.getUrlForIdentifier.

Constructs a URL based on the query.

public boolean
isValidKey(@NonNull String apiKey)

Overrides default org.jabref.logic.importer.fetcher.CustomizableKeyFetcher.isValidKey.

Returns whether the API key is valid

public @NonNull List<BibEntry>
performRawSearchQuery(@NonNull String rawQuery)

Overrides default org.jabref.logic.importer.SearchBasedFetcher.performRawSearchQuery.

The raw query is sent as the term parameter of PubMed's esearch API (see SEARCH_URL)

public @NonNull List<BibEntry>
performSearch(@NonNull BaseQueryNode queryNode)

Implements org.jabref.logic.importer.SearchBasedFetcher.performSearch.

This method is used to send complex queries using fielded search.

private List<BibEntry>
searchForEntries(String query)

Searches PubMed for IDs matching the query, then fetches the corresponding entries

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

FETCHER_NAMEback to summary
public static final String FETCHER_NAME
ID_URLback to summary
private static final String ID_URL
importerPreferencesback to summary
private final ImporterPreferences importerPreferences
LOGGERback to summary
private static final Logger LOGGER

Hides org.jabref.logic.importer.IdBasedParserFetcher.LOGGER.

NUMBER_TO_FETCHback to summary
private static final int NUMBER_TO_FETCH
numberOfResultsFoundback to summary
private int numberOfResultsFound
SEARCH_URLback to summary
private static final String SEARCH_URL

Constructor Detail

MedlineFetcherback to summary
public MedlineFetcher(ImporterPreferences importerPreferences)

Method Detail

createSearchUrlback to summary
private URL createSearchUrl(String query) throws URISyntaxException, MalformedURLException
doPostCleanupback to summary
public void doPostCleanup(BibEntry entry)

Overrides default org.jabref.logic.importer.ParserFetcher.doPostCleanup.

Doc from org.jabref.logic.importer.ParserFetcher.doPostCleanup.

Performs a cleanup of the fetched entry.

Only systematic errors of the fetcher should be corrected here (i.e. if information is consistently contained in the wrong field or the wrong format) but not cosmetic issues which may depend on the user's taste (for example, LateX code vs HTML in the abstract).

Try to reuse existing org.jabref.logic.formatter.Formatter for the cleanup. For example, new FieldFormatterCleanup(StandardField.TITLE, new RemoveBracesFormatter()).cleanup(entry);

By default, no cleanup is done.

Annotations
@Override
fetchMedlineback to summary
private List<BibEntry> fetchMedline(List<String> ids) throws FetcherException

Fetch and parse an medline item from eutils.ncbi.nlm.nih.gov. The E-utilities generate a huge XML file containing all entries for the ids

Parameters
ids:List<String>

A list of IDs to search for.

Returns:List<BibEntry>

Will return an empty list on error.

getHelpPageback to summary
public @NonNull Optional<HelpFile> getHelpPage()

Overrides default org.jabref.logic.importer.WebFetcher.getHelpPage.

Doc from org.jabref.logic.importer.WebFetcher.getHelpPage.

Returns the help page for this fetcher.

Annotations
@Override
getNameback to summary
public String getName()

Implements org.jabref.logic.importer.WebFetcher.getName.

Doc from org.jabref.logic.importer.WebFetcher.getName.

Returns the localized name of this fetcher. The title can be used to display the fetcher in the menu and in the side pane.

Todo

This name is also used for identifying the fetcher in preferences for API keys. Thus, any switch of the language will "remove" API keys.

Annotations
@Override
getParserback to summary
public Parser getParser()

Implements org.jabref.logic.importer.IdBasedParserFetcher.getParser.

Doc from org.jabref.logic.importer.IdBasedParserFetcher.getParser.

Returns the parser used to convert the response to a list of BibEntry.

Annotations
@Override
getPubMedIdsFromQueryback to summary
private List<String> getPubMedIdsFromQuery(String query) throws FetcherException

When using 'esearch.fcgi?db=<database>&term=<query>' we will get a list of IDs matching the query. Input: Any text query (&term) Output: List of UIDs matching the query

See Also
www.ncbi.nlm.nih.gov/books/NBK25500/
getTestUrlback to summary
private String getTestUrl(String apiKey)
getUrlForIdentifierback to summary
public URL getUrlForIdentifier(String identifier) throws URISyntaxException, MalformedURLException

Implements org.jabref.logic.importer.IdBasedParserFetcher.getUrlForIdentifier.

Doc from org.jabref.logic.importer.IdBasedParserFetcher.getUrlForIdentifier.

Constructs a URL based on the query.

Annotations
@Override
isValidKeyback to summary
public boolean isValidKey(@NonNull String apiKey)

Overrides default org.jabref.logic.importer.fetcher.CustomizableKeyFetcher.isValidKey.

Doc from org.jabref.logic.importer.fetcher.CustomizableKeyFetcher.isValidKey.

Returns whether the API key is valid

Annotations
@Override
performRawSearchQueryback to summary
public @NonNull List<BibEntry> performRawSearchQuery(@NonNull String rawQuery) throws FetcherException

Overrides default org.jabref.logic.importer.SearchBasedFetcher.performRawSearchQuery.

The raw query is sent as the term parameter of PubMed's esearch API (see SEARCH_URL)

Annotations
@Override
performSearchback to summary
public @NonNull List<BibEntry> performSearch(@NonNull BaseQueryNode queryNode) throws FetcherException

Implements org.jabref.logic.importer.SearchBasedFetcher.performSearch.

Doc from org.jabref.logic.importer.SearchBasedFetcher.performSearch.

This method is used to send complex queries using fielded search.

Annotations
@Override
searchForEntriesback to summary
private List<BibEntry> searchForEntries(String query) throws FetcherException

Searches PubMed for IDs matching the query, then fetches the corresponding entries