-
-
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 new parser for MathSciNet search #11055
Conversation
src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java
Outdated
Show resolved
Hide resolved
Hi, thanks for your pull request, on first look, your changes are promising. Thanks especially for providing a test with your changes. However, there are some small issues with your codestyle and the MathSciNetTest is failing. Don't worry about the other fetchertests for now. |
Hey, thanks! I missed the codestyle extension. I'll also have a look at the test and get back. |
e421224
to
3dc1f55
Compare
Done! @calixtus |
src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java
Outdated
Show resolved
Hide resolved
src/test/java/org/jabref/logic/importer/fetcher/MathSciNetTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/jabref/logic/importer/fetcher/MathSciNetTest.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Oliver Kopp <[email protected]>
…bref into fix-for-issue-10996
cbb8a05
to
e1e1daa
Compare
private Optional<String> getOrNull(JSONObject item, List<String> keys) { | ||
Object value = item; | ||
for (String key : keys) { | ||
if (value instanceof JSONObject) { |
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.
if (value instanceof JSONObject) { | |
if (value instanceof JSONObject obj) { | |
.... |
You can use the new instance of pattern matching syntax, which makes the extra casting step necessary
https://docs.oracle.com/en/java/javase/17/language/pattern-matching-instanceof-operator.html#GUID-843060B5-240C-4F47-A7B0-95C42E5B08A7
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.
Hi, I just went through the docs. If I'm not wrong, did you mean that it would make the extra casting step "unnecessary"?
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 removed the casts and followed the new syntax. It is odd that IntelliJ is giving me red squiggly lines and a suggestion to cast it back. Will ignore for now.
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.
Okay nope, I added the obj syntax but seems like the cast is necessary, else I'm getting this compilation error:
error: cannot find symbol
value = value.opt(key);
^
symbol: method opt(String)
location: variable value of type Object
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.
See the examples in the linked docs, you need to use value = obj.get... After the if
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.
Got it!
src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Oliver Kopp <[email protected]>
Co-authored-by: Oliver Kopp <[email protected]>
Co-authored-by: Oliver Kopp <[email protected]>
src/test/java/org/jabref/logic/importer/fetcher/MathSciNetTest.java
Outdated
Show resolved
Hide resolved
…bref into fix-for-issue-10996
I've made these new set of changes (wherever feasible, otherwise I've commented on your suggestions) and re-requested for review. I have learnt more from this single pull request regarding production-ready code than I ever have from my three years of CS degree. Thank you so much for your valuable inputs and patience. @koppor @Siedlerchr |
Optional<BibEntry> fetchedEntry = fetcher.performSearchById("3537908"); | ||
assertEquals(Optional.of(ratiuEntry), fetchedEntry); | ||
void getParser() throws Exception { | ||
String fileName = "/importer/fetcher/jsonTest.json"; |
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.
Java has a special folder for resources src/main/resoures and for test src/test/resources
See the other importer test files there
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.
Some small code comments
return Optional.of(authorsString); | ||
} | ||
|
||
private String getKeywords(JSONObject primaryClass) { |
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.
Please also use the Optional<String>
thing you did at toAuhtors
. Because of consistency.
// Skip author and keywords fields as they are already set | ||
if (field == StandardField.AUTHOR || field == StandardField.KEYWORDS) { | ||
continue; | ||
} |
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.
Just remove StandardField.AUTHOR
and StandardField.KEYWORDS
from FIELD_MAPPING
. Think, this is the only "use" in the code, which savely can be removed.
// Handle articleUrl and mrnumber fields separately, as they are non-nested properties in the JSON and can be retrieved as Strings directly | ||
String doi = item.optString("articleUrl", ""); | ||
if (!doi.isEmpty()) { | ||
entry.setField(StandardField.DOI, doi); |
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.
Try to route through DOI#parse
. If that optional is present, use doi.getNormalized()
, otherwise use the doi
variable. In That way, the http prefix is removed if it is a valid doi, but the full string is kept in case of a DOI parsing error.
return Optional.empty(); | ||
} | ||
|
||
// Method to change character set, to fix output string encoding |
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.
Convert to full JavaDoc:
/**
* ... text ...
*/
…bref into fix-for-issue-10996
Made the third round of changes. @koppor @Siedlerchr |
fix tests, rename resources
I took the opportunity to fix some issues:
|
Thank you so much. (1) is a huge one, don't know if this was because of sleepless coding or a slip of keyboard. (2) will remember this convention. (3) nice catch! |
Closes #10996
Closes #8170
The issue exposed a bug where MathSciNet search gives the following parsing error:
(Replicated locally)
To fix the issue, a new parser has been built for MathSciNet which parses the retrieved JSON results correctly. A test has been added as well.
Files modified:
jabref/src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java
jabref/src/test/java/org/jabref/logic/importer/fetcher/MathSciNet.java
The search now works fine:
Mandatory checks
CHANGELOG.md
described in a way that is understandable for the average user (if applicable)