Skip to content
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
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ The <action> type attribute can be add,update,fix,remove.
</properties>
<body>
<release version="1.9.1" date="202Y-MM-DD" description="Release 1.9.1. Requires Java 8.">
<action issue="TEXT-158" type="fix" dev="kinow">Incorrect values for Jaccard similarity with empty strings</action>
<action issue="TEXT-185" type="add" dev="ggregory" due-to="Larry West, Gary Gregory">Release Notes page hasn't been updated for 1.9 release yet.</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Update spotbugs.plugin.version 4.0.0 to 4.0.4.</action>
</release>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public Double apply(final CharSequence left, final CharSequence right) {
private Double calculateJaccardSimilarity(final CharSequence left, final CharSequence right) {
final int leftLength = left.length();
final int rightLength = right.length();
if (leftLength == 0 && rightLength == 0) {
return 1d;
}
if (leftLength == 0 || rightLength == 0) {
return 0d;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void setUp() {
@Test
public void testGettingJaccardDistance() {
// Expected Jaccard distance = 1.0 - (intersect / union)
assertEquals(1.0, classBeingTested.apply("", ""));
assertEquals(0.0, classBeingTested.apply("", ""));
assertEquals(1.0, classBeingTested.apply("left", ""));
assertEquals(1.0, classBeingTested.apply("", "right"));
assertEquals(1.0 - (3.0 / 4), classBeingTested.apply("frog", "fog"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void setUp() {
@Test
public void testGettingJaccardSimilarity() {
// Expected Jaccard similarity = (intersect / union)
assertEquals(0.0, classBeingTested.apply("", ""));
assertEquals(1.0, classBeingTested.apply("", ""));
assertEquals(0.0, classBeingTested.apply("left", ""));
assertEquals(0.0, classBeingTested.apply("", "right"));
assertEquals(3.0 / 4, classBeingTested.apply("frog", "fog"));
Expand Down