Skip to content

Enabled abstract retrieval by different types of Scopus ID - #71

Merged
Michael-E-Rose merged 4 commits into
pybliometrics-dev:masterfrom
mbrcic:adding-general-ID-lookup
Oct 14, 2018
Merged

Enabled abstract retrieval by different types of Scopus ID#71
Michael-E-Rose merged 4 commits into
pybliometrics-dev:masterfrom
mbrcic:adding-general-ID-lookup

Conversation

@mbrcic

@mbrcic mbrcic commented Oct 8, 2018

Copy link
Copy Markdown
Contributor

I have generalized abstract retrieval by other types of ID, in addition to already supported EID. Abstracts can now also be retrieved by DOI, PII, PubMed ID, and Scopus ID. This generalization was necessary for my project.

@Michael-E-Rose

Copy link
Copy Markdown
Contributor

Hi @mbrcic, this is very cool, thanks! I did not know this was possible.
Do you think it is possible to avoid the ID_type parameter and let the code infer the ID type instead?

@mbrcic

mbrcic commented Oct 8, 2018

Copy link
Copy Markdown
Contributor Author

Hi @Michael-E-Rose ,

ID type auto-discovery is a good idea!

DOI and EID are easily distinguishable, as well as PII.
However, I am not totally sure for PubMed ID and Scopus ID as they are both numerical codes. All the Scopus IDs I have seen have 10 or 11 digits, with leading zeros. In fact, Scopus ID is the suffix of EID.
PubMed ID is a serial code currently at <=8 digits.

I've just added the auto-discovery into the code and it works great for my IDs of all types. It can be tweaked in future if there are better discriminators between Scopus ID and PubMed ID.

@mbrcic

mbrcic commented Oct 8, 2018

Copy link
Copy Markdown
Contributor Author

Just to add, I did not remove the ID_type parameter because I like to give users more flexibility. If ID_type is set to 'auto' (which is the default value), then the type is inferred from the ID. User can also manually specify the type of ID through the same parameter.

@Michael-E-Rose

Copy link
Copy Markdown
Contributor

Yes, that's probably a smart move. But rather than auto, the default value should be None. Could you change that, too, please? Some minor things I add in the code.

@Michael-E-Rose
Michael-E-Rose self-requested a review October 9, 2018 12:22
@mbrcic

mbrcic commented Oct 9, 2018

Copy link
Copy Markdown
Contributor Author

I've changed ID_type default value to None, it does make more sense.

Comment thread scopus/utils/__init__.py Outdated
from scopus.utils.get_content import *
from scopus.utils.get_encoded_text import *
from scopus.utils.startup import *
from scopus.utils.discover_id_type import * No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There needs to be a blank line after this

Comment thread scopus/abstract_retrieval.py Outdated
raise ValueError('ID_type parameter must be one of ' +
', '.join(allowed_id_types))

qfile = join(config.get('Directories', 'AbstractRetrieval'), EID.replace('/','_'))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the .replace('/','_')?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still open question

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is due to caching in function scopus.utils.get_content, line 85 which tries to create the file.

In Unix-based systems '/' is used as a path separator so it can't be used in file names. This is only a problem in the case of DOI, which always contains '/'.

@mbrcic mbrcic Oct 10, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though, I admit that replacement character '_' is kind-of arbitrarily chosen. And EID could be defensively casted to string when calling for replacement.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. That's why in the search classes we cache files with the hashed-version of the filename. I think the underscore is okay. Could you also update the note in the docstring, please?

Comment thread scopus/abstract_retrieval.py Outdated

ID_type: str (optional, default=auto)
The overload type of used ID. On Scopus it can be one of
{'eid','pii','scopus_id','pubmed_id','doi'}. If using option

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No set nottation, please.

Comment thread scopus/abstract_retrieval.py
Comment thread scopus/abstract_retrieval.py Outdated
from scopus import config
from scopus.utils import get_content

from scopus.utils import discover_id_type

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be merged with above line: from scopus.utils import discover_id_type, get_content

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one still needs to be adressed

Comment thread scopus/utils/discover_id_type.py Outdated
cases with only 16 for old converted articles.

"""
if ID.startswith('2-s2.0-'):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will run into AttributeErrors when ID is already numeric. You should write str(ID).startswith('2-s2.0-')

@mbrcic mbrcic Oct 10, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the conditional statements in this function lean on the assumption that ID is string. It is probably best to defensively cast it to string at the beginning of the function.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, or even before that, in __init__. Because in the case of pubmed or scopus ID, users can supply an integer rather than a string.

@mbrcic mbrcic Oct 11, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it is true that both pubmed and scopus IDs contain only digits, I have come across scopus IDs with leading zeros. If interpreting or supplying them as integers with leading zeros, it will change the token interpretation and that renders the ID invalid. Namely, leading zeros in python 2 force interpretation as an octal number, if possible. Python 3 does not allow leading zeros in numbers and raises SyntaxError. The scopus ID supplied as a number with manually omitted leading zeros is an invalid resource identifier.
So I would say that scopus ID is a string consisting only of digits. You can try it out on the following 10-digit scopus ID:
https://api.elsevier.com/content/abstract/scopus_id/0028981867

Pubmed ID is simply a number which can be supplied as such.

I have put this in the notes of detect_id_type function. And I have casted IDs to strings in both functions.

Comment thread scopus/utils/discover_id_type.py Outdated
@Michael-E-Rose

Copy link
Copy Markdown
Contributor

Thanks, it's getting there! There are few open things however. When you have addressed them, I merge the PR.

@Michael-E-Rose
Michael-E-Rose force-pushed the master branch 2 times, most recently from 1fbc71a to 8bb8035 Compare October 11, 2018 15:39
@Michael-E-Rose
Michael-E-Rose merged commit d53a8d0 into pybliometrics-dev:master Oct 14, 2018
@Michael-E-Rose

Copy link
Copy Markdown
Contributor

Thanks a lot for this work, @mbrcic! I just merged the PR. Somewhen next week I will make this live with scopus 1.2. There's one other minor thing in another class I want to address.

@mbrcic
mbrcic deleted the adding-general-ID-lookup branch October 14, 2018 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants