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

Rework journal abbreviation caching #6304

Merged
merged 13 commits into from
May 1, 2020
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

- We removed the obsolete `External programs / Open PDF` section in the preferences, as the default application to open PDFs is now set in the `Manage external file types` dialog. [#6130](https://github.com/JabRef/jabref/pull/6130)
- We removed the option to configure whether a `.bib.bak` file should be generated upon save. It is now always enabled. Documentation at <https://docs.jabref.org/general/autosave>. [#6092](https://github.com/JabRef/jabref/issues/6092)
- We removed the built-in list of IEEE journal abbreviations using BibTeX strings. If you still want to use them, you have to download them separately from <https://abbrv.jabref.org>.

## [5.0] – 2020-03-06

Expand Down
22 changes: 13 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import groovy.json.JsonSlurper
import org.gradle.internal.os.OperatingSystem
import org.jabref.build.JournalAbbreviationConverter
import org.jabref.build.antlr.JabRefAntlrPlugin
import org.jabref.build.localization.LocalizationPlugin
import org.jabref.build.xjc.XjcPlugin
Expand All @@ -8,13 +9,6 @@ import org.jabref.build.xjc.XjcTask
// to update the gradle wrapper, execute
// ./gradlew wrapper --gradle-version=6.0 --distribution-type=bin

buildscript {
repositories {
mavenLocal()
jcenter()
}
}

plugins {
id 'application'
id "com.simonharrer.modernizer" version '1.8.0-1'
Expand Down Expand Up @@ -116,6 +110,7 @@ dependencies {
implementation 'org.apache.pdfbox:xmpbox:2.0.19'

implementation group: 'org.apache.commons', name: 'commons-csv', version: '1.8'
implementation 'com.h2database:h2-mvstore:1.4.200'

implementation group: 'org.apache.tika', name: 'tika-core', version: '1.24'

Expand Down Expand Up @@ -297,9 +292,10 @@ task generateSource(dependsOn: ["generateBstGrammarSource",
"generateMedlineSource",
"generateBibtexmlSource",
"generateEndnoteSource",
"generateModsSource"]) {
"generateModsSource",
"generateJournalAbbreviationList"]) {
group = 'JabRef'
description 'Generates all Java source files.'
description 'Generates all necessary (Java) source files.'
}

task generateBstGrammarSource(type: org.jabref.build.antlr.AntlrTask) {
Expand Down Expand Up @@ -359,6 +355,14 @@ task generateModsSource(type: XjcTask) {
arguments = '-npa'
}

task generateJournalAbbreviationList(type: JournalAbbreviationConverter) {
group = 'JabRef'
description = "Converts the comma-separated journal abbreviation file to a H2 MVStore."

inputDir = file("src/main/resources/journals")
outputDir = file("src/main/resources/journals")
}

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
Expand Down
19 changes: 19 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apply plugin: 'java'

repositories {
jcenter()
}

dependencies {
compile 'com.h2database:h2-mvstore:1.4.200'
compile 'org.apache.commons:commons-csv:1.8'
compile 'org.slf4j:slf4j-api:2.0.0-alpha1'
}

sourceSets{
main {
java {
srcDir "${project.rootDir}/../src/main/java/org/jabref/logic/journals"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.jabref.build

import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.tasks.*
import org.h2.mvstore.MVMap
import org.h2.mvstore.MVStore
import org.jabref.logic.journals.JournalAbbreviationLoader

import java.util.stream.Collectors

abstract class JournalAbbreviationConverter extends DefaultTask {
@PathSensitive(PathSensitivity.NAME_ONLY)
@InputDirectory
abstract DirectoryProperty getInputDir()

@OutputDirectory
abstract DirectoryProperty getOutputDir()

@TaskAction
def convert() {
def targetFile = outputDir.file("journalList.mv").get().asFile
targetFile.delete()
MVStore.open(targetFile.toString()).withCloseable { store ->
MVMap<String, String> fullToAbbreviation = store.openMap("FullToAbbreviation")
MVMap<String, String> abbreviationToFull = store.openMap("AbbreviationToFull")

inputDir.getAsFileTree().filter({ File f -> f.name.endsWith(".csv") }).getFiles().each { file ->
def abbreviations = JournalAbbreviationLoader.readJournalListFromFile(file.toPath())
fullToAbbreviation.putAll(
abbreviations
.stream()
.collect(Collectors.toMap({ abbreviation -> abbreviation.getName() }, { abbreviation -> abbreviation.getAbbreviation() }))
)

abbreviations
.forEach({ abbreviation ->
abbreviationToFull.putIfAbsent(abbreviation.getAbbreviation(), abbreviation.getName())
})
}
}
}
}
24 changes: 24 additions & 0 deletions docs/adr/0010-use-h2-as-internal-database.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Use H2 as Internal SQL Database

## Context and Problem Statement

We need to store data internally in a structured way to gain performance.

## Decision Drivers

* Easy to integrate
* Easy to use
* Common technology

## Considered Options

* [H2 Database Engine](http://www.h2database.com/html/main.html)
* [SQLite](https://www.sqlite.org/index.html)

## Decision Outcome

Chosen option: "H2 Database Engine", because it was straight-forward to use.

## Links

* [Comparison at SQL Workbench](https://www.sql-workbench.eu/dbms_comparison.html)
1 change: 1 addition & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,5 @@
requires flexmark.ext.gfm.tasklist;
requires flexmark.util.ast;
requires flexmark.util.data;
requires com.h2database.mvstore;
}
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.jabref.gui.util.ThemeLoader;
import org.jabref.logic.exporter.ExporterFactory;
import org.jabref.logic.importer.ImportFormatReader;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.protectedterms.ProtectedTermsLoader;
import org.jabref.logic.remote.server.RemoteListenerServerLifecycle;
import org.jabref.logic.util.BuildInfo;
Expand Down Expand Up @@ -56,7 +56,7 @@ public class Globals {
* This field is initialized upon startup.
* Only GUI code is allowed to access it, logic code should use dependency injection.
*/
public static JournalAbbreviationLoader journalAbbreviationLoader;
public static JournalAbbreviationRepository journalAbbreviationRepository;

/**
* This field is initialized upon startup.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ private static boolean handleMultipleAppInstances(String[] args) {

private static void applyPreferences(JabRefPreferences preferences) {
// Read list(s) of journal names and abbreviations
Globals.journalAbbreviationLoader = new JournalAbbreviationLoader();
Globals.journalAbbreviationRepository = JournalAbbreviationLoader.loadRepository(Globals.prefs.getJournalAbbreviationPreferences());

// Build list of Import and Export formats
Globals.IMPORT_FORMAT_READER.resetImportFormats(Globals.prefs.getImportFormatPreferences(),
Globals.prefs.getXMPPreferences(), Globals.getFileUpdateMonitor());
Globals.entryTypesManager.addCustomOrModifiedTypes(preferences.loadBibEntryTypes(BibDatabaseMode.BIBTEX),
preferences.loadBibEntryTypes(BibDatabaseMode.BIBLATEX));
Globals.exportFactory = Globals.prefs.getExporterFactory(Globals.journalAbbreviationLoader);
Globals.exportFactory = Globals.prefs.getExporterFactory(Globals.journalAbbreviationRepository);

// Initialize protected terms loader
Globals.protectedTermsLoader = new ProtectedTermsLoader(Globals.prefs.getProtectedTermsPreferences());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,9 @@ private void importPreferences() {
Globals.prefs.importPreferences(cli.getPreferencesImport());
Globals.entryTypesManager.addCustomOrModifiedTypes(Globals.prefs.loadBibEntryTypes(BibDatabaseMode.BIBTEX),
Globals.prefs.loadBibEntryTypes(BibDatabaseMode.BIBLATEX));
List<TemplateExporter> customExporters = Globals.prefs.getCustomExportFormats(Globals.journalAbbreviationLoader);
List<TemplateExporter> customExporters = Globals.prefs.getCustomExportFormats(Globals.journalAbbreviationRepository);
LayoutFormatterPreferences layoutPreferences = Globals.prefs
.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader);
.getLayoutFormatterPreferences(Globals.journalAbbreviationRepository);
SavePreferences savePreferences = Globals.prefs.loadForExportFromPreferences();
XmpPreferences xmpPreferences = Globals.prefs.getXMPPreferences();
Globals.exportFactory = ExporterFactory.create(customExporters, layoutPreferences, savePreferences, xmpPreferences);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public void setupMainPanel() {
private void setupAutoCompletion() {
AutoCompletePreferences autoCompletePreferences = preferences.getAutoCompletePreferences();
if (autoCompletePreferences.shouldAutoComplete()) {
suggestionProviders = new SuggestionProviders(getDatabase(), autoCompletePreferences, Globals.journalAbbreviationLoader);
suggestionProviders = new SuggestionProviders(getDatabase(), Globals.journalAbbreviationRepository);
} else {
// Create empty suggestion providers if auto completion is deactivated
suggestionProviders = new SuggestionProviders();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/gui/DefaultInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.jabref.JabRefGUI;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.protectedterms.ProtectedTermsLoader;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.PreferencesService;
Expand Down Expand Up @@ -36,8 +36,8 @@ private static Object createDependency(Class<?> clazz) {
return Globals.prefs;
} else if (clazz == KeyBindingRepository.class) {
return Globals.getKeyPrefs();
} else if (clazz == JournalAbbreviationLoader.class) {
return Globals.journalAbbreviationLoader;
} else if (clazz == JournalAbbreviationRepository.class) {
return Globals.journalAbbreviationRepository;
} else if (clazz == StateManager.class) {
return Globals.stateManager;
} else if (clazz == FileUpdateMonitor.class) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -770,11 +770,11 @@ private MenuBar createMenu() {
new SeparatorMenuItem(),

factory.createSubMenu(StandardActions.ABBREVIATE,
factory.createMenuItem(StandardActions.ABBREVIATE_DEFAULT, new AbbreviateAction(StandardActions.ABBREVIATE_DEFAULT, this, dialogService, stateManager, prefs)),
factory.createMenuItem(StandardActions.ABBREVIATE_MEDLINE, new AbbreviateAction(StandardActions.ABBREVIATE_MEDLINE, this, dialogService, stateManager, prefs)),
factory.createMenuItem(StandardActions.ABBREVIATE_SHORTEST_UNIQUE, new AbbreviateAction(StandardActions.ABBREVIATE_SHORTEST_UNIQUE, this, dialogService, stateManager, prefs))),
factory.createMenuItem(StandardActions.ABBREVIATE_DEFAULT, new AbbreviateAction(StandardActions.ABBREVIATE_DEFAULT, this, dialogService, stateManager)),
factory.createMenuItem(StandardActions.ABBREVIATE_MEDLINE, new AbbreviateAction(StandardActions.ABBREVIATE_MEDLINE, this, dialogService, stateManager)),
factory.createMenuItem(StandardActions.ABBREVIATE_SHORTEST_UNIQUE, new AbbreviateAction(StandardActions.ABBREVIATE_SHORTEST_UNIQUE, this, dialogService, stateManager))),

factory.createMenuItem(StandardActions.UNABBREVIATE, new AbbreviateAction(StandardActions.UNABBREVIATE, this, dialogService, stateManager, prefs))
factory.createMenuItem(StandardActions.UNABBREVIATE, new AbbreviateAction(StandardActions.UNABBREVIATE, this, dialogService, stateManager))
);

Menu lookupIdentifiers = factory.createSubMenu(StandardActions.LOOKUP_DOC_IDENTIFIER);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
package org.jabref.gui.autocompleter;

import org.jabref.logic.journals.JournalAbbreviationLoader;
import java.util.stream.Stream;

import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.entry.field.Field;

import com.google.common.collect.Streams;

public class JournalsSuggestionProvider extends FieldValueSuggestionProvider {

JournalsSuggestionProvider(Field field, BibDatabase database, AutoCompletePreferences preferences,
JournalAbbreviationLoader abbreviationLoader) {
private final JournalAbbreviationRepository repository;

JournalsSuggestionProvider(Field field, BibDatabase database, JournalAbbreviationRepository repository) {
super(field, database);

/*
TODO: Reenable
this.repository = repository;
}

JournalAbbreviationPreferences journalAbbreviationPreferences = preferences.getJournalAbbreviationPreferences();
List<String> journals = abbreviationLoader.getRepository(journalAbbreviationPreferences)
.getAbbreviations().stream()
.map(Abbreviation::getName)
.collect(Collectors.toList());
addPossibleSuggestions(journals);
*/
@Override
public Stream<String> getSource() {
return Streams.concat(super.getSource(), repository.getFullNames().stream());
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.jabref.gui.autocompleter;

import java.util.Objects;
import java.util.Set;

import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.FieldProperty;
Expand All @@ -13,13 +12,11 @@ public class SuggestionProviders {

private final boolean isEmpty;
private BibDatabase database;
private AutoCompletePreferences preferences;
private JournalAbbreviationLoader abbreviationLoader;
private JournalAbbreviationRepository abbreviationRepository;

public SuggestionProviders(BibDatabase database, AutoCompletePreferences preferences, JournalAbbreviationLoader abbreviationLoader) {
public SuggestionProviders(BibDatabase database, JournalAbbreviationRepository abbreviationRepository) {
this.database = database;
this.preferences = Objects.requireNonNull(preferences);
this.abbreviationLoader = abbreviationLoader;
this.abbreviationRepository = abbreviationRepository;
this.isEmpty = false;
}

Expand All @@ -39,7 +36,7 @@ public SuggestionProvider<?> getForField(Field field) {
return new BibEntrySuggestionProvider(database);
} else if (fieldProperties.contains(FieldProperty.JOURNAL_NAME)
|| StandardField.PUBLISHER.equals(field)) {
return new JournalsSuggestionProvider(field, database, preferences, abbreviationLoader);
return new JournalsSuggestionProvider(field, database, abbreviationRepository);
} else {
return new WordSuggestionProvider(field, database);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/cleanup/CleanupAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private void doCleanup(BibDatabaseContext databaseContext, CleanupPreset preset,
// Create and run cleaner
CleanupWorker cleaner = new CleanupWorker(
databaseContext,
preferences.getCleanupPreferences(Globals.journalAbbreviationLoader));
preferences.getCleanupPreferences(Globals.journalAbbreviationRepository));

List<FieldChange> changes = cleaner.cleanup(preset, entry);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/edit/CopyMoreAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private void copyKeyAndTitle() {
StringReader layoutString = new StringReader("\\bibtexkey - \\begin{title}\\format[RemoveBrackets]{\\title}\\end{title}\n");
Layout layout;
try {
layout = new LayoutHelper(layoutString, preferencesService.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader)).getLayoutFromText();
layout = new LayoutHelper(layoutString, preferencesService.getLayoutFormatterPreferences(Globals.journalAbbreviationRepository)).getLayoutFromText();
} catch (IOException e) {
LOGGER.info("Could not get layout.", e);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
Expand All @@ -29,8 +29,8 @@ public class DeprecatedFieldsTab extends FieldsEditorTab {

private final BibEntryTypesManager entryTypesManager;

public DeprecatedFieldsTab(BibDatabaseContext databaseContext, SuggestionProviders suggestionProviders, UndoManager undoManager, DialogService dialogService, JabRefPreferences preferences, BibEntryTypesManager entryTypesManager, ExternalFileTypes externalFileTypes, TaskExecutor taskExecutor, JournalAbbreviationLoader journalAbbreviationLoader) {
super(false, databaseContext, suggestionProviders, undoManager, dialogService, preferences, externalFileTypes, taskExecutor, journalAbbreviationLoader);
public DeprecatedFieldsTab(BibDatabaseContext databaseContext, SuggestionProviders suggestionProviders, UndoManager undoManager, DialogService dialogService, JabRefPreferences preferences, BibEntryTypesManager entryTypesManager, ExternalFileTypes externalFileTypes, TaskExecutor taskExecutor, JournalAbbreviationRepository journalAbbreviationRepository) {
super(false, databaseContext, suggestionProviders, undoManager, dialogService, preferences, externalFileTypes, taskExecutor, journalAbbreviationRepository);
this.entryTypesManager = entryTypesManager;

setText(Localization.lang("Deprecated fields"));
Expand Down
Loading