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
099f714c
Commit
099f714c
authored
Dec 03, 2014
by
Andreas Mueller
Browse files
Merge pull request #34 from defacto133/python3
Python3
parents
1254715d
20cb719e
Changes
1
Hide whitespace changes
Inline
Side-by-side
wordcloud/wordcloud.py
View file @
099f714c
...
...
@@ -7,6 +7,7 @@
from
random
import
Random
import
os
import
re
import
sys
import
numpy
as
np
from
operator
import
itemgetter
...
...
@@ -229,7 +230,7 @@ class WordCloud(object):
integral
[
x
:,
y
:]
=
partial_integral
self
.
layout_
=
zip
(
words
,
font_sizes
,
positions
,
orientations
,
colors
)
self
.
layout_
=
list
(
zip
(
words
,
font_sizes
,
positions
,
orientations
,
colors
)
)
return
self
.
layout_
def
process_text
(
self
,
text
):
...
...
@@ -253,7 +254,8 @@ class WordCloud(object):
"""
d
=
{}
flags
=
re
.
UNICODE
if
type
(
text
)
is
unicode
else
0
flags
=
re
.
UNICODE
if
sys
.
version
<
'3'
and
\
type
(
text
)
is
unicode
else
0
for
word
in
re
.
findall
(
r
"\w[\w']*"
,
text
,
flags
=
flags
):
if
word
.
isdigit
():
continue
...
...
@@ -275,11 +277,11 @@ class WordCloud(object):
d3
=
{}
for
d2
in
d
.
values
():
# Get the most popular case.
first
=
max
(
d2
.
iter
items
(),
key
=
item1
)[
0
]
first
=
max
(
d2
.
items
(),
key
=
item1
)[
0
]
d3
[
first
]
=
sum
(
d2
.
values
())
# merge plurals into the singular count (simple cases only)
for
key
in
d3
.
keys
():
for
key
in
list
(
d3
.
keys
()
)
:
if
key
.
endswith
(
's'
):
key_singular
=
key
[:
-
1
]
if
key_singular
in
d3
:
...
...
@@ -288,7 +290,7 @@ class WordCloud(object):
d3
[
key_singular
]
=
val_singular
+
val_plural
del
d3
[
key
]
words
=
sorted
(
d3
.
iter
items
(),
key
=
item1
,
reverse
=
True
)
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
):
...
...
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