Skip to content

Commit

Permalink
pybliometrics-dev#351 Implementation of ScienceDirect ArticleEntitlement
Browse files Browse the repository at this point in the history
  • Loading branch information
nils-herrmann committed Dec 20, 2024
1 parent 3aba0a6 commit 630051e
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 1 deletion.
1 change: 1 addition & 0 deletions pybliometrics/sciencedirect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
from pybliometrics.sciencedirect.article_metadata import *
from pybliometrics.sciencedirect.sciencedirect_search import *
from pybliometrics.sciencedirect.subject_classifications import *
from pybliometrics.sciencedirect.article_entitlement import *
102 changes: 102 additions & 0 deletions pybliometrics/sciencedirect/article_entitlement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
"""Module for retrieving article entitlement information from ScienceDirect."""
from typing import Optional, Union

from pybliometrics.superclasses import Retrieval
from pybliometrics.utils import (
chained_get,
check_parameter_value,
detect_id_type,
VIEWS,
)


class ArticleEntitlement(Retrieval):
"""Class to retrieve the entitlement status for a document from ScienceDirect."""
@property
def status(self) -> Optional[str]:
"""Status of whether a document has been found"""
return self._json.get("@status")

@property
def identifier(self) -> Optional[str]:
"""Identifier of a document."""
return self._json.get("dc:identifier")

@property
def eid(self) -> Optional[str]:
"The eid of a document."
return self._json.get("eid")

@property
def entitled(self) -> Optional[str]:
"""Entitlement status of a document."""
return self._json.get("entitled")

@property
def link(self) -> Optional[str]:
"""ScienceDirect canonical URL."""
return chained_get(self._json, ['link', '@href'])

@property
def message(self) -> Optional[str]:
"""Entitlement status message."""
return self._json.get("message")

@property
def pii(self) -> Optional[str]:
"""The pii of a document."""
return self._json.get("pii")

@property
def pii_norm(self) -> Optional[str]:
"""The pii-norm of a document."""
return self._json.get("pii-norm")

@property
def doi(self) -> Optional[str]:
"""The doi of a document."""
return self._json.get("prism:doi")

@property
def pubmed_id(self) -> Optional[str]:
"""The pubmed_id of a document (when used in the request)."""
return self._json.get("pubmed_id")

@property
def url(self) -> Optional[str]:
"""API url used to check entitlement."""
return self._json.get("prism:url")


@property
def scopus_id(self) -> Optional[str]:
"""The scopus_id of a document (when used in the request)."""
return self._json.get("scopus_id")

def __init__(self,
identifier: Union[int, str],
view: str = "FULL",
id_type: Optional[str] = None,
refresh: Union[bool, int] = False,
**kwds: str) -> None:

# Checks
identifier = str(identifier)
check_parameter_value(view, VIEWS["ArticleEntitlement"], "view")
if not id_type:
id_type = detect_id_type(identifier)
else:
allowed_id_types = ("eid", "pii", "scopus_id", "pubmed_id", "doi", "pui")
check_parameter_value(id_type, allowed_id_types, "id_type")

self._view = view
self._refresh = refresh

Retrieval.__init__(self, identifier=identifier, id_type=id_type, **kwds)

self._json = chained_get(self._json, ["entitlement-response", "document-entitlement"])

def __str__(self) -> str:
s = self.message
s += f' with doi: {self.doi}'
return s
29 changes: 29 additions & 0 deletions pybliometrics/sciencedirect/tests/test_ArticleEntitlement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Tests for sciencedirect.ArticleEntitlement"""
from pybliometrics.sciencedirect import ArticleEntitlement, init

init()

ae_1 = ArticleEntitlement('10.1016/j.reseneeco.2015.06.001', view='FULL', id_type='doi', refresh=30)
ae_2 = ArticleEntitlement('S0140988320302814', view='FULL', refresh=30)


def test_all_fields():
"""Test all propoerties of ArticleEntitlement."""
assert ae_1.doi == '10.1016/j.reseneeco.2015.06.001'
assert ae_1.eid == '1-s2.0-S092876551500038X'
assert ae_1.entitled is True
assert ae_1.identifier == 'http://dx.doi.org/10.1016/j.reseneeco.2015.06.001'
assert ae_1.link == 'https://www.sciencedirect.com/science/article/pii/S092876551500038X'
assert ae_1.message == 'Requestor is entitled to the requested resource'
assert ae_1.pii == 'S0928-7655(15)00038-X'
assert ae_1.pii_norm == 'S092876551500038X'
assert ae_1.pubmed_id is None
assert ae_1.scopus_id == '84935028440'
assert ae_1.status == 'found'
assert ae_1.url == 'https://api.elsevier.com/content/article/pii/S092876551500038X'


def test_str():
"""Test print message."""
expected_str = 'Requestor is entitled to the requested resource with doi: 10.1016/j.eneco.2020.104941'
assert ae_2.__str__() == expected_str
2 changes: 1 addition & 1 deletion pybliometrics/superclasses/retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self,
api = self.__class__.__name__
# Construct URL and cache file name
url = URLS[api]
if api in ("AbstractRetrieval", "PlumXMetrics", "ArticleRetrieval"):
if api in ("AbstractRetrieval", "PlumXMetrics", "ArticleRetrieval", "ArticleEntitlement"):
url += id_type + "/"
if api == 'CitationOverview':
stem = identifier.replace("/", "")
Expand Down
4 changes: 4 additions & 0 deletions pybliometrics/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
'SerialTitle': BASE_PATH_SCOPUS / 'serial_title',
'PlumXMetrics': BASE_PATH_SCOPUS / 'plumx',
'SubjectClassifications': BASE_PATH_SCOPUS / 'subject_classification',
'ArticleEntitlement': BASE_PATH_SCIENCEDIRECT / 'article_entitlement',
'ArticleMetadata': BASE_PATH_SCIENCEDIRECT / 'article_metadata / ',
'ArticleRetrieval': BASE_PATH_SCIENCEDIRECT / 'article_retrieval',
'ScienceDirectSearch': BASE_PATH_SCIENCEDIRECT / 'science_direct_search',
Expand All @@ -52,6 +53,7 @@
'SerialTitle': RETRIEVAL_BASE + 'serial/title/issn/',
'SubjectClassifications': RETRIEVAL_BASE + 'subject/scopus',
'PlumXMetrics': 'https://api.elsevier.com/analytics/plumx/',
'ArticleEntitlement': RETRIEVAL_BASE + 'article/entitlement/',
'ArticleMetadata': RETRIEVAL_BASE + 'metadata/article/',
'ArticleRetrieval': RETRIEVAL_BASE + 'article/',
'ScienceDirectSearch': SEARCH_BASE + 'sciencedirect/',
Expand All @@ -71,6 +73,7 @@
"SerialSearch": ["STANDARD", "ENHANCED", "CITESCORE"],
"SerialTitle": ["STANDARD", "ENHANCED", "CITESCORE"],
"SubjectClassifications": [''],
"ArticleEntitlement": ["FULL"],
"ArticleRetrieval": ["META", "META_ABS", "META_ABS_REF", "FULL", "ENTITLED"],
"ArticleMetadata": ["STANDARD", "COMPLETE"],
"ScienceDirectSearch": ["STANDARD"],
Expand All @@ -90,6 +93,7 @@
'SerialTitle': 6,
'PlumXMetrics': 6,
'SubjectClassifications': 0,
'ArticleEntitlement': 0,
'ArticleMetadata': 6,
'ArticleRetrieval': 10,
'ScienceDirectSearch': 2,
Expand Down

0 comments on commit 630051e

Please sign in to comment.