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
943ede2e
Commit
943ede2e
authored
Aug 18, 2015
by
Andreas Mueller
Browse files
fix sorting and normalization: wasn't applied if frequencies were given directly.
parent
1f63d4ad
Changes
1
Hide whitespace changes
Inline
Side-by-side
wordcloud/wordcloud.py
View file @
943ede2e
...
...
@@ -21,7 +21,8 @@ from .query_integral_image import query_integral_image
item1
=
itemgetter
(
1
)
FONT_PATH
=
os
.
environ
.
get
(
"FONT_PATH"
,
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"DroidSansMono.ttf"
))
FONT_PATH
=
os
.
environ
.
get
(
"FONT_PATH"
,
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"DroidSansMono.ttf"
))
STOPWORDS
=
set
([
x
.
strip
()
for
x
in
open
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'stopwords'
)).
read
().
split
(
'
\n
'
)])
...
...
@@ -215,6 +216,15 @@ class WordCloud(object):
self
"""
# make sure frequencies are sorted and normalized
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
])
for
i
,
(
word
,
freq
)
in
enumerate
(
frequencies
):
frequencies
[
i
]
=
word
,
freq
/
max_frequency
if
self
.
random_state
is
not
None
:
random_state
=
self
.
random_state
else
:
...
...
@@ -361,27 +371,21 @@ class WordCloud(object):
d3
[
key_singular
]
=
val_singular
+
val_plural
del
d3
[
key
]
words
=
sorted
(
d3
.
items
(),
key
=
item1
,
reverse
=
True
)
words
=
words
[:
self
.
max_words
]
maximum
=
float
(
max
(
d3
.
values
()))
for
i
,
(
word
,
count
)
in
enumerate
(
words
):
words
[
i
]
=
word
,
count
/
maximum
self
.
words_
=
words
self
.
words_
=
d3
.
items
()
return
words
return
self
.
words
_
def
generate_from_text
(
self
,
text
):
"""Generate wordcloud from text.
Calls process_text and
fit_word
s.
Calls process_text and
generate_from_frequencie
s.
Returns
-------
self
"""
self
.
process_text
(
text
)
self
.
fit_word
s
(
self
.
words_
)
self
.
generate_from_frequencie
s
(
self
.
words_
)
return
self
def
generate
(
self
,
text
):
...
...
@@ -389,7 +393,7 @@ class WordCloud(object):
Alias to generate_from_text.
Calls process_text and
fit_word
s.
Calls process_text and
generate_from_frequencie
s.
Returns
-------
...
...
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