From c494b6957c07052cb3751deb5b992a74252d395e Mon Sep 17 00:00:00 2001 From: djvanderlaan Date: Wed, 14 Oct 2015 14:47:47 +0200 Subject: [PATCH 1/2] Fix for bug #43 --- pkg/src/jaro.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/src/jaro.c b/pkg/src/jaro.c index 9988533..b3c18b1 100644 --- a/pkg/src/jaro.c +++ b/pkg/src/jaro.c @@ -122,7 +122,8 @@ double jaro_winkler_dist( if ( m < 1 ){ d = 1.0; } else { - d = 1.0 - (1.0/3.0)*(w[0]*m/((double) x) + w[1]*m/((double) y) + w[2]*(m-t)/m); + double tot_weight = w[0] + w[1] + w[2]; + d = 1.0 - (1.0/tot_weight)*(w[0]*m/((double) x) + w[1]*m/((double) y) + w[2]*(m-t)/m); } // Winkler's penalty factor From 2b60c9d2c39012d354aa3522973b2d0f2e88889d Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 14 Oct 2015 17:12:46 +0200 Subject: [PATCH 2/2] fixed tests for weighted jaro distance --- pkg/tests/testthat/testStringdist.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/tests/testthat/testStringdist.R b/pkg/tests/testthat/testStringdist.R index 17b41b4..abb75cb 100644 --- a/pkg/tests/testthat/testStringdist.R +++ b/pkg/tests/testthat/testStringdist.R @@ -324,15 +324,15 @@ test_that("Extended examples work",{ # idem, with weights expect_equal( round(1 - stringdist("crate","trace",metho='jw',weight=c(0.5,1,1)),8), - round((0.5*3/5 + 3/5 + (3-0)/3)/3,8) + round((0.5*3/5 + 3/5 + (3-0)/3)/2.5,8) ) expect_equal( round(1 - stringdist("crate","trace",metho='jw',weight=c(1,0.5,1)),8), - round((3/5 + 0.5*3/5 + (3-0)/3)/3,8) + round((3/5 + 0.5*3/5 + (3-0)/3)/2.5,8) ) expect_equal( round(1 - stringdist("crate","trace",metho='jw',weight=c(1,1,0.5)),8), - round((3/5 + 3/5 + 0.5*(3-0)/3)/3,8) + round((3/5 + 3/5 + 0.5*(3-0)/3)/2.5,8) ) # Other cases