-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Integrate with SearchRxiv #15373
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
LoayTarek5
wants to merge
19
commits into
JabRef:main
Choose a base branch
from
LoayTarek5:integrate-with-SearchRxiv-12618
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.
Open
Integrate with SearchRxiv #15373
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
37ab8bc
including SearchRxiv integration for SLR and enhancements to citatio…
LoayTarek5 9919a8a
Add share functionality for SearchRxiv
LoayTarek5 a27d4ac
introduce buildStudy method for creating Study instances and enhance …
LoayTarek5 9f47f53
adding a button for exporting search queries to SearchRxiv and improv…
LoayTarek5 0f32f15
Implement SearchRxivExporter for exporting study search queries in JS…
LoayTarek5 9a95c12
adding export options for search queries in JSON format
LoayTarek5 ec9f863
Add unit tests for SearchRxivExporter, verifying file creation and JS…
LoayTarek5 45303dd
Revert unrelated changes, keep only SearchRxiv integration files
LoayTarek5 eea0bb9
Sync remaining unrelated files with upstream main
LoayTarek5 673dbd6
Merge branch 'main' into integrate-with-SearchRxiv-12618
LoayTarek5 2b52e3b
Merge branch 'main' into integrate-with-SearchRxiv-12618
LoayTarek5 be5620e
Fix localization
LoayTarek5 21f89d9
Merge branch 'integrate-with-SearchRxiv-12618' of github.com:LoayTare…
LoayTarek5 dcf4774
Fix localization: match tooltip key with FXML
LoayTarek5 af6d2eb
Fix localization: add missing key and match tooltip with FXML
LoayTarek5 303fc5a
Merge branch 'main' into integrate-with-SearchRxiv-12618
LoayTarek5 8e1cf45
Fix CHANGELOG, restore some missing
LoayTarek5 b1da1e9
Extract noCatalogEnabled to ActionHelper
LoayTarek5 8f8625a
Merge branch 'integrate-with-SearchRxiv-12618' of github.com:LoayTare…
LoayTarek5 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
Some comments aren't visible on the classic Files Changed page.
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
75 changes: 75 additions & 0 deletions
75
jablib/src/main/java/org/jabref/logic/exporter/SearchRxivExporter.java
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 |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package org.jabref.logic.exporter; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import org.jabref.model.study.Study; | ||
| import org.jabref.model.study.StudyDatabase; | ||
| import org.jabref.model.study.StudyQuery; | ||
|
|
||
| import tools.jackson.databind.ObjectMapper; | ||
|
|
||
| /// Exports study search queries in the SearchRxiv / search-query JSON format. | ||
| /// One file is created per query and database combination, | ||
| /// as the format uses a single platform string per record. | ||
| /// | ||
| /// The JSON format follows the search-query library's SearchFile specification. | ||
| /// | ||
| /// @see <a href="https://github.com/CoLRev-Environment/search-query">search-query library</a> | ||
| /// @see <a href="https://colrev-environment.github.io/search-query/">search-query format documentation</a> | ||
| /// @see <a href="https://www.cabidigitallibrary.org/journal/searchrxiv">SearchRxiv</a> | ||
| public class SearchRxivExporter { | ||
|
|
||
| public static final String SEARCHRXIV_URL = "https://www.cabidigitallibrary.org/journal/searchrxiv"; | ||
|
|
||
| private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); | ||
|
|
||
| /// Exports the study's search queries as JSON files to the given directory. | ||
| /// One file per query and database combination is created. | ||
| /// | ||
| /// @param study The study containing queries, databases, and authors | ||
| /// @param directory The target directory to write the JSON files into | ||
| /// @throws IOException if a file cannot be written | ||
| public void export(Study study, Path directory) throws IOException { | ||
| int index = 0; | ||
| for (StudyQuery studyQuery : study.getQueries()) { | ||
| for (StudyDatabase database : study.getDatabases()) { | ||
| Path file = directory.resolve(buildFileName(studyQuery.getQuery(), database.getName(), index)); | ||
| Files.writeString(file, buildJson(study, studyQuery.getQuery(), database.getName())); | ||
| index++; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Builds a JSON string following the search-query format. | ||
| /// Format spec: <a href="https://github.com/CoLRev-Environment/search-query">search-query</a> | ||
| private String buildJson(Study study, String query, String platform) throws IOException { | ||
| Map<String, Object> data = new LinkedHashMap<>(); | ||
| data.put("search_string", query); | ||
| data.put("platform", platform.toLowerCase()); | ||
| data.put("authors", study.getAuthors().stream() | ||
| .map(author -> Map.of("name", author)) | ||
| .toList()); | ||
| // Placeholder fields — to be filled by the user on SearchRxiv | ||
| data.put("record_info", Map.of()); | ||
| data.put("date", Map.of()); | ||
| data.put("database", List.of()); | ||
| return OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(data); | ||
| } | ||
|
|
||
| private String buildFileName(String query, String databaseName, int index) { | ||
| String cleanDb = databaseName.replaceAll("[^A-Za-z0-9]", "_"); | ||
| String cleanQuery = query.replaceAll("[^A-Za-z0-9]", "_"); | ||
| if (cleanQuery.isEmpty()) { | ||
| cleanQuery = "query"; | ||
| } | ||
| if (cleanQuery.length() > 20) { | ||
| cleanQuery = cleanQuery.substring(0, 20); | ||
| } | ||
| return cleanDb + "-" + cleanQuery + "-" + index + ".json"; | ||
| } | ||
| } |
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
80 changes: 80 additions & 0 deletions
80
jablib/src/test/java/org/jabref/logic/exporter/SearchRxivExporterTest.java
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 |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package org.jabref.logic.exporter; | ||
|
|
||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.util.List; | ||
|
|
||
| import org.jabref.model.study.Study; | ||
| import org.jabref.model.study.StudyDatabase; | ||
| import org.jabref.model.study.StudyQuery; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.io.TempDir; | ||
| import tools.jackson.databind.JsonNode; | ||
| import tools.jackson.databind.ObjectMapper; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| class SearchRxivExporterTest { | ||
|
|
||
| private final SearchRxivExporter exporter = new SearchRxivExporter(); | ||
|
|
||
| private Study buildStudy() { | ||
| return new Study( | ||
| List.of("John Doe"), | ||
| "Test Study", | ||
| List.of("What is AI?"), | ||
| List.of(new StudyQuery("artificial intelligence AND health")), | ||
| List.of(new StudyDatabase("IEEE", true))); | ||
| } | ||
|
|
||
| @Test | ||
| void exportCreatesOneFilePerQueryAndDatabase(@TempDir Path tempDir) throws Exception { | ||
| exporter.export(buildStudy(), tempDir); | ||
|
|
||
| try (var files = Files.list(tempDir)) { | ||
| assertEquals(1, files.count()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void exportedJsonContainsCorrectFields(@TempDir Path tempDir) throws Exception { | ||
| exporter.export(buildStudy(), tempDir); | ||
|
|
||
| Path file; | ||
| try (var files = Files.list(tempDir)) { | ||
| file = files.findFirst().orElseThrow(); | ||
| } | ||
| String content = Files.readString(file); | ||
|
InAnYan marked this conversation as resolved.
|
||
| ObjectMapper mapper = new ObjectMapper(); | ||
| JsonNode root = mapper.readTree(content); | ||
|
|
||
| assertEquals("artificial intelligence AND health", root.get("search_string").asText()); | ||
| assertEquals("ieee", root.get("platform").asText()); | ||
| assertEquals("John Doe", root.get("authors").get(0).get("name").asText()); | ||
| assertTrue(root.has("record_info")); | ||
| assertTrue(root.has("date")); | ||
| assertFalse(root.has("title")); | ||
| assertTrue(root.has("database")); | ||
| assertEquals(0, root.get("database").size()); | ||
| } | ||
|
|
||
| @Test | ||
| void exportCreatesMultipleFilesForMultipleDatabases(@TempDir Path tempDir) throws Exception { | ||
| Study study = new Study( | ||
| List.of("John Doe"), | ||
| "Test Study", | ||
| List.of("What is AI?"), | ||
| List.of(new StudyQuery("machine learning")), | ||
| List.of(new StudyDatabase("IEEE", true), | ||
| new StudyDatabase("ACM", true))); | ||
|
|
||
| exporter.export(study, tempDir); | ||
|
|
||
| try (var files = Files.list(tempDir)) { | ||
| assertEquals(2, files.count()); | ||
| } | ||
| } | ||
| } | ||
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.