diff --git a/.gitignore b/.gitignore index 011f314..1cf96d6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ .vscode *.cov res/*/* -address_compare -guxiang_animation +address_compare* +guxiang_animation* /*.png test/*.jpg diff --git a/Project.toml b/Project.toml index 26cfd20..8b7c6fb 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "WordCloud" uuid = "6385f0a0-cb03-45b6-9089-4e0acc74b26b" authors = ["guoyongzhi "] -version = "0.3.1" +version = "0.3.2" [deps] ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4" diff --git a/README.md b/README.md index d8d7df5..b630ca9 100644 --- a/README.md +++ b/README.md @@ -40,9 +40,9 @@ paint(wc, "alice.png", ratio=0.5, background=outline(wc.mask, color="purple", li [Training animation](./examples/animation.jl) *Run the command `runexample(:animation)` or `showexample(:animation)` to get the result.* ## Specifies the style of a particular word -![specifystyle](res/specifystyle.png) -[Specifies the style of a particular word](./examples/specifystyle.jl) -*Run the command `runexample(:specifystyle)` or `showexample(:specifystyle)` to get the result.* +![specifiedstyle](res/specifiedstyle.png) +[Specifies the style of a particular word](./examples/specifiedstyle.jl) +*Run the command `runexample(:specifiedstyle)` or `showexample(:specifiedstyle)` to get the result.* ## Comparison ![compare](res/compare.png) [Comparison of Obama's and Trump's inaugural address](./examples/compare.jl) diff --git a/examples/alice.jl b/examples/alice.jl index ff7776f..a91ccda 100644 --- a/examples/alice.jl +++ b/examples/alice.jl @@ -5,6 +5,6 @@ wc = wordcloud( colors = :Set1_5, angles = (0, 90), fillingrate = 0.7) |> generate! -println("save results to alice.png") +println("results are saved to alice.png") paint(wc, "alice.png", background=outline(wc.mask, color="purple", linewidth=1)) wc \ No newline at end of file diff --git a/examples/animation.jl b/examples/animation.jl index fab4370..681997d 100644 --- a/examples/animation.jl +++ b/examples/animation.jl @@ -3,11 +3,11 @@ using DataFrames using WordCloud df = CSV.File(pkgdir(WordCloud)*"/res/guxiang_frequency.txt", header=false)|> DataFrame; -texts = df[!, "Column2"] +words = df[!, "Column2"] weights = df[!, "Column3"] -wc = wordcloud(texts, weights, fillingrate=0.8) -println("save results to guxiang_animation") +wc = wordcloud(words, weights, fillingrate=0.8) gifdirectory = "guxiang_animation" generate_animation!(wc, 100, outputdir=gifdirectory) +println("results are saved in guxiang_animation") wc \ No newline at end of file diff --git a/examples/trainermetric.jl b/examples/benchmark.jl similarity index 100% rename from examples/trainermetric.jl rename to examples/benchmark.jl diff --git a/examples/compare.jl b/examples/compare.jl index aaf497c..6b8b4ce 100644 --- a/examples/compare.jl +++ b/examples/compare.jl @@ -57,7 +57,7 @@ mb = paint(wcb) h,w = size(ma) space = fill(mb[1], (h, w÷20)) try mkdir("address_compare") catch end -println("save results to address_compare") +println("results are saved in address_compare") WordCloud.ImageMagick.save("address_compare/compare.png", [ma space mb]) gif = WordCloud.GIF("address_compare") diff --git a/examples/specifystyle.jl b/examples/specifiedstyle.jl similarity index 91% rename from examples/specifystyle.jl rename to examples/specifiedstyle.jl index b21c36b..01d57ae 100644 --- a/examples/specifystyle.jl +++ b/examples/specifiedstyle.jl @@ -18,6 +18,6 @@ pin(wc, "Alice in Wonderland") do generate!(wc) end -println("save results to specifystyle.png") -paint(wc, "specifystyle.png") +println("results are saved to specifiedstyle.png") +paint(wc, "specifiedstyle.png") wc \ No newline at end of file diff --git a/src/nlp.jl b/src/nlp.jl index 0e03e6c..cf16e31 100644 --- a/src/nlp.jl +++ b/src/nlp.jl @@ -48,8 +48,12 @@ function process(counter::Dict{<:AbstractString, <:Number}; maxnum=500, minweight=1/maxnum, maxweight=minweight*20) stopwords = Set(stopwords) + println("$(sum(values(counter))) words") + println("$(length(counter)) different words") for (w, c) in counter - if (c < minfrequency || length(w) < minlength || length(w) > maxlength || lowercase(w) in stopwords) + if (c < minfrequency + || length(w) < minlength || length(w) > maxlength + || lowercase(w) in stopwords || w in stopwords) delete!(counter, w) end end diff --git a/src/rendering.jl b/src/rendering.jl index 980d4e3..d66629b 100644 --- a/src/rendering.jl +++ b/src/rendering.jl @@ -192,6 +192,7 @@ function try_gif_gen(gifdirectory; framerate=4) -i $(gifdirectory)/result-palette.png -lavfi paletteuse -y $(gifdirectory)/result.gif`, stdout=devnull, stderr=devnull) |> run catch e + @warn "You need to have FFmpeg manually installed to use this function." @warn e end end diff --git a/src/train.jl b/src/train.jl index 41a0d55..94263f1 100644 --- a/src/train.jl +++ b/src/train.jl @@ -355,7 +355,8 @@ function teleport!(ts, maskqt, collpool, args...; kargs...) end function train!(ts, maskqt, nepoch::Number=-1, args...; - trainer=trainepoch_EM2!, patient::Number=trainer(:patient), callbackstep=0, callbackfun=x->x, kargs...) + trainer=trainepoch_EM2!, patient::Number=trainer(:patient), optimiser=Momentum(η=1/4, ρ=0.5), + callbackstep=0, callbackfun=x->x, kargs...) ep = 0 nc = 0 count = 0 @@ -373,7 +374,7 @@ function train!(ts, maskqt, nepoch::Number=-1, args...; @show nepoch, patient while ep < nepoch # @show "##", ep, nc, length(collpool), (count,nc_min) - nc = trainer(ts, maskqt, args...; resource..., kargs...) + nc = trainer(ts, maskqt, args...; resource..., optimiser=optimiser, kargs...) ep += 1 count += 1 if nc < nc_min