Skip to content

Commit

Permalink
Bring back a modified ISBN check and add more tests (JabRef#11217)
Browse files Browse the repository at this point in the history
* Bring back a modified ISBN check and add more tests

Signed-off-by: AbdAlRahmanGad <[email protected]>

* Reformulate the ISBN check.

Signed-off-by: AbdAlRahmanGad <[email protected]>

* Change order of conditions for more readability

Signed-off-by: AbdAlRahmanGad <[email protected]>

---------

Signed-off-by: AbdAlRahmanGad <[email protected]>
  • Loading branch information
AbdAlRahmanGad authored Apr 18, 2024
1 parent 3f81c1d commit 2b5fddd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/org/jabref/logic/database/DuplicateCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
Expand All @@ -25,6 +26,8 @@
import org.jabref.model.entry.field.OrFields;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.identifier.DOI;
import org.jabref.model.entry.identifier.ISBN;
import org.jabref.model.entry.types.StandardEntryType;
import org.jabref.model.strings.StringUtil;

import com.google.common.collect.Sets;
Expand Down Expand Up @@ -337,6 +340,16 @@ public boolean isDuplicate(final BibEntry one, final BibEntry two, final BibData
return false;
}

// In case an ISBN is present, it is a strong indicator that the entries are equal.
// Only in InBook, InCollection, or Article the ISBN may be equal and the puplication on different pages (and thus not equal)
Optional<ISBN> oneISBN = one.getISBN();
Optional<ISBN> twoISBN = two.getISBN();
if (oneISBN.isPresent() && twoISBN.isPresent()
&& Objects.equals(oneISBN, twoISBN)
&& !List.of(StandardEntryType.Article, StandardEntryType.InBook, StandardEntryType.InCollection).contains(one.getType())) {
return true;
}

final Optional<BibEntryType> type = entryTypesManager.enrich(one.getType(), bibDatabaseMode);
if (type.isPresent()) {
BibEntryType entryType = type.get();
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/org/jabref/logic/database/DuplicateCheckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -555,4 +555,30 @@ void differentArticlesFromTheSameBookAreNotDuplicates() {

assertFalse(duplicateChecker.isDuplicate(entryOne, entryTwo, BibDatabaseMode.BIBTEX));
}

@Test
void differentInbooksWithTheSameISBNAreNotDuplicates() {
BibEntry entryOne = new BibEntry(StandardEntryType.InBook)
.withField(StandardField.TITLE, "Performance on a Signal")
.withField(StandardField.ISBN, "978-1-4684-8585-1");

BibEntry entryTwo = new BibEntry(StandardEntryType.InBook)
.withField(StandardField.TITLE, "Rest in Treatment")
.withField(StandardField.ISBN, "978-1-4684-8585-1");

assertFalse(duplicateChecker.isDuplicate(entryOne, entryTwo, BibDatabaseMode.BIBTEX));
}

@Test
void differentInCollectionWithTheSameISBNAreNotDuplicates() {
BibEntry entryOne = new BibEntry(StandardEntryType.InCollection)
.withField(StandardField.TITLE, "Performance on a Signal")
.withField(StandardField.ISBN, "978-1-4684-8585-1");

BibEntry entryTwo = new BibEntry(StandardEntryType.InCollection)
.withField(StandardField.TITLE, "Rest in Treatment")
.withField(StandardField.ISBN, "978-1-4684-8585-1");

assertFalse(duplicateChecker.isDuplicate(entryOne, entryTwo, BibDatabaseMode.BIBTEX));
}
}

0 comments on commit 2b5fddd

Please sign in to comment.