Skip to content
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 support for scite.ai #10617

Merged
merged 26 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5b5ff36
task: first cut of Scite tab and associated preference
u7500248 Nov 3, 2023
8b559b4
task: comments and minor refactoring
u7500248 Nov 3, 2023
c3c9425
task: Updated readme.md for issue #375
u7500248 Nov 3, 2023
6d0e5bb
fix: Import ordering and markdown space
u7500248 Nov 3, 2023
8780f12
fix: imports and whitespace (checkstyle)
u7500248 Nov 3, 2023
f03516e
fix: imports and whitespace (checkstyle)
u7500248 Nov 3, 2023
1f32428
fix: imports and whitespace (checkstyle)
u7500248 Nov 3, 2023
41795bb
fix: Removed unnecessary parentheses (OpenRewrite)
u7500248 Nov 3, 2023
9308fff
fix: Unit tests and localisation keys
u7500248 Nov 3, 2023
a960df1
fix: Removed unnecessary heading in CHANGELOG.md
u7500248 Nov 6, 2023
03bc945
fix: Made SciteTallyDTO a record type and moved it to new file
u7500248 Nov 6, 2023
3064e5a
fix: Made the scite.ai base url a constant
u7500248 Nov 6, 2023
c838463
fix: Exception handling now catches most specific exceptions, and ret…
u7500248 Nov 6, 2023
ac77a46
Merge branch 'main' into fix-for-issue-375
u7500248 Nov 6, 2023
da9ec37
fix: style for scite message box
u7500248 Nov 8, 2023
659feea
fix: Catch specific exception and display error message rather than t…
u7500248 Nov 8, 2023
b9f7d42
fix: Localization for SciteTab error messages, and "Scite" name is no…
u7500248 Nov 8, 2023
ed4bd79
Merge branch 'main' into fix-for-issue-375
u7500248 Nov 8, 2023
54e97cc
some small refactoring
Siedlerchr Nov 9, 2023
41cdec3
checkstyle
Siedlerchr Nov 9, 2023
57da7fd
Update CHANGELOG.md
calixtus Nov 9, 2023
65474e5
Update EntryEditorTab.java
calixtus Nov 9, 2023
79b50dd
move and checkstyle
Siedlerchr Nov 9, 2023
d065a41
Merge branch 'fix-for-issue-375' of github.com:u7500248/jabref into f…
Siedlerchr Nov 9, 2023
64b226e
fix l10n and rename
Siedlerchr Nov 9, 2023
c067707
Merge branch 'main' into fix-for-issue-375
calixtus Nov 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Added

- We Added an integration to scite.ai that retrieves 'Smart Citation' tallies for citations that have a DOI. This appears as a tab on the entry editor pane, and can be disabled via a preference check box [#375](https://github.com/koppor/jabref/issues/375)

### Added
u7500248 marked this conversation as resolved.
Show resolved Hide resolved

- We added a dropdown menu to let users change the reference library during AUX file import. [#10472](https://github.com/JabRef/jabref/issues/10472)
- We added a button to let users reset the cite command to the default value. [#10569](https://github.com/JabRef/jabref/issues/10569)

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ private List<EntryEditorTab> createTabs() {
entryEditorTabList.remove(RelatedArticlesTab.NAME);
entryEditorTabList.remove(LatexCitationsTab.NAME);
entryEditorTabList.remove(FulltextSearchResultsTab.NAME);
entryEditorTabList.remove(SciteTab.NAME);
entryEditorTabList.remove("Comments");
// Then show the remaining configured
for (Map.Entry<String, Set<Field>> tab : entryEditorTabList.entrySet()) {
Expand Down Expand Up @@ -302,6 +303,8 @@ private List<EntryEditorTab> createTabs() {

entryEditorTabs.add(new FulltextSearchResultsTab(stateManager, preferencesService, dialogService, taskExecutor));

entryEditorTabs.add(new SciteTab(preferencesService, taskExecutor));

return entryEditorTabs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static JournalPopupEnabled fromString(String status) {
private final DoubleProperty dividerPosition;
private final BooleanProperty autoLinkFiles;
private final ObjectProperty<JournalPopupEnabled> enablementStatus;
private final BooleanProperty shouldShowSciteTab;

public EntryEditorPreferences(Map<String, Set<Field>> entryEditorTabList,
Map<String, Set<Field>> defaultEntryEditorTabList,
Expand All @@ -58,7 +59,8 @@ public EntryEditorPreferences(Map<String, Set<Field>> entryEditorTabList,
boolean allowIntegerEditionBibtex,
double dividerPosition,
boolean autolinkFilesEnabled,
JournalPopupEnabled journalPopupEnabled) {
JournalPopupEnabled journalPopupEnabled,
boolean showSciteTab) {

this.entryEditorTabList = new SimpleMapProperty<>(FXCollections.observableMap(entryEditorTabList));
this.defaultEntryEditorTabList = new SimpleMapProperty<>(FXCollections.observableMap(defaultEntryEditorTabList));
Expand All @@ -71,6 +73,7 @@ public EntryEditorPreferences(Map<String, Set<Field>> entryEditorTabList,
this.dividerPosition = new SimpleDoubleProperty(dividerPosition);
this.autoLinkFiles = new SimpleBooleanProperty(autolinkFilesEnabled);
this.enablementStatus = new SimpleObjectProperty<>(journalPopupEnabled);
this.shouldShowSciteTab = new SimpleBooleanProperty(showSciteTab);
}

public ObservableMap<String, Set<Field>> getEntryEditorTabs() {
Expand Down Expand Up @@ -196,4 +199,16 @@ public ObjectProperty<JournalPopupEnabled> enableJournalPopupProperty() {
public void setEnableJournalPopup(JournalPopupEnabled journalPopupEnabled) {
this.enablementStatus.set(journalPopupEnabled);
}

public boolean shouldShowSciteTab() {
return this.shouldShowSciteTab.get();
}

public BooleanProperty shouldShowLSciteTabProperty() {
return this.shouldShowSciteTab;
}

public void setShouldShowSciteTab(boolean shouldShowSciteTab) {
this.shouldShowSciteTab.set(shouldShowSciteTab);
}
}
122 changes: 122 additions & 0 deletions src/main/java/org/jabref/gui/entryeditor/SciteTab.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package org.jabref.gui.entryeditor;

import java.net.URLEncoder;

import javafx.geometry.HPos;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;

import org.jabref.gui.desktop.JabRefDesktop;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.entry.BibEntry;
import org.jabref.preferences.PreferencesService;

import com.tobiasdiez.easybind.EasyBind;
import org.controlsfx.control.HyperlinkLabel;

public class SciteTab extends EntryEditorTab {

public static final String NAME = "Scite";

private final GridPane sciteResultsPane;
private final ProgressIndicator progressIndicator;
private final SciteTabViewModel viewModel;
private final PreferencesService preferencesService;

public SciteTab(PreferencesService preferencesService, TaskExecutor taskExecutor) {
this.preferencesService = preferencesService;
this.viewModel = new SciteTabViewModel(preferencesService, taskExecutor);
this.sciteResultsPane = new GridPane();
this.progressIndicator = new ProgressIndicator();

setText(Localization.lang("Scite"));
setTooltip(new Tooltip(Localization.lang("Search scite.ai for Smart Citations")));
setSciteResultsPane();
}

private void setSciteResultsPane() {
progressIndicator.setMaxSize(100, 100);
sciteResultsPane.add(progressIndicator, 0, 0);

ColumnConstraints column = new ColumnConstraints();
column.setPercentWidth(100);
column.setHalignment(HPos.CENTER);

sciteResultsPane.getColumnConstraints().setAll(column);
sciteResultsPane.setId("scitePane");
setContent(sciteResultsPane);

EasyBind.subscribe(viewModel.statusProperty(), status -> {
sciteResultsPane.getChildren().clear();
switch (status) {
case IN_PROGRESS:
sciteResultsPane.add(progressIndicator, 0, 0);
break;
case FOUND:
if (viewModel.getCurrentResult().isPresent()) {
sciteResultsPane.add(getTalliesPane(viewModel.getCurrentResult().get()), 0, 0);
}
break;
case ERROR:
sciteResultsPane.add(getErrorPane(), 0, 0);
break;
}
});
}

@Override
public boolean shouldShow(BibEntry entry) {
return viewModel.shouldShow();
}

@Override
protected void bindToEntry(BibEntry entry) {
viewModel.bindToEntry(entry);
}

private VBox getErrorPane() {
Label titleLabel = new Label(Localization.lang("Error"));
titleLabel.setStyle("-fx-font-size: 1.5em;-fx-font-weight: bold;-fx-text-fill: -fx-accent;");
Text errorMessageText = new Text(viewModel.searchErrorProperty().get());
VBox errorMessageBox = new VBox(30, titleLabel, errorMessageText);
errorMessageBox.setStyle("-fx-padding: 30 0 0 30;");
return errorMessageBox;
}

private VBox getTalliesPane(SciteTabViewModel.SciteTallyDTO tallyDTO) {
Label titleLabel = new Label(Localization.lang("Tallies for") + " " + tallyDTO.getDoi());
titleLabel.setStyle("-fx-font-size: 1.5em;-fx-font-weight: bold;");
calixtus marked this conversation as resolved.
Show resolved Hide resolved
Text message = new Text(String.format("Total Citations: %d\nSupporting: %d\nContradicting: %d\nMentioning: %d\nUnclassified: %d\nCiting Publications: %d",
tallyDTO.getTotal(),
tallyDTO.getSupporting(),
tallyDTO.getContradicting(),
tallyDTO.getMentioning(),
tallyDTO.getUnclassified(),
tallyDTO.getCitingPublications()
));

String url = "https://scite.ai/reports/" + URLEncoder.encode(tallyDTO.getDoi());
calixtus marked this conversation as resolved.
Show resolved Hide resolved
HyperlinkLabel link = new HyperlinkLabel(String.format("See full report at [%s]", url));
link.setOnAction(event -> {
if (event.getSource() instanceof Hyperlink) {
var filePreferences = preferencesService.getFilePreferences();
try {
JabRefDesktop.openBrowser(url, filePreferences);
} catch (Exception ex) {
calixtus marked this conversation as resolved.
Show resolved Hide resolved
throw new RuntimeException(ex);
}
}
});

VBox messageBox = new VBox(30, titleLabel, message, link);
messageBox.setStyle("-fx-padding: 30 0 0 30;");
calixtus marked this conversation as resolved.
Show resolved Hide resolved
return messageBox;
}
}
Loading
Loading