From cd9d95d39be469f3cb76b26bae08d9a260eacd6f Mon Sep 17 00:00:00 2001 From: guoyongzhi Date: Wed, 8 May 2024 23:06:47 +0800 Subject: [PATCH] less print --- src/strategy.jl | 8 ++++---- src/wc-class.jl | 6 +++--- src/wc-method.jl | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/strategy.jl b/src/strategy.jl index c43c20b..74958c5 100644 --- a/src/strategy.jl +++ b/src/strategy.jl @@ -151,7 +151,7 @@ function findscale!(wc::WC; initialscale=0, density=0.3, maxiter=5, tolerance=0. setparameter!(wc, sc1, :scale) tg1 = wordsoccupancy!(wc) dens = tg1 / area - println("⋯scale=$(getparameter(wc, :scale)), density=$dens\t", dens > density ? "↑" : "↓") + @debug "⋯scale=$(getparameter(wc, :scale)), density=$dens\t" * (dens > density ? "↑" : "↓") if tg1 > target if best_tar_H > tg1 best_tar_H = tg1 @@ -169,18 +169,18 @@ function findscale!(wc::WC; initialscale=0, density=0.3, maxiter=5, tolerance=0. if !(best_scale_L < sc2 < best_scale_H) if isfinite(best_tar_H + best_tar_L) sc2_ = √((best_scale_H^2 + best_scale_L^2) / 2.) - println("bisection search takes effect: scale $sc2 -> $sc2_") + @debug "bisection search takes effect: scale $sc2 -> $sc2_" sc2 = sc2_ # @show best_scale_L best_scale_H elseif isfinite(best_tar_H) sc2_ = sc1 * (0.95^oneway_count) oneway_count += 1 - println("one-way search takes effect: scale $sc2 -> $sc2_") + @debug "one-way search takes effect: scale $sc2 -> $sc2_" sc2 = sc2_ elseif isfinite(best_tar_L) sc2_ = sc1 / (0.95^oneway_count) oneway_count += 1 - println("one-way search takes effect: scale $sc2 -> $sc2_") + @debug "one-way search takes effect: scale $sc2 -> $sc2_" sc2 = sc2_ else error("`findscale!` failed") diff --git a/src/wc-class.jl b/src/wc-class.jl index 075b8d1..d8397b2 100644 --- a/src/wc-class.jl +++ b/src/wc-class.jl @@ -93,7 +93,7 @@ function wordcloud(words::AbstractVector{<:AbstractString}, weights::AbstractVec error("Have you set the right `transparent`? e.g. `transparent=mask[1,1]`") end avgsize = round(Int, sqrt(volume / length(words))) - println("mask size: $(size(mask, 1))×$(size(mask, 2)), volume: $(round(Int, √volume))² ($(avgsize)²/word)") + @debug "mask size: $(size(mask, 1))×$(size(mask, 2)), volume: $(round(Int, √volume))² ($(avgsize)²/word)" params[:maxfontsize0] = maxfontsize if maxfontsize == :auto maxfontsize = minimum(size(mask)) @@ -103,7 +103,7 @@ function wordcloud(words::AbstractVector{<:AbstractString}, weights::AbstractVec minfontsize = min(maxfontsize, 8, sqrt(volume / length(words) / 8)) # 只和单词数量有关,和单词长度无关。不管单词多长,字号小了依然看不见。 end - println("set fontsize ∈ [$minfontsize, $maxfontsize]") + @debug "set fontsize ∈ [$minfontsize, $maxfontsize]" params[:minfontsize] = minfontsize params[:maxfontsize] = maxfontsize params[:spacing] = spacing @@ -359,7 +359,7 @@ end Base.show(io::IO, m::MIME"image/png", wc::WC) = Base.show(io, m, paint(wc::WC)) Base.show(io::IO, m::MIME"image/svg+xml", wc::WC) = Base.show(io, m, paintsvg(wc::WC)) -Base.show(io::IO, m::MIME"text/plain", wc::WC) = print(io, "wordcloud(", wc.words, ") # ", length(wc), "words") +Base.show(io::IO, m::MIME"text/plain", wc::WC) = println(io, "wordcloud(", wc.words, ") # ", length(wc), "words") function Base.showable(::MIME"image/png", wc::WC) STATEIDS[getstate(wc)] >= STATEIDS[:initialize!] && showable("image/png", zeros(ARGB, (1, 1))) end diff --git a/src/wc-method.jl b/src/wc-method.jl index 3d8682b..06e9099 100644 --- a/src/wc-method.jl +++ b/src/wc-method.jl @@ -36,7 +36,7 @@ function initialize!(wc::WC; maxiter=5, tolerance=0.02) wc.params[:wordids] = @view wc.params[:wordids][si] wc.params[:word2index] = nothing wc.params[:id2index] = nothing - println("set density = $(params[:density])") + @debug "set density = $(params[:density])" findscale!(wc, density=params[:density], maxiter=maxiter, tolerance=tolerance) printfontsizes(wc) initialize!(wc, :) @@ -46,10 +46,10 @@ end function printfontsizes(wc) nsmall = findlast(i->getfontsizes(wc, i)<=wc.params[:minfontsize], length(wc):-1:1) nsmall === nothing && (nsmall = 0) - println("fontsize ∈ [$(getfontsizes(wc, length(wc))), $(getfontsizes(wc, 1))]") + @debug "fontsize ∈ [$(getfontsizes(wc, length(wc))), $(getfontsizes(wc, 1))]" if nsmall > 0 perc = round(Int, nsmall/length(wc)*100) - println("$nsmall words($perc%) are limited to the minimum font size.") + @debug "$nsmall words($perc%) are limited to the minimum font size." if perc > 70 msg = "It seems too crowded. Word size may be seriously distorted. You need to reduce the number of words or set a larger mask." ratio = volumeproposal(wc.words, wc.weights) / √getparameter(wc, :volume)