guo-yong-zhi / WordCloud.jl

word cloud generator in julia
MIT License
105 stars 2 forks source link

Word == Sentences ?? #19

Closed JMarianoIFSTTAR closed 1 year ago

JMarianoIFSTTAR commented 1 year ago

Hi I would like to generate word cloud but with ... sentences/expressions... The given text file may be of the following form

"This is sentence A" "Another expression" "What a good tool" "Julia is powerful"

Seems that's not possible for now with Wordcloud (because of splitword regexp ?) Thanks for WordCloud!

guo-yong-zhi commented 1 year ago

If you don't want to count words, you should explicitly pass in a parameter weights to the function wordcloud:

list= ["This is sentence A",
"Another expression",
"What a good tool",
"Julia is powerful"]
weights = 1
wc = wordcloud(list, weights) |> generate!

If you want WordCloud.jl to do the counting job but not in word-wise way, you can set a custom regexp:

wc = wordcloud(processtext(list, regexp=r".*")) |> generate!

or

wc = wordcloud(processtext(list, regexp=nothing)) |> generate!
JMarianoIFSTTAR commented 1 year ago

Le 16/03/2023 à 14:23, Guo Yongzhi a écrit :

please try

Yes, it's ok

But I can't reach the same result with something like :

wc = wordcloud(open("./text.txt"))

=>

wordcloud(["Another", "expression", "Julia", "powerful", "sentence", "good", "tool"]) #7words

text.txt is

"This is sentence A", "Another expression", "What a good tool", "Julia is powerful"

Did I miss something ?

Thanks

guo-yong-zhi commented 1 year ago

Everything in the file will be treated as an article, so it will be counted by word. You can manually read the file to a list. e.g. list = readlines(open("text.txt"))