-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix(fetchers): fix OpenAlex entry type assignment #16533
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
InAnYan
wants to merge
5
commits into
JabRef:main
Choose a base branch
from
InAnYan:refactor/open-alex-1
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.
+63
−16
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aa82e64
fix(fetchers): fix OpenAlex entry type assignment
InAnYan ce757d9
refactor(fetchers): change type mappings in OpenAlex
InAnYan dfc01c6
Merge branch 'main' into refactor/open-alex-1
InAnYan ff35142
fix(fetchers): fix OpenAlex tests
InAnYan 2884819
Merge remote-tracking branch 'origin/refactor/open-alex-1' into refac…
InAnYan 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ | |
| import java.net.URL; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Locale; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
| import java.util.function.Function; | ||
|
|
@@ -31,7 +33,10 @@ | |
| import org.jabref.model.entry.BibEntry; | ||
| import org.jabref.model.entry.field.StandardField; | ||
| import org.jabref.model.entry.identifier.DOI; | ||
| import org.jabref.model.entry.types.EntryTypeFactory; | ||
| import org.jabref.model.entry.types.BiblatexNonStandardEntryType; | ||
| import org.jabref.model.entry.types.EntryType; | ||
| import org.jabref.model.entry.types.StandardEntryType; | ||
| import org.jabref.model.entry.types.UnknownEntryType; | ||
| import org.jabref.model.search.query.BaseQueryNode; | ||
|
|
||
| import com.google.common.annotations.VisibleForTesting; | ||
|
|
@@ -55,6 +60,33 @@ public class OpenAlex implements CustomizableKeyFetcher, SearchBasedParserFetche | |
| private static final Logger LOGGER = LoggerFactory.getLogger(OpenAlex.class); | ||
|
|
||
| private static final String URL_PATTERN = "https://api.openalex.org/works"; | ||
| private static final Map<String, EntryType> OPENALEX_TYPE_TO_ENTRY_TYPE = Map.ofEntries( | ||
| Map.entry("article", StandardEntryType.Article), | ||
| Map.entry("other", StandardEntryType.Misc), | ||
| Map.entry("dataset", StandardEntryType.Dataset), | ||
| Map.entry("book-chapter", StandardEntryType.InBook), | ||
| Map.entry("dissertation", StandardEntryType.Thesis), | ||
| Map.entry("conference-paper", StandardEntryType.InProceedings), | ||
| Map.entry("book", StandardEntryType.Book), | ||
| Map.entry("preprint", StandardEntryType.Online), | ||
| Map.entry("paratext", StandardEntryType.Misc), | ||
| Map.entry("conference-abstract", StandardEntryType.InProceedings), | ||
| Map.entry("report", StandardEntryType.Report), | ||
| Map.entry("reference-entry", StandardEntryType.InReference), | ||
| Map.entry("book-review", BiblatexNonStandardEntryType.Review), | ||
| Map.entry("libguides", StandardEntryType.Online), | ||
| Map.entry("peer-review", BiblatexNonStandardEntryType.Review), | ||
|
Comment on lines
+75
to
+78
Contributor
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. 1. Biblatex-only types mapped OpenAlex maps some OpenAlex work types to BibLaTeX-exclusive EntryTypes (e.g., BiblatexNonStandardEntryType.Review, StandardEntryType.Report/Thesis/Online/Dataset/Software). In BibTeX-mode libraries this triggers an integrity warning (BibTeXEntryTypeChecker) and exports the non-BibTeX entry type header verbatim, which many BibTeX toolchains may not recognize. Agent Prompt
|
||
| Map.entry("editorial", StandardEntryType.Article), | ||
| Map.entry("review", StandardEntryType.Article), | ||
| Map.entry("software", StandardEntryType.Software), | ||
| Map.entry("supplementary-materials", StandardEntryType.Misc), | ||
| Map.entry("letter", StandardEntryType.Article), | ||
| Map.entry("erratum", StandardEntryType.Article), | ||
| Map.entry("standard", StandardEntryType.Misc), | ||
| Map.entry("retraction", StandardEntryType.Misc), | ||
| Map.entry("data-paper", StandardEntryType.Article), | ||
| Map.entry("software-paper", StandardEntryType.Article) | ||
| ); | ||
|
|
||
| private final ImporterPreferences importerPreferences; | ||
|
|
||
|
|
@@ -67,6 +99,18 @@ public String getName() { | |
| return FETCHER_NAME; | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| EntryType mapOpenAlexTypeToEntryType(String openAlexType) { | ||
| String normalizedOpenAlexType = openAlexType.toLowerCase(Locale.ENGLISH); | ||
|
|
||
| EntryType entryType = OPENALEX_TYPE_TO_ENTRY_TYPE.get(normalizedOpenAlexType); | ||
| if (entryType != null) { | ||
| return entryType; | ||
| } | ||
|
|
||
| return new UnknownEntryType(openAlexType); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| Optional<String> extractOpenAlexId(String url) { | ||
| if (StringUtil.isBlank(url)) { | ||
|
|
@@ -178,7 +222,10 @@ private BibEntry jsonItemToBibEntry(JSONObject item) throws ParseException { | |
| DoiCleanup DoiCleanup = new DoiCleanup(); | ||
| BibEntry entry = new BibEntry(); | ||
|
|
||
| entry.setType(EntryTypeFactory.parse(item.getString("type"))); | ||
| String openAlexType = item.optString("type", null); | ||
| if (openAlexType != null) { | ||
| entry.setType(mapOpenAlexTypeToEntryType(openAlexType)); | ||
| } | ||
|
qodo-free-for-open-source-projects[bot] marked this conversation as resolved.
qodo-free-for-open-source-projects[bot] marked this conversation as resolved.
|
||
|
|
||
| entry.setField(StandardField.TITLE, item.optString("title")); | ||
|
|
||
|
|
@@ -289,7 +336,7 @@ public Optional<URL> findFullText(BibEntry entry) throws IOException, FetcherExc | |
| .filter(Objects::nonNull) | ||
| .map(primaryLocation -> primaryLocation.optString("pdf_url", "")) | ||
| .filter(StringUtil::isNotBlank) | ||
| .map(Unchecked.function(pdfUrl -> URLUtil.create(pdfUrl))); | ||
| .map(Unchecked.function(URLUtil::create)); | ||
| } catch (RuntimeException e) { | ||
| LOGGER.warn("Malformed URL", e); | ||
| throw (MalformedURLException) e.getCause(); | ||
|
|
@@ -314,7 +361,7 @@ public TrustLevel getTrustLevel() { | |
|
|
||
| private List<BibEntry> workUrlsToBibEntryList(@Nullable JSONArray workUrlArray) { | ||
| if (workUrlArray == null) { | ||
| List.of(); | ||
| return List.of(); | ||
| } | ||
| // TODO: This could be batched - see https://github.com/JabRef/jabref/pull/15023#issuecomment-3846630255 | ||
| return IntStream.range(0, workUrlArray.length()) | ||
|
|
@@ -351,7 +398,7 @@ private List<BibEntry> workArrayToBibEntryList(@Nullable JSONArray workUrlArray) | |
| } | ||
| return IntStream.range(0, workUrlArray.length()) | ||
| .mapToObj(workUrlArray::getJSONObject) | ||
| .map(Unchecked.function(jsonItem -> jsonItemToBibEntry(jsonItem))) | ||
| .map(Unchecked.function(this::jsonItemToBibEntry)) | ||
| .toList(); | ||
| } | ||
|
|
||
|
|
@@ -421,7 +468,7 @@ public Optional<URI> getCitationsApiUri(BibEntry entry) { | |
| // Instead, we perform a search for works that cite the given work's ID | ||
| try { | ||
| return getWorkObject(entry, List.of("id")) | ||
| .map(work -> work.optString("id")) | ||
| .map(work -> work.optString("id", null)) | ||
| .filter(Objects::nonNull) | ||
| .map(Unchecked.function(id -> | ||
| getUriBuilder("", 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.
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.
Uh oh!
There was an error while loading. Please reload this page.