Skip to content

Commit

Permalink
Add DOI matching with not full coincidence.
Browse files Browse the repository at this point in the history
  • Loading branch information
KunAndrew committed Aug 8, 2020
1 parent 04a8d3e commit 6c8b7d7
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/main/java/org/jabref/logic/bibtex/DuplicateCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,15 @@ public boolean isDuplicate(final BibEntry one, final BibEntry two, final BibData
return true;
}

// check DOI
if (one.getDOI().isPresent() && two.getDOI().isPresent() && one.getDOI().get().isCompareNotExact(two.getDOI().get())) {
return true;
}
// check ISBN
if (one.getISBN().isPresent() && two.getISBN().isPresent() && one.getISBN().get().equals(two.getISBN().get())) {
return true;
}

if (haveDifferentEntryType(one, two) ||
haveDifferentEditions(one, two) ||
haveDifferentChaptersOrPagesOfTheSameBook(one, two)) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/jabref/model/entry/BibEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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.EntryType;
import org.jabref.model.entry.types.IEEETranEntryType;
import org.jabref.model.entry.types.StandardEntryType;
Expand Down Expand Up @@ -459,6 +460,10 @@ public Optional<DOI> getDOI() {
return getField(StandardField.DOI).flatMap(DOI::parse);
}

public Optional<ISBN> getISBN() {
return getField(StandardField.ISBN).flatMap(ISBN::parse);
}

/**
* Return the LaTeX-free contents of the given field or its alias an an Optional
* <p>
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/jabref/model/entry/identifier/DOI.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ public String getNormalized() {
return doi;
}

public boolean isCompareNotExact(DOI o2) {
String s1 = this.doi.replaceAll("[^\\w]", "");
String s2 = o2.doi.replaceAll("[^\\w]", "");
return s1.equalsIgnoreCase(s2);
}

/**
* DOIs are case-insensitive. Thus, 10.1109/cloud.2017.89 equals 10.1109/CLOUD.2017.89
*/
Expand All @@ -253,5 +259,4 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(doi.toLowerCase(Locale.ENGLISH));
}

}
18 changes: 18 additions & 0 deletions src/main/java/org/jabref/model/entry/identifier/ISBN.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -106,4 +107,21 @@ public Optional<URI> getExternalURI() {
return Optional.empty();
}
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if ((o == null) || (getClass() != o.getClass())) {
return false;
}
ISBN other = (ISBN) o;
return isbnString.equalsIgnoreCase(other.isbnString);
}

@Override
public int hashCode() {
return Objects.hash(isbnString.toLowerCase(Locale.ENGLISH));
}
}
19 changes: 19 additions & 0 deletions src/test/java/org/jabref/logic/bibtex/DuplicateCheckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,25 @@ public void twoEntriesWithSameDoiButDifferentTypesAreDuplicates() {
assertTrue(duplicateChecker.isDuplicate(simpleArticle, duplicateWithDifferentType, BibDatabaseMode.BIBTEX));
}

@Test
public void twoEntriesWithSameDoiButDifferentTypesAreDuplicates2() {
simpleArticle.setField(StandardField.DOI, "10.1016/j.is.2004.02.002");
unrelatedArticle.setField(StandardField.DOI, "10.1016/j.is.2004.02.0\\02");
BibEntry duplicateWithDifferentType = (BibEntry) unrelatedArticle;
duplicateWithDifferentType.setType(StandardEntryType.InCollection);

assertTrue(duplicateChecker.isDuplicate(simpleArticle, duplicateWithDifferentType, BibDatabaseMode.BIBTEX));
}
@Test
public void twoEntriesWithSameISBNButDifferentTypesAreDuplicates() {
simpleArticle.setField(StandardField.ISBN, "0-123456-47-9");
unrelatedArticle.setField(StandardField.ISBN, "0-123456-47-9");
BibEntry duplicateWithDifferentType = (BibEntry) unrelatedArticle;
duplicateWithDifferentType.setType(StandardEntryType.InCollection);

assertTrue(duplicateChecker.isDuplicate(simpleArticle, duplicateWithDifferentType, BibDatabaseMode.BIBTEX));
}

@Test
public void twoInbooksWithDifferentChaptersAreNotDuplicates() {
twoEntriesWithDifferentSpecificFieldsAreNotDuplicates(simpleInbook, StandardField.CHAPTER,
Expand Down

0 comments on commit 6c8b7d7

Please sign in to comment.