Skip to content

Commit

Permalink
merge plurals before choosing case of word to keep so different cases…
Browse files Browse the repository at this point in the history
… are merged, too
  • Loading branch information
boidolr committed Dec 6, 2015
1 parent 6100640 commit 39d74c3
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions wordcloud/wordcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,22 +368,24 @@ def process_text(self, text):
# Look in any case dict.
d2[word] = d2.get(word, 0) + 1

# merge plurals into the singular count (simple cases only)
for key in list(d.keys()):
if key.endswith('s'):
key_singular = key[:-1]
if key_singular in d:
dict_plural = d[key]
dict_singular = d[key_singular]
for word, count in dict_plural.items():
singular = word[:-1]
dict_singular[singular] = dict_singular.get(singular, 0) + count
del d[key]

d3 = {}
for d2 in d.values():
# Get the most popular case.
first = max(d2.items(), key=item1)[0]
d3[first] = sum(d2.values())

# merge plurals into the singular count (simple cases only)
for key in list(d3.keys()):
if key.endswith('s'):
key_singular = key[:-1]
if key_singular in d3:
val_plural = d3[key]
val_singular = d3[key_singular]
d3[key_singular] = val_singular + val_plural
del d3[key]

return d3.items()

def generate_from_text(self, text):
Expand Down

0 comments on commit 39d74c3

Please sign in to comment.