Skip to content

Commit

Permalink
Enable the exploration of bib entries' relations (cited by and citing) (
Browse files Browse the repository at this point in the history
#10324)

Co-authored-by: Tim Bachmann <58782027+timbachmann@users.noreply.github.com>
Co-authored-by: Raphael Kreft <r.kreft@unibas.ch>
Co-authored-by: Marcel Luethi <marcel.luethi@unibas.ch>
Co-authored-by: olivierM <olivier.mattmann@stud.unibas.ch>
Co-authored-by: matiascg <matiascargon@hotmail.com>
  • Loading branch information
6 people authored Sep 11, 2023
1 parent 8d7d772 commit 0c6c0a9
Show file tree
Hide file tree
Showing 17 changed files with 973 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Added

- We added the possibility to find (and add) papers that cite or are cited by a given paper. [#6187](https://github.com/JabRef/jabref/issues/6187)
- We added an error-specific message for when a download from a URL fails. [#9826](https://github.com/JabRef/jabref/issues/9826)
- We added support for customizating the citation command (e.g., `[@key1,@key2]`) when [pushing to external applications](https://docs.jabref.org/cite/pushtoapplications). [#10133](https://github.com/JabRef/jabref/issues/10133)
- We added protected terms described as "Computer science". [#10222](https://github.com/JabRef/jabref/pull/10222)
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 @@ -31,6 +31,7 @@
import org.jabref.gui.StateManager;
import org.jabref.gui.citationkeypattern.GenerateCitationKeySingleAction;
import org.jabref.gui.cleanup.CleanupSingleAction;
import org.jabref.gui.entryeditor.citationrelationtab.CitationRelationsTab;
import org.jabref.gui.entryeditor.fileannotationtab.FileAnnotationTab;
import org.jabref.gui.entryeditor.fileannotationtab.FulltextSearchResultsTab;
import org.jabref.gui.externalfiles.ExternalFilesEntryLinker;
Expand Down Expand Up @@ -282,6 +283,8 @@ private List<EntryEditorTab> createTabs() {
entryEditorTabs.add(new MathSciNetTab());
entryEditorTabs.add(new FileAnnotationTab(libraryTab.getAnnotationCache()));
entryEditorTabs.add(new RelatedArticlesTab(entryEditorPreferences, preferencesService, dialogService, taskExecutor));
entryEditorTabs.add(new CitationRelationsTab(entryEditorPreferences, dialogService, databaseContext,
undoManager, stateManager, fileMonitor, preferencesService, libraryTab));

sourceTab = new SourceTab(
databaseContext,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.jabref.gui.entryeditor.citationrelationtab;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.identifier.DOI;

public class BibEntryRelationsCache {
private static final Map<String, List<BibEntry>> CITATIONS_MAP = new HashMap<>();
private static final Map<String, List<BibEntry>> REFERENCES_MAP = new HashMap<>();

public List<BibEntry> getCitations(BibEntry entry) {
return CITATIONS_MAP.getOrDefault(entry.getDOI().map(DOI::getDOI).orElse(""), Collections.emptyList());
}

public List<BibEntry> getReferences(BibEntry entry) {
return REFERENCES_MAP.getOrDefault(entry.getDOI().map(DOI::getDOI).orElse(""), Collections.emptyList());
}

public void cacheOrMergeCitations(BibEntry entry, List<BibEntry> citations) {
entry.getDOI().ifPresent(doi -> CITATIONS_MAP.put(doi.getDOI(), citations));
}

public void cacheOrMergeReferences(BibEntry entry, List<BibEntry> references) {
entry.getDOI().ifPresent(doi -> REFERENCES_MAP.putIfAbsent(doi.getDOI(), references));
}

public boolean citationsCached(BibEntry entry) {
return CITATIONS_MAP.containsKey(entry.getDOI().map(DOI::getDOI).orElse(""));
}

public boolean referencesCached(BibEntry entry) {
return REFERENCES_MAP.containsKey(entry.getDOI().map(DOI::getDOI).orElse(""));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.jabref.gui.entryeditor.citationrelationtab;

import java.util.List;

import org.jabref.gui.entryeditor.citationrelationtab.semanticscholar.SemanticScholarFetcher;
import org.jabref.logic.importer.FetcherException;
import org.jabref.model.entry.BibEntry;

public class BibEntryRelationsRepository {
private final SemanticScholarFetcher fetcher;
private final BibEntryRelationsCache cache;

public BibEntryRelationsRepository(SemanticScholarFetcher fetcher, BibEntryRelationsCache cache) {
this.fetcher = fetcher;
this.cache = cache;
}

public List<BibEntry> getCitations(BibEntry entry) {
if (needToRefreshCitations(entry)) {
forceRefreshCitations(entry);
}

return cache.getCitations(entry);
}

public List<BibEntry> getReferences(BibEntry entry) {
if (needToRefreshReferences(entry)) {
List<BibEntry> references = fetcher.searchCiting(entry);
cache.cacheOrMergeReferences(entry, references);
}

return cache.getReferences(entry);
}

public void forceRefreshCitations(BibEntry entry) {
try {
List<BibEntry> citations = fetcher.searchCitedBy(entry);
cache.cacheOrMergeCitations(entry, citations);
} catch (FetcherException e) {
throw new RuntimeException(e);
}
}

public boolean needToRefreshCitations(BibEntry entry) {
return !cache.citationsCached(entry);
}

public boolean needToRefreshReferences(BibEntry entry) {
return !cache.referencesCached(entry);
}

public void forceRefreshReferences(BibEntry entry) {
List<BibEntry> references = fetcher.searchCiting(entry);
cache.cacheOrMergeReferences(entry, references);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.jabref.gui.entryeditor.citationrelationtab;

import java.util.EnumSet;

import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;

import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.util.TextFlowLimited;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.types.EntryType;
import org.jabref.model.entry.types.StandardEntryType;

/**
* Class to unify the display method of BibEntries in ListViews.
*/
public class BibEntryView {

/**
* Creates a layout for a given {@link BibEntry} to be displayed in a List
*
* @param entry {@link BibEntry} to display
* @return layout container displaying the entry
*/
public static Node getEntryNode(BibEntry entry) {
Node entryType = getIcon(entry.getType()).getGraphicNode();
entryType.getStyleClass().add("type");
Label authors = new Label(entry.getFieldOrAliasLatexFree(StandardField.AUTHOR).orElse(""));
authors.getStyleClass().add("authors");
authors.setWrapText(true);
Label title = new Label(entry.getFieldOrAliasLatexFree(StandardField.TITLE).orElse(""));
title.getStyleClass().add("title");
title.setWrapText(true);
Label year = new Label(entry.getFieldOrAliasLatexFree(StandardField.YEAR).orElse(""));
year.getStyleClass().add("year");
Label journal = new Label(entry.getFieldOrAliasLatexFree(StandardField.JOURNAL).orElse(""));
journal.getStyleClass().add("journal");

VBox entryContainer = new VBox(
new HBox(10, entryType, title),
new HBox(5, year, journal),
authors
);
entry.getFieldOrAliasLatexFree(StandardField.ABSTRACT).ifPresent(summaryText -> {
TextFlowLimited summary = new TextFlowLimited(new Text(summaryText));
summary.getStyleClass().add("summary");
entryContainer.getChildren().add(summary);
});

entryContainer.getStyleClass().add("bibEntry");
return entryContainer;
}

/**
* Gets the correct Icon for a given {@link EntryType}
*
* @param type {@link EntryType} to get Icon for
* @return Icon corresponding to {@link EntryType}
*/
private static IconTheme.JabRefIcons getIcon(EntryType type) {
EnumSet<StandardEntryType> crossRefTypes = EnumSet.of(StandardEntryType.InBook,
StandardEntryType.InProceedings, StandardEntryType.InCollection);
if (type == StandardEntryType.Book) {
return IconTheme.JabRefIcons.BOOK;
} else if (crossRefTypes.contains(type)) {
return IconTheme.JabRefIcons.OPEN_LINK;
}
return IconTheme.JabRefIcons.ARTICLE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.jabref.gui.entryeditor.citationrelationtab;

import org.jabref.model.entry.BibEntry;

/**
* Class to hold a BibEntry and a boolean value whether it is already in the current database or not.
*/
public class CitationRelationItem {
private final BibEntry entry;
private final boolean isLocal;

public CitationRelationItem(BibEntry entry, boolean isLocal) {
this.entry = entry;
this.isLocal = isLocal;
}

public BibEntry getEntry() {
return entry;
}

public boolean isLocal() {
return isLocal;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.addEntryButton {
-fx-font-size: 2em;
}

.addEntryButton:selected {
-fx-background-color: transparent;
-fx-fill: -jr-selected;
}

.entry-container {
-fx-padding: 0.5em 0em 0.5em 0em;
}

.list-cell:default {
-fx-padding: 0.5em 0.1em 0.5em 0em;
}

.list-cell:selected {
-fx-background-color: derive(-jr-selected, 60%);
}
Loading

0 comments on commit 0c6c0a9

Please # to comment.