Skip to content

Commit

Permalink
fix(textprocessing): improve case merging logic
Browse files Browse the repository at this point in the history
  • Loading branch information
guo-yong-zhi committed Oct 10, 2024
1 parent c343b57 commit e57c419
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions examples/benchmark.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#md# Test the performance of different trainers
#md# <details>
#md#
using WordCloud
using Random
# Random.seed!(8)
Expand Down Expand Up @@ -37,3 +39,5 @@ for (i, (wc, e)) in enumerate(zip(wcs, es))
println("##$(i - 1) $(length(wc))@$(size(wc.mask)):")
println(repr("text/plain", e))
end
#md# </details>
#md#
9 changes: 6 additions & 3 deletions src/textprocessing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,12 @@ end
function casemerge!(d)
for w in keys(d)
if length(w) > 0 && isuppercase(w[1]) && islowercase(w[end])
lw = lowercase(w)
if lw != w && lw in keys(d) && d[lw] > d[w]
d[lw] += d[w]
w2 = lowercase(w)
if w2 != w && w2 in keys(d)
if d[w2] < d[w]
w, w2 = w2, w
end
d[w2] += d[w]
pop!(d, w)
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ include("test_textprocessing.jl")
angles=(0, 90));
rescale!(wc, 1.23)
@test getwords(wc, WordCloud.ID(2)) == words[2]
pin(wc, ["head", "cat"]) do
pin(wc, ["head", "voice"]) do
@test length(wc) == 298
setpositions!(wc, 1, (2, 2))
setpositions!(wc, [1, "Alice", "eye"], (-1, -2))
Expand Down

0 comments on commit e57c419

Please sign in to comment.