FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bugfix in weighted edit-based distances · linearregression/stringdist@0a960c4 · GitHub

Repository navigation

Commit 0a960c4

Browse files
committed
bugfix in weighted edit-based distances
1 parent 788cf5d commit 0a960c4

6 files changed

Lines changed: 29 additions & 7 deletions

File tree

‎pkg/NEWS‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
version 0.9.3
2+
- bugfix in dl, lv, osa distance: weights were not taken into account properly (thanks to Zach Price)
3+
14
version 0.9.2
25
- Update fixing some errors (missing documentation, tests) in the 0.9.1 release.
36
- Fixed a few possible memory leaks.

‎pkg/src/Rstringdist.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ SEXP R_amatch(SEXP x, SEXP table, SEXP method
184184
, p
185185
, q
186186
);
187+
187188
double d = R_PosInf, d1 = R_PosInf;
188189
int index, len_X, len_T;
189190
unsigned int *str;

‎pkg/src/dl.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ double dl_dist(
135135
/* j = tgt index */
136136
for(i=1;i<=x;i++){
137137
uniquePush(dict,src[i]);
138-
scores[(i+1) * (y + 2) + 1] = i;
138+
scores[(i+1) * (y + 2) + 1] = i * weight[0];
139139
scores[(i+1) * (y + 2) + 0] = score_ceil;
140140
swapCount = 0;
141141

142142
for(j=1;j<=y;j++){
143143
if(i == 1) {
144144
uniquePush(dict,tgt[j]);
145-
scores[1 * (y + 2) + (j + 1)] = j;
145+
scores[1 * (y + 2) + (j + 1)] = j * weight[0];
146146
scores[0 * (y + 2) + (j + 1)] = score_ceil;
147147
}
148148
targetCharCount = dict->value[which(dict, tgt[j-1])];

‎pkg/src/lv.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,11 @@ double lv_dist(
4343
int I = na+1, L = na+1, J = nb+1;
4444
double sub;
4545

46-
4746
for ( i = 0; i < I; ++i ){
48-
scores[i] = i;
47+
scores[i] = i * weight[0];
4948
}
5049
for ( j = 1; j < J; ++j, L += I ){
51-
scores[L] = j;
50+
scores[L] = j * weight[0];
5251
}
5352

5453
int M;

‎pkg/src/osa.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ double osa_dist(unsigned int *a, int na, unsigned int *b, int nb, double *weight
4141
double sub, tran;
4242

4343
for ( i = 0; i < I; ++i ){
44-
scores[i] = i;
44+
scores[i] = i * weight[0];
4545
}
4646
for ( j = 1; j < J; ++j, L += I ){
47-
scores[L] = j;
47+
scores[L] = j * weight[0];
4848
}
4949

5050
for ( i = 1; i <= na; ++i ){

‎pkg/tests/testthat/testStringdist.R‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,25 @@ test_that("weights are handled correctly",{
5555
stringdist("abc","ac",method='osa',weight=c(0.5,1,1,1)),
5656
stringdist("ac","abc",method='osa',weight=c(1,0.5,1,1))
5757
)
58+
expect_equal(
59+
stringdist("ABC", "BC", method = "lv", weight = c(i=.1, d=.1, s=.1)),.1
60+
)
61+
expect_equal(
62+
stringdist("ABC", "BC", method = "lv", weight = c(i=.1, d=.1, s=1)),.1
63+
)
64+
65+
expect_equal(
66+
stringdist("ABC", "BC", method = "osa", weight = c(i=.1, d=.1, s=.1,t=.1)),.1
67+
)
68+
expect_equal(
69+
stringdist("ABC", "BC", method = "osa", weight = c(i=.1, d=.1, s=1,t=.1)),.1
70+
)
71+
expect_equal(
72+
stringdist("ABC", "BC", method = "dl", weight = c(i=.1, d=.1, s=.1,t=.1)),.1
73+
)
74+
expect_equal(
75+
stringdist("ABC", "BC", method = "dl", weight = c(i=.1, d=.1, s=1,t=.1)),.1
76+
)
5877
})
5978

6079
test_that("NA's are handled correctly",{

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL