Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

claell
Copy link

@claell claell commented Oct 17, 2023

First implementation, might need some cleanup.

I thought, I will already start the PR, so feedback can be given.

Fixes #295

First implementation, might need some cleanup.
@Michael-E-Rose Michael-E-Rose force-pushed the master branch 4 times, most recently from 403e8a5 to 12b1e6e Compare January 15, 2024 10:33
Comment on lines +227 to +255
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"
Copy link
Contributor

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?

Copy link
Author

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!

Comment on lines +308 to +313
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
Copy link
Contributor

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.

Copy link
Author

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 [...]?

Comment on lines +324 to +326
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)
Copy link
Contributor

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), ...]

Copy link
Author

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):
Copy link
Contributor

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?

Copy link
Author

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:
Copy link
Contributor

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?

Copy link
Author

@claell claell Dec 12, 2024

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...

@Michael-E-Rose Michael-E-Rose force-pushed the master branch 3 times, most recently from 9cfdac3 to 9d182fa Compare November 14, 2024 15:45
@Michael-E-Rose
Copy link
Contributor

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.

@claell
Copy link
Author

claell commented Dec 12, 2024

Ah, I guess your review wasn't seen by me, before. I'll add some comments!

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.

Add proper export (to bibtex)
2 participants