-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Show fetch exception at citation relation #13549
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
Open
koppor
wants to merge
3
commits into
main
Choose a base branch
from
citation-relations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+117
−82
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,15 +8,23 @@ | |
import org.jabref.logic.importer.ImporterPreferences; | ||
import org.jabref.logic.importer.fetcher.CustomizableKeyFetcher; | ||
import org.jabref.logic.importer.fetcher.citation.CitationFetcher; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.logic.net.URLDownload; | ||
import org.jabref.logic.util.URLUtil; | ||
import org.jabref.model.entry.BibEntry; | ||
|
||
import com.google.gson.Gson; | ||
import org.hisp.dhis.jsontree.JsonMixed; | ||
import org.hisp.dhis.jsontree.JsonNode; | ||
import org.jspecify.annotations.NonNull; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class SemanticScholarCitationFetcher implements CitationFetcher, CustomizableKeyFetcher { | ||
public static final String FETCHER_NAME = "Semantic Scholar Citations Fetcher"; | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(SemanticScholarCitationFetcher.class); | ||
|
||
private static final String SEMANTIC_SCHOLAR_API = "https://api.semanticscholar.org/graph/v1/"; | ||
|
||
private static final Gson GSON = new Gson(); | ||
|
@@ -27,8 +35,8 @@ public SemanticScholarCitationFetcher(ImporterPreferences importerPreferences) { | |
this.importerPreferences = importerPreferences; | ||
} | ||
|
||
public String getAPIUrl(String entry_point, BibEntry entry) { | ||
return SEMANTIC_SCHOLAR_API + "paper/" + "DOI:" + entry.getDOI().orElseThrow().asString() + "/" + entry_point | ||
public String getAPIUrl(String entryPoint, BibEntry entry) { | ||
return SEMANTIC_SCHOLAR_API + "paper/" + "DOI:" + entry.getDOI().orElseThrow().asString() + "/" + entryPoint | ||
+ "?fields=" + "title,authors,year,citationCount,referenceCount,externalIds,publicationTypes,abstract,url" | ||
+ "&limit=1000"; | ||
} | ||
|
@@ -42,6 +50,7 @@ public List<BibEntry> searchCitedBy(BibEntry entry) throws FetcherException { | |
URL citationsUrl; | ||
try { | ||
citationsUrl = URLUtil.create(getAPIUrl("citations", entry)); | ||
LOGGER.debug("Cited URL {} ", citationsUrl); | ||
} catch (MalformedURLException e) { | ||
throw new FetcherException("Malformed URL", e); | ||
} | ||
|
@@ -66,15 +75,30 @@ public List<BibEntry> searchCitedBy(BibEntry entry) throws FetcherException { | |
URL referencesUrl; | ||
try { | ||
referencesUrl = URLUtil.create(getAPIUrl("references", entry)); | ||
LOGGER.debug("Citing URL {} ", referencesUrl); | ||
} catch (MalformedURLException e) { | ||
throw new FetcherException("Malformed URL", e); | ||
} | ||
|
||
URLDownload urlDownload = new URLDownload(referencesUrl); | ||
importerPreferences.getApiKey(getName()).ifPresent(apiKey -> urlDownload.addHeader("x-api-key", apiKey)); | ||
ReferencesResponse referencesResponse = GSON.fromJson(urlDownload.asString(), ReferencesResponse.class); | ||
String response = urlDownload.asString(); | ||
ReferencesResponse referencesResponse = GSON.fromJson(response, ReferencesResponse.class); | ||
|
||
if (referencesResponse.getData() == null) { | ||
JsonNode json = JsonNode.of(response); | ||
JsonNode disclaimerJson = json.getOrNull("citingPaperInfo.openAccessPdf.disclaimer"); | ||
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. Use kong's unirest json that allows you to use optionals
|
||
if (disclaimerJson != null) { | ||
JsonMixed disclaimerNode = JsonMixed.of(disclaimerJson); | ||
if (disclaimerNode.isString()) { | ||
String disclaimer = disclaimerNode.string(); | ||
LOGGER.debug("Received a disclaimer from Semantic Scholar: {}", disclaimer); | ||
if (disclaimer.contains("'references'")) { | ||
throw new FetcherException(Localization.lang("Restricted access to references: %0", disclaimer)); | ||
} | ||
} | ||
} | ||
|
||
return List.of(); | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why another json library?
Uh oh!
There was an error while loading. Please reload this page.
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.
For optionals use kongs unirest 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.
Because I know the author personally. And it is fast
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.
Show me. 😅
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: eg.g
JSONObject result = item.getJSONObject("resultList").getJSONArray("result").getJSONObject(0);
jabref/jablib/src/main/java/org/jabref/logic/importer/fetcher/EuropePmcFetcher.java
Line 117 in e29044c