WordCloud.jl Documentation

Adding WordCloud.jl

julia> using Pkg
julia> Pkg.add("WordCloud") Resolving package versions... Updating `~/.julia/packages/WordCloud/5k8OM/docs/Project.toml` [6385f0a0] ~ WordCloud v0.10.5 `~/.julia/packages/WordCloud/5k8OM` ⇒ v0.10.5 Updating `~/.julia/packages/WordCloud/5k8OM/docs/Manifest.toml` [6385f0a0] ~ WordCloud v0.10.5 `~/.julia/packages/WordCloud/5k8OM` ⇒ v0.10.5

Documentation

WordCloud.WordCloudModule

The WordCloud package is a flexible, fast and exact word cloud generator in julia.

using WordCloud
wc = wordcloud("It's easy to generate word clouds") |> generate!
paint(wc, "wordcloud.svg")

Have a look at the repository: https://github.com/guo-yong-zhi/WordCloud.jl

WordCloud.fit!Method

Positional Args

  • wc: the wordcloud to fit
  • nepoch: training epoch nums

Keyword Args

  • patient: number of epochs before repositioning
  • reposition: a Bool value to turn on/off teleport, a Float number p between 0~1 indicating the repositioning ratio (Minimum p), a Int number n equivalent to i -> i >= n, a Function index::Int -> doteleport::Boll, or a white list collision.
  • trainer: appoint a training engine
WordCloud.generate!Method

Positional Args

  • wc: the wordcloud to fit
  • nepoch: training epoch nums

Keyword Args

  • retry: shrink & retrain times, defaults to 3, set to 1 to disable shrinking
  • patient: number of epochs before repositioning
  • reposition: a Bool value to turn on/off teleport, a Float number p between 0~1 indicating the repositioning ratio (Minimum p), a Int number n equivalent to i -> i >= n, a Function index::Int -> doteleport::Boll, or a white list collision.
  • trainer: appoint a training engine
WordCloud.getanglesFunction

The 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index. And the index argument can be ignored to get all values.

WordCloud.getcolorsFunction

The 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index. And the index argument can be ignored to get all values.

WordCloud.getfontsFunction

The 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index. And the index argument can be ignored to get all values.

WordCloud.getfontsizesFunction

The 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index. And the index argument can be ignored to get all values.

WordCloud.getimagesFunction

The 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index. And the index argument can be ignored to get all values.

WordCloud.getpositionsFunction

The 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index. And the index argument can be ignored to get all values. Keyword argment type can be getshift or getcenter.

WordCloud.getsvgimagesFunction

The 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index. And the index argument can be ignored to get all values.

WordCloud.getweightsFunction

The 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index. And the index argument can be ignored to get all values.

WordCloud.getwordsFunction

The 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index. And the index argument can be ignored to get all values.

WordCloud.ignoreMethod

ignore some words as if they don't exist, then execute the function. It's the opposite of keep.

  • ignore(fun, wc, ws::String) #ignore a word
  • ignore(fun, wc, ws::Set{String}) #ignore all words in ws
  • ignore(fun, wc, ws::Vector{String}) #ignore all words in ws
  • ignore(fun, wc, inds::Union{Integer, Vector{Integer}})
  • ignore(fun, wc::WC, mask::AbstractArray{Bool}) #ignore words. length(mask)==length(wc)
WordCloud.keepMethod

keep some words and ignore the others, then execute the function. It's the opposite of ignore.

  • keep(fun, wc, ws::String) #keep a word
  • keep(fun, wc, ws::Set{String}) #kepp all words in ws
  • keep(fun, wc, ws::Vector{String}) #keep all words in ws
  • keep(fun, wc, inds::Union{Integer, Vector{Integer}})
  • keep(fun, wc::WC, mask::AbstractArray{Bool}) #keep words. length(mask)==length(wc)
WordCloud.loadmaskMethod

load a img as mask, recolor, or resize, etc

examples

  • loadmask(open("res/heart.jpg"), 256, 256) #resize to 256*256
  • loadmask("res/heart.jpg", ratio=0.3) #scale 0.3
  • loadmask("res/heart.jpg", color="red", ratio=2) #set forecolor
  • loadmask("res/heart.jpg", transparent=rgba->maximum(rgba[1:3])*(rgba[4]/255)>128) #set transparent with a Function
  • loadmask("res/heart.jpg", color="red", transparent=(1,1,1)) #set forecolor and transparent
  • loadmask("res/heart.svg") #other arguments are not supported

padding: an Integer or a tuple of two Integers About orther keyword arguments like outline, linecolor, smoothness, see function outline.

WordCloud.paintMethod

examples

  • paint(wc::WC)
  • paint(wc::WC, background=false) #no background
  • paint(wc::WC, background=outline(wc.mask)) #use a new background
  • paint(wc::WC, ratio=0.5) #resize the result
  • paint(wc::WC, "result.png", ratio=0.5) #save as png file, other bitmap formats may also work
  • paint(wc::WC, "result.svg") #save as svg file
WordCloud.pinMethod

pin some words as if they were part of the background, then execute the function.

  • pin(fun, wc, ws::String) #pin a word
  • pin(fun, wc, ws::Set{String}) #pin all words in ws
  • pin(fun, wc, ws::Vector{String}) #pin all words in ws
  • pin(fun, wc, inds::Union{Integer, Vector{Integer}})
  • pin(fun, wc::WC, mask::AbstractArray{Bool}) #pin words. length(mask)==length(wc)
WordCloud.placewords!Method
  • placewords!(wc)
  • placewords!(wc, style=:uniform)
  • placewords!(wc, style=:gathering)
  • placewords!(wc, style=:gathering, level=5) #level controls the intensity of gathering, typically between 4 and 6, defaults to 5.
  • placewords!(wc, style=:gathering, level=6, rt=0) #rt=0, rectangle; rt=1, ellipse; rt=2, rhombus. defaults to 1.

There is also a keyword argument centeredword. e.g. centeredword=1, centeredword="Alice", centeredword=false When you have set style=:gathering, you should disable repositioning in generate! at the same time, especially for big words. e.g. generate!(wc, reposition=0.7). The keyword argument reorder is a function to reorder the words, which affects the order of placement. Like reverse, WordCloud.shuffle.

WordCloud.recolor!Method

recolor the words in wc in different styles with the background picture. The styles supported are :average, :main, :clipping, :blending, and :reset (to undo all effects of others). e.g.

  • recolor!(wc, style=:average)
  • recolor!(wc, style=:main)
  • recolor!(wc, style=:clipping, background=blur(getmask(wc))) # background is optional
  • recolor!(wc, style=:blending, alpha=0.3) # background and alpha are optional
  • recolor!(wc, style=:reset)

The effects of :average, :main and :clipping are only determined by the background. But the effect of :blending is also affected by the previous word color. Therefore, :blending can also be used in combination with others The results of clipping and blending can not be exported as SVG files, use PNG instead.

WordCloud.rescale!Method

rescale!(wc::WC, ratio::Real) Rescale all words's size. set ratio<1 to shrink, set ratio>1 to expand.

WordCloud.runexampleFunction

Available values: [:alice, :animation1, :animation2, :benchmark, :compare, :compare2, :custom, :fromweb, :gathering, :highdensity, :juliadoc, :lettermask, :logo, :nomask, :outline, :pattern, :qianziwen, :random, :recolor, :semantic, :series, :中文]

WordCloud.setangles!Method

The 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index, the 3rd argument is the value to assign.

WordCloud.setcolors!Method

The 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index, the 3rd argument is the value to assign.

WordCloud.setfonts!Method

The 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index, the 3rd argument is the value to assign.

WordCloud.setfontsizes!Method

The 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index, the 3rd argument is the value to assign.

WordCloud.setimages!Method

The 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index, the 3rd argument is the value to assign.

WordCloud.setpositions!Method

The 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index, the 3rd argument is the value to assign. Keyword argment type can be setshift! or setcenter!.

WordCloud.setsvgimages!Method

The 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index, the 3rd argument is the value to assign.

WordCloud.setweights!Method

The 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index, the 3rd argument is the value to assign.

WordCloud.setwords!Method

The 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index, the 3rd argument is the value to assign.

WordCloud.showexampleFunction

Available values: [:alice, :animation1, :animation2, :benchmark, :compare, :compare2, :custom, :fromweb, :gathering, :highdensity, :juliadoc, :lettermask, :logo, :nomask, :outline, :pattern, :qianziwen, :random, :recolor, :semantic, :series, :中文]

WordCloud.wordcloudMethod

Positional Arguments

Positional arguments are used to specify words and weights, and can be in different forms, such as Tuple or Dict, etc.

  • words::AbstractVector{<:AbstractString}, weights::AbstractVector{<:Real}
  • words_weights::Tuple
  • counter::AbstractDict
  • counter::AbstractVector{<:Pair}

Optional Keyword Arguments

style keyword arguments

  • colors = "black" #all same color
  • colors = ("black", (0.5,0.5,0.7), "yellow", "#ff0000", 0.2) #choose entries randomly
  • colors = ["black", (0.5,0.5,0.7), "yellow", "red", (0.5,0.5,0.7), 0.2, ......] #use entries sequentially in cycle
  • colors = :seaborn_dark #using a preset scheme. see WordCloud.colorschemes for all supported Symbols. and WordCloud.displayschemes() may be helpful.
  • angles = 0 #all same angle
  • angles = (0, 90, 45) #choose entries randomly
  • angles = 0:180 #choose entries randomly
  • angles = [0, 22, 4, 1, 100, 10, ......] #use entries sequentially in cycle
  • fonts = "Serif Bold" #all same font
  • fonts = ("Arial", "Times New Roman", "Tahoma") #choose entries randomly
  • fonts = ["Arial", "Times New Roman", "Tahoma", ......] #use entries sequentially in cycle
  • density = 0.55 #default 0.5
  • spacing = 1 #minimum spacing between words

mask keyword arguments

  • mask = loadmask("res/heart.jpg", 256, 256) #see the doc of loadmask
  • mask = loadmask("res/heart.jpg", color="red", ratio=2) #see the doc of loadmask
  • mask = "res/heart.jpg" #shorthand for loadmask("res/heart.jpg")
  • mask = shape(ellipse, 800, 600, color="white", backgroundcolor=(0,0,0,0)) #See the doc of shape.
  • mask = box #mask can also be one of box, ellipse, squircle, ngon and star. See the doc of shape.
  • masksize: Can be a tuple (width, height) or just a single number as a side length hint.
  • backgroundsize: See shape. Need to be used with masksize to specify the padding size.
  • maskcolor: like "black", "#ff0000", (0.5,0.5,0.7), 0.2, or :default, :original (keep it unchanged), :auto (auto recolor the mask).
  • backgroundcolor: like "black", "#ff0000", (0.5,0.5,0.7), 0.2, or :default, :original, :maskcolor, :auto (random choose between :original and :maskcolor)
  • outline, linecolor, smoothness: See function shape and outline.
  • transparent = (1,0,0) #set the transparent color in mask
  • transparent = nothing #no transparent color
  • transparent = c->(c[1]+c[2]+c[3])/3*(c[4]/255)>128) #set transparent with a Function. c is a (r,g,b,a) Tuple.

–-NOTE Some arguments depend on whether or not the mask is given or the type of the given mask.

other keyword arguments

  • style, centeredword, reorder, rt, level: config the style of placewords!. See the doc of placewords!.
  • state = placewords! #default setting, will initialize word's position
  • state = generate! #get result directly
  • state = initwords! #only initialize resources, such as rendering word images
  • state = identity #do nothing

The keyword argument state is a function. It will be called after the wordcloud object constructed. This will set the object to a specific state. –-NOTE

  • After getting the wordcloud object, these steps are needed to get the result picture: initwords! -> placewords! -> generate! -> paint
  • You can skip placewords! and/or initwords!, and these operations will be performed automatically with default parameters

Index