Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
keeleliin
word_cloud_est
Commits
ab1f17ff
Commit
ab1f17ff
authored
Aug 18, 2015
by
Andreas Mueller
Browse files
store sorted / normalized frequencies, make the max a float
parent
943ede2e
Changes
1
Show whitespace changes
Inline
Side-by-side
wordcloud/wordcloud.py
View file @
ab1f17ff
...
...
@@ -220,11 +220,13 @@ class WordCloud(object):
frequencies
=
sorted
(
frequencies
,
key
=
lambda
x
:
x
[
1
],
reverse
=
True
)
frequencies
=
frequencies
[:
self
.
max_words
]
# largest entry will be 1
max_frequency
=
np
.
max
([
freq
for
word
,
freq
in
frequencies
])
max_frequency
=
float
(
np
.
max
([
freq
for
word
,
freq
in
frequencies
])
)
for
i
,
(
word
,
freq
)
in
enumerate
(
frequencies
):
frequencies
[
i
]
=
word
,
freq
/
max_frequency
self
.
words_
=
frequencies
if
self
.
random_state
is
not
None
:
random_state
=
self
.
random_state
else
:
...
...
@@ -371,9 +373,7 @@ class WordCloud(object):
d3
[
key_singular
]
=
val_singular
+
val_plural
del
d3
[
key
]
self
.
words_
=
d3
.
items
()
return
self
.
words_
return
d3
.
items
()
def
generate_from_text
(
self
,
text
):
"""Generate wordcloud from text.
...
...
@@ -384,8 +384,8 @@ class WordCloud(object):
-------
self
"""
self
.
process_text
(
text
)
self
.
generate_from_frequencies
(
self
.
words
_
)
words
=
self
.
process_text
(
text
)
self
.
generate_from_frequencies
(
words
)
return
self
def
generate
(
self
,
text
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment