-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 Cleanup for copying over physcial review article id as the page n… #7025
Changes from 1 commit
c9b5284
3856f25
342cacb
e69989a
1779e42
3704269
1853df7
983962f
a1fe707
593c86d
a1fdf3e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.jabref.logic.cleanup; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.jabref.model.FieldChange; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.field.StandardField; | ||
|
||
/** | ||
* adds the article ID of a journal as the page count, but only if the page field is empty | ||
*/ | ||
public class PageFieldCleanup implements CleanupJob { | ||
|
||
@Override | ||
public List<FieldChange> cleanup(BibEntry entry) { | ||
List<FieldChange> changes = new ArrayList<>(); | ||
Optional<String> doiAsString = entry.getField(StandardField.DOI); | ||
|
||
if (doiAsString.isPresent() && !entry.hasField(StandardField.PAGES)) { | ||
String articleId = new String(); | ||
int index = doiAsString.get().length() - 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would simply use a substring with lastIndexOf(.) to the the part after the last dot. |
||
while (Character.isDigit(doiAsString.get().charAt(index))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this issue only concerns articles from Physical Review, I would suggest to use a regex based on the format outlined in #7019 (comment). In particular, make sure it only applies to doi's to Physical Review, and not all dois ending on some number. |
||
articleId = doiAsString.get().charAt(index--) + articleId; | ||
} | ||
entry.setField(StandardField.PAGES, articleId); | ||
FieldChange change = new FieldChange(entry, StandardField.PAGES, "", articleId); | ||
changes.add(change); | ||
} | ||
|
||
return changes; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
import java.util.Optional; | ||
|
||
import org.jabref.logic.cleanup.FieldFormatterCleanup; | ||
import org.jabref.logic.cleanup.PageFieldCleanup; | ||
import org.jabref.logic.formatter.bibtexfields.ClearFormatter; | ||
import org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter; | ||
import org.jabref.logic.help.HelpFile; | ||
|
@@ -89,6 +90,7 @@ public Optional<BibEntry> performSearchById(String identifier) throws FetcherExc | |
} | ||
|
||
private void doPostCleanup(BibEntry entry) { | ||
new PageFieldCleanup().cleanup(entry); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a good idea to put it here, because it would be called for every type of DOI, and the APS are only a very specific subset. and also adding it to the Cleanup Dialog maybe as Move article id to pages? (APS). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do think it's the right place, the DOI fetcher is not returning the right/full information, so we improve this here. Of course, you are right and the extraction should only be applied for DOI's from APS (see my comment above). |
||
new FieldFormatterCleanup(StandardField.PAGES, new NormalizePagesFormatter()).cleanup(entry); | ||
new FieldFormatterCleanup(StandardField.URL, new ClearFormatter()).cleanup(entry); | ||
} | ||
|
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.
Since this is only used for the DOI fetcher, I would suggest to add this functionality as a private class method in
DoiFetcher
instead of a new class.