pybliometrics.sciencedirect.ObjectRetrieval¶
ObjectRetrieval() retrieves objects in a document using the ScienceDirect Object Retrieval API. All components of a Document that are not text (figures, formulas, etc.) are called objects.
Documentation¶
- class pybliometrics.sciencedirect.ObjectRetrieval(identifier, filename, id_type=None, refresh=False, **kwds)[source]¶
Class to retrieve a specific object of a document by its filename.
- Parameters:
identifier (
int|str) – The indentifier of the document.filename (
str) – Filename of the object to be retrieved. To get a list of all available objects of a document (and its corresponding filename) use the class ObjectMetadata.id_type (
str|None, optional) – Document identifier. Allowed values: doi, pii, scopus_id, pubmed_id, eid.Default:Nonerefresh (
bool|int, optional) – Whether to refresh the cached file if it exists. Default: False.Default:Falsekwds (str)
- property object: BytesIO¶
The object retrieved.
- get_cache_file_age()¶
Return the age of the cached file in days.
- Return type:
int
- get_cache_file_mdate()¶
Return the modification date of the cached file.
- Return type:
str
- get_key_remaining_quota()¶
Return number of remaining requests for the current key and the current API (relative on last actual request).
- Return type:
str | None
- get_key_reset_time()¶
Return time when current key is reset (relative on last actual request).
- Return type:
str | None
Examples¶
Objects are uniquely identified by the document id and the object filename. To get the filename of an object you use the ObjectMetadata class. Let’s start by retrieving all object’s filenames:
>>> from PIL import Image >>> from pybliometrics.sciencedirect import init, ObjectMetadata, ObjectRetrieval >>> init() >>> # Get all objects and its filenames >>> om = ObjectMetadata('10.1016/j.rcim.2020.102086') >>> all_filenames = [f.filename for f in om.results] >>> all_filenames ['gr13.jpg', 'gr9.jpg', 'gr12.jpg', ..., 'si98.svg', 'si99.svg', 'am.pdf']
In the following example, we retrieve the third object in the list (gr12.jpg), and display it using PIL:
>>> obj_ret = ObjectRetrieval('10.1016/j.rcim.2020.102086', all_filenames[2]) >>> # Access object using the 'object' property and display using PIL >>> img = Image.open(obj_ret.object) >>>> img.show()