don't create vector of characters
parent
0a72cd60ee
commit
85740599e8
|
@ -164,13 +164,16 @@ function evaluate(dist::Jaro, s1::AbstractString, s2::AbstractString)
|
||||||
# if both are empty, m = 0 so should be 1.0 according to wikipedia. Add this line so that not the case
|
# if both are empty, m = 0 so should be 1.0 according to wikipedia. Add this line so that not the case
|
||||||
len2 == 0 && return 0.0
|
len2 == 0 && return 0.0
|
||||||
maxdist = max(0, div(len2, 2) - 1)
|
maxdist = max(0, div(len2, 2) - 1)
|
||||||
m = 0 # matching characters
|
# count m matching characters
|
||||||
|
m = 0
|
||||||
flag = fill(false, len2)
|
flag = fill(false, len2)
|
||||||
i1 = 0
|
i1 = 0
|
||||||
|
state1 = start(s1)
|
||||||
startstate2 = start(s2)
|
startstate2 = start(s2)
|
||||||
starti2 = 0
|
starti2 = 0
|
||||||
c = Vector{Char}()
|
i1_match = fill!(Array{typeof(state1)}(len1), state1)
|
||||||
for ch1 in s1
|
while !done(s1, state1)
|
||||||
|
ch1, newstate1 = next(s1, state1)
|
||||||
i1 += 1
|
i1 += 1
|
||||||
if starti2 < i1 - maxdist - 1
|
if starti2 < i1 - maxdist - 1
|
||||||
startstate2 = nextind(s2, startstate2)
|
startstate2 = nextind(s2, startstate2)
|
||||||
|
@ -184,12 +187,13 @@ function evaluate(dist::Jaro, s1::AbstractString, s2::AbstractString)
|
||||||
if ch1 == ch2 && !flag[i2]
|
if ch1 == ch2 && !flag[i2]
|
||||||
m += 1
|
m += 1
|
||||||
flag[i2] = true
|
flag[i2] = true
|
||||||
push!(c, ch1)
|
i1_match[m] = state1
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
state1 = newstate1
|
||||||
end
|
end
|
||||||
# count transpotsitions
|
# count t transpotsitions
|
||||||
t = 0
|
t = 0
|
||||||
i1 = 0
|
i1 = 0
|
||||||
i2 = 0
|
i2 = 0
|
||||||
|
@ -197,7 +201,7 @@ function evaluate(dist::Jaro, s1::AbstractString, s2::AbstractString)
|
||||||
i2 += 1
|
i2 += 1
|
||||||
if flag[i2]
|
if flag[i2]
|
||||||
i1 += 1
|
i1 += 1
|
||||||
t += ch2 != c[i1]
|
t += ch2 != next(s1, i1_match[i1])[1]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
m == 0.0 && return 1.0
|
m == 0.0 && return 1.0
|
||||||
|
|
|
@ -91,7 +91,6 @@ for x in solutions
|
||||||
if isnan(evaluate(t, strings[i]...))
|
if isnan(evaluate(t, strings[i]...))
|
||||||
@test isnan(solution[i])
|
@test isnan(solution[i])
|
||||||
else
|
else
|
||||||
@show strings[i]
|
|
||||||
@test evaluate(t, strings[i]...) ≈ solution[i] atol = 1e-4
|
@test evaluate(t, strings[i]...) ≈ solution[i] atol = 1e-4
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue