-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add BibTeX export for ScopusSearch #302
base: master
Are you sure you want to change the base?
Conversation
First implementation, might need some cleanup.
403e8a5
to
12b1e6e
Compare
type_conference_paper = "Conference Paper" | ||
type_conference_review = "Conference Review" | ||
type_article = "Article" | ||
type_review = "Review" | ||
type_short_survey = "Short Survey" | ||
type_editorial = "Editorial" | ||
type_note = "Note" | ||
type_letter = "Letter" | ||
type_data_paper = "Data Paper" | ||
type_erratum = "Erratum" | ||
type_book_chapter = "Book Chapter" | ||
type_book = "Book" | ||
type_report = "Report" | ||
type_retracted = "Retracted" | ||
type_none = None | ||
|
||
aggregation_type_conference_proceedings = "Conference Proceeding" | ||
aggregation_type_journal = "Journal" | ||
aggregation_type_trade_journal = "Trade Journal" | ||
aggregation_type_book_series = "Book Series" | ||
aggregation_type_book = "Book" | ||
aggregation_type_report = "Report" | ||
aggregation_type_none = None | ||
|
||
bib_tex_type_article = "Article" | ||
bib_tex_type_in_proceedings = "InProceedings" | ||
bib_tex_type_in_collection = "InCollection" | ||
bib_tex_type_book = "Book" | ||
bib_tex_type_techreport = "TechReport" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these variables just contain one string. Isn't it easier to just use the strings instead of the variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also possible. I chose this way to allow reuse, a better structure, making similar strings distinguishable (bib_tex vs. Scopus), and possibly in the future allowing modularity (for example by storing such strings in a different file).
But I'll adhere to the project's style for that!
if (document_type in [type_article, type_review, type_short_survey, type_editorial, type_note, type_letter, type_data_paper, type_erratum, type_conference_review, type_conference_paper, type_retracted, type_none] and aggregation_type == aggregation_type_journal) or (document_type in [type_article, type_review, type_short_survey, type_note] and aggregation_type == aggregation_type_trade_journal) or (document_type == type_article and aggregation_type == aggregation_type_none): | ||
bib_tex_type = bib_tex_type_article | ||
if aggregation_type == aggregation_type_conference_proceedings or (document_type == type_conference_paper and aggregation_type in [aggregation_type_book, aggregation_type_none]): | ||
bib_tex_type = bib_tex_type_in_proceedings | ||
elif aggregation_type == aggregation_type_book_series or (document_type in [type_book_chapter, type_article, type_editorial] and aggregation_type == aggregation_type_book): | ||
bib_tex_type = bib_tex_type_in_collection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be more readable to define suitable doctypes as a set beforehand:
in_collection = {"ed", "ar", "ch"}
etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mh, you mean only for the subcheck document_type in [...]
?
fields = self.add_bibtex_field(fields, "author", authors) | ||
fields = self.add_bibtex_field(fields, "title", result.title) | ||
fields = self.add_bibtex_field(fields, "date", result.coverDate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you turn this and the following statements into a loop of tuples?
[("author", authors), ("title", result.title), ...]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if I recall this correctly, but I might have followed the style of the other existing bibtex export function in pybliometrics.
The problem with putting this in a loop is that there are some fields depending on checks. So the list would then need to be constructed in a similar manner, not making the code much shorter. Still probable makes sense to eliminate a bit of duplication!
bib_library.add(entry) | ||
|
||
# Check whether the addition was successful or resulted in a duplicate block that needs fixing. | ||
for i in range(26): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does the 26 come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i is later used for shifting letters from a to z.
# Check whether the addition was successful or resulted in a duplicate block that needs fixing. | ||
for i in range(26): | ||
failed_blocks = bib_library.failed_blocks | ||
if failed_blocks: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What exactly is happening here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The used python library has problems adding a new entry if the key already exists in the library. So if there is already "@author" in the library, no other entry with @Book{Author, ...}
can be added. Then, the addition will result in a failed block. This checks whether the addition failed. If so, we try to add the entry as @Book{Authora, ...}
instead. If that fails, it will just move through the alphabet until it reaches @Book{Authorz, ...}
. Not ideal, but this is mainly dealing with shortcomings of the used library...
9cfdac3
to
9d182fa
Compare
Dear @claell , do we want to continue here? I very much appreciate your effort and willingness to improve pybliometrics, but I do not understand all the code. And here and there we are able to improve the code, which helps other users because of clarity and transparency. |
Ah, I guess your review wasn't seen by me, before. I'll add some comments! |
First implementation, might need some cleanup.
I thought, I will already start the PR, so feedback can be given.
Fixes #295