diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b388a96140..1fe422a112f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We fixed an issue where in rare cases entries where overlayed in the main table. https://github.com/JabRef/jabref/issues/3281 - We fixed an issue where selecting a group messed up the focus of the main table / entry editor. https://github.com/JabRef/jabref/issues/3367 - We fixed an issue where composite author names were sorted incorrectly. https://github.com/JabRef/jabref/issues/2828 +- We fixed an issue where some journal names were wrongly marked as abbreviated. [#4115](https://github.com/JabRef/jabref/issues/4115) - We fixed an issue where the custom file column were sorted incorrectly. https://github.com/JabRef/jabref/issues/3119 - We fixed an issues where the entry losses focus when a field is edited and at the same time used for sorting. https://github.com/JabRef/jabref/issues/3373 - We fixed an issue where the menu on Mac OS was not displayed in the usual Mac-specific way. https://github.com/JabRef/jabref/issues/3146 diff --git a/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java b/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java index 72a90329e4b..68bc4c17370 100644 --- a/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java +++ b/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java @@ -27,18 +27,28 @@ private static boolean isMatched(String name, Abbreviation abbreviation) { } private static boolean isMatchedAbbreviated(String name, Abbreviation abbreviation) { - return name.equalsIgnoreCase(abbreviation.getIsoAbbreviation()) + boolean isAbbreviated = name.equalsIgnoreCase(abbreviation.getIsoAbbreviation()) || name.equalsIgnoreCase(abbreviation.getMedlineAbbreviation()); + boolean isExpanded = name.equalsIgnoreCase(abbreviation.getName()); + return isAbbreviated && !isExpanded; } public int size() { return abbreviations.size(); } + /** + * Returns true if the given journal name is contained in the list either in its full form (e.g Physical Review + * Letters) or its abbreviated form (e.g. Phys. Rev. Lett.). + */ public boolean isKnownName(String journalName) { return abbreviations.stream().anyMatch(abbreviation -> isMatched(journalName.trim(), abbreviation)); } + /** + * Returns true if the given journal name is in its abbreviated form (e.g. Phys. Rev. Lett.). The test is strict, + * i.e. journals whose abbreviation is the same as the full name are not considered + */ public boolean isAbbreviatedName(String journalName) { return abbreviations.stream().anyMatch(abbreviation -> isMatchedAbbreviated(journalName.trim(), abbreviation)); } diff --git a/src/test/java/org/jabref/logic/integrity/AbbreviationCheckerTest.java b/src/test/java/org/jabref/logic/integrity/AbbreviationCheckerTest.java new file mode 100644 index 00000000000..033bdbe98d1 --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/AbbreviationCheckerTest.java @@ -0,0 +1,35 @@ +package org.jabref.logic.integrity; + +import java.util.Optional; + +import org.jabref.logic.journals.Abbreviation; +import org.jabref.logic.journals.JournalAbbreviationRepository; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +class AbbreviationCheckerTest { + + private JournalAbbreviationRepository abbreviationRepository; + private AbbreviationChecker checker; + + @BeforeEach + void setUp() { + abbreviationRepository = new JournalAbbreviationRepository(new Abbreviation("Test Journal", "T. J.")); + checker = new AbbreviationChecker(abbreviationRepository); + } + + @Test + void checkValueComplainsAboutAbbreviatedJournalName() { + assertNotEquals(Optional.empty(), checker.checkValue("T. J.")); + } + + @Test + void checkValueDoesNotComplainAboutJournalNameThatHasSameAbbreviation() { + abbreviationRepository.addEntry(new Abbreviation("Journal", "Journal")); + assertEquals(Optional.empty(), checker.checkValue("Journal")); + } +}