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

Refactor to meet line length standard #4

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.jabref.logic.util.strings;

import java.util.Locale;

import info.debatty.java.stringsimilarity.Levenshtein;

import java.util.Locale;

public class StringSimilarity {
private final Levenshtein METRIC_DISTANCE = new Levenshtein();
// edit distance threshold for entry title comparison
Expand All @@ -22,6 +22,8 @@ public boolean isSimilar(String a, String b) {

public double editDistanceIgnoreCase(String a, String b) {
// TODO: Locale is dependent on the language of the strings. English is a good denominator.
return METRIC_DISTANCE.distance(a.toLowerCase(Locale.ENGLISH), b.toLowerCase(Locale.ENGLISH));
a = a.toLowerCase(Locale.ENGLISH);
b = b.toLowerCase(Locale.ENGLISH);
return METRIC_DISTANCE.distance(a, b);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.jabref.logic.util.strings;

import org.junit.Test;
import org.junit.Before;

import static org.junit.jupiter.api.Assertions.*;

public class StringSimilarityTest {

private StringSimilarity sut;

@Before
public void setup() {
sut = new StringSimilarity();
}

@Test
public void givenIdenticalStrings_whenIsSimilarMethod_thenReturnTrue() {
String a = "Hello";
String b = "Hello";
assertTrue(sut.isSimilar(a, b));
}

@Test
public void givenIdenticalStrings_whenEditDistanceIgnoreCaseMethod_thenReturnZero() {
String a = "A";
String b = "A";
assertEquals(0.0, sut.editDistanceIgnoreCase(a, b));
}

@Test
public void givenSlightlyDifferentStrings_whenEditDistanceIgnoreCaseMethod_thenReturnLevenshteinDistance() {
String a = "Abc";
String b = "Bbc";
assertEquals(1.0, sut.editDistanceIgnoreCase(a,b));
}

@Test
public void givenVeryDifferentStrings_whenEditDistanceIgnoreCaseMethod_thenReturnLevenshteinDistance() {
String a = "Fish";
String b = "Bears";
assertEquals(5.0, sut.editDistanceIgnoreCase(a,b));
}

@Test
public void givenDissimilarStrings_whenIsSimilarMethod_thenReturnFalse() {
String a = "Johnson";
String b = "Daghtsen";
System.out.println(sut.editDistanceIgnoreCase(a,b));
assertFalse(sut.isSimilar(a,b));
}

}