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

Integrity check "Abbreviation Detection" detects abbreviated names for journals and booktitles based on the internal list instead of only looking for "." signs. #3362

Merged
merged 3 commits into from
Nov 5, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Changelog
All notable changes to this project will be documented in this file.
This project **does not** adhere to [Semantic Versioning](http://semver.org/).
Expand Down Expand Up @@ -25,7 +26,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We no longer create a new entry editor when selecting a new entry to increase performance. [#3187](https://github.com/JabRef/jabref/pull/3187)
- We increased performance and decreased the memory footprint of the entry editor drastically. [#3331](https://github.com/JabRef/jabref/pull/3331)
- Late initialization of the context menus in the entry editor. This improves performance and memory footprint further [#3340](https://github.com/JabRef/jabref/pull/3340)

- Integrity check "Abbreviation Detection" detects abbreviated names for journals and booktitles based on the internal list instead of only looking for "." signs. Fixes [#3144](https://github.com/JabRef/jabref/issues/3144).

### Fixed
- We fixed the translation of \textendash in the entry preview [#3307](https://github.com/JabRef/jabref/issues/3307)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecu

AutoCompleteSuggestionProvider<?> suggestionProvider = getSuggestionProvider(fieldName, suggestionProviders, databaseContext.getMetaData());

FieldCheckers fieldCheckers = new FieldCheckers(databaseContext, preferences.getFileDirectoryPreferences());
FieldCheckers fieldCheckers = new FieldCheckers(databaseContext, preferences.getFileDirectoryPreferences(), journalAbbreviationLoader.getRepository(journalAbbreviationPreferences));

if (preferences.getTimestampPreferences().getTimestampField().equals(fieldName) || fieldExtras.contains(FieldProperty.DATE)) {
if (fieldExtras.contains(FieldProperty.ISO_DATE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@

import java.util.Optional;

import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.strings.StringUtil;

public class AbbreviationChecker implements ValueChecker {

private final JournalAbbreviationRepository abbreviationRepository;

public AbbreviationChecker(JournalAbbreviationRepository abbreviationRepository) {
this.abbreviationRepository = abbreviationRepository;
}

@Override
public Optional<String> checkValue(String value) {
if (StringUtil.isBlank(value)) {
return Optional.empty();
}

if (value.contains(".")) {
if (abbreviationRepository.isAbbreviatedName(value)) {
return Optional.of(Localization.lang("abbreviation detected"));
}

Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/jabref/logic/integrity/FieldCheckers.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@
import java.util.List;
import java.util.stream.Collectors;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.FieldName;
import org.jabref.model.entry.InternalBibtexFields;
import org.jabref.model.metadata.FileDirectoryPreferences;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;

public class FieldCheckers {

private Multimap<String, ValueChecker> fieldChecker;

public FieldCheckers(BibDatabaseContext databaseContext, FileDirectoryPreferences fileDirectoryPreferences) {
fieldChecker = getAllMap(databaseContext, fileDirectoryPreferences);
public FieldCheckers(BibDatabaseContext databaseContext, FileDirectoryPreferences fileDirectoryPreferences, JournalAbbreviationRepository abbreviationRepository) {
fieldChecker = getAllMap(databaseContext, fileDirectoryPreferences, abbreviationRepository);
}

private static Multimap<String, ValueChecker> getAllMap(BibDatabaseContext databaseContext, FileDirectoryPreferences fileDirectoryPreferences) {
private static Multimap<String, ValueChecker> getAllMap(BibDatabaseContext databaseContext, FileDirectoryPreferences fileDirectoryPreferences, JournalAbbreviationRepository abbreviationRepository) {
ArrayListMultimap<String, ValueChecker> fieldCheckers = ArrayListMultimap.create(50, 10);

for (String field : InternalBibtexFields.getJournalNameFields()) {
fieldCheckers.put(field, new AbbreviationChecker());
fieldCheckers.put(field, new AbbreviationChecker(abbreviationRepository));
}
for (String field : InternalBibtexFields.getBookNameFields()) {
fieldCheckers.put(field, new AbbreviationChecker());
fieldCheckers.put(field, new AbbreviationChecker(abbreviationRepository));
}
for (String field : InternalBibtexFields.getPersonNameFields()) {
fieldCheckers.put(field, new PersonNamesChecker(databaseContext));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private List<IntegrityMessage> checkBibtexEntry(BibEntry entry) {
return result;
}

FieldCheckers fieldCheckers = new FieldCheckers(bibDatabaseContext, fileDirectoryPreferences);
FieldCheckers fieldCheckers = new FieldCheckers(bibDatabaseContext, fileDirectoryPreferences, journalAbbreviationRepository);
for (FieldChecker checker : fieldCheckers.getAll()) {
result.addAll(checker.check(entry));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@ public void testTitleChecks() {
@Test
public void testAbbreviationChecks() {
for (String field : Arrays.asList("booktitle", "journal")) {
assertCorrect(createContext(field, "IEEE SW"));
assertWrong(createContext(field, "Proc. of the"));
assertCorrect(createContext(field, "IEEE Software"));
assertCorrect(createContext(field, ""));
assertWrong(createContext(field, "IEEE SW"));
}
}

Expand Down