-
-
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
Implimented arXivId Parsing for PDF with arXivId #12335
Changes from 1 commit
220ddac
32e9867
9c80e04
89de378
28755cf
06b6bb0
457bb3f
a653de5
06c771b
1512d7e
0308a0b
15ac9a2
a21f893
774ee84
148b716
126cbaa
03fede4
cfe1664
b3d8556
18673c8
1f112a2
5e961fa
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 |
---|---|---|
|
@@ -372,9 +372,9 @@ Optional<BibEntry> getEntryFromPDFContent(String firstpageContents, String lineS | |
EntryType type = StandardEntryType.InProceedings; | ||
if (curString.length() > 4) { | ||
// special case: possibly conference as first line on the page | ||
arXivId = getArXivId(null); | ||
extractYear(); | ||
doi = getDoi(null); | ||
arXivId = getArXivId(arXivId); | ||
if (curString.contains("Conference")) { | ||
fillCurStringWithNonEmptyLines(); | ||
conference = curString; | ||
|
@@ -391,7 +391,7 @@ Optional<BibEntry> getEntryFromPDFContent(String firstpageContents, String lineS | |
} | ||
} | ||
// sometimes ArXiv ID is read before title | ||
getArXivId(null); | ||
arXivId = getArXivId(arXivId); | ||
// start: title | ||
fillCurStringWithNonEmptyLines(); | ||
title = streamlineTitle(curString); | ||
|
@@ -608,18 +608,16 @@ private String getDoi(String doi) { | |
} | ||
|
||
private String getArXivId(String arXivId) { | ||
final int ARXIV_PREFIX_LENGTH = "arxiv:".length(); | ||
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. Let's define it as static and move it outside the method to avoid reallocating the same string object everytime the method is called.
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. should i move it to the 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. In general (and in OOP more specifically) we want to keep the data as close as possible to the code that uses it, if the constant is used there then okay otherwise let's keep it in the class where it is used. 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. sure, thank you |
||
if (arXivId == null) { | ||
String arXiv = curString.split(" ")[0]; | ||
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 could lead to a null pointer if there is no whitespace and you access the 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. Hello Siedlerchr, I tested this method with empty/non-empty strings with/without whitespaces and it would only give a null pointer if the |
||
arXivId = ArXivIdentifier.parse(arXiv).map(ArXivIdentifier::asString).orElse(null); | ||
if (arXivId != null) { | ||
if (curString.length() > arXivId.length() + 7) { | ||
// The arxiv string also contains the year | ||
curString = curString.substring(arXivId.length() + 7); | ||
extractYear(); | ||
curString = ""; | ||
proceedToNextNonEmptyLine(); | ||
} | ||
return arXivId; | ||
if (arXivId != null && curString.length() > arXivId.length() + ARXIV_PREFIX_LENGTH) { | ||
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 what I meant by reduced nesting, Please read this: https://szymonkrajewski.pl/why-should-you-return-early/ 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 what I wrote based on my understanding of the article, please share you feedback 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. Yes, great, it looks better! |
||
// The arxiv string also contains the year | ||
curString = curString.substring(arXivId.length() + ARXIV_PREFIX_LENGTH); | ||
extractYear(); | ||
curString = ""; | ||
proceedToNextNonEmptyLine(); | ||
} | ||
} | ||
return arXivId; | ||
|
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.
This is an example why comments are to be avoided as much as possible, this line compiles fine, runs fine but the comment above it is misguiding. Please move comment to its correct location.
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.
sure