Commit a8fbf5bc authored by Andreas Mueller's avatar Andreas Mueller
Browse files

Merge pull request #18 from petrushev/merge-plural-into-singular

Merge the value of the plural form into the key with the singular form
parents f0b3739e 1358180b
......@@ -205,6 +205,16 @@ def process_text(text, max_features=200, stopwords=None):
first = sorted(d2.iteritems(), key=lambda x: x[1], reverse=True)[0][0]
d3[first] = sum(d2.values())
# merge plurals into the singular count (simple cases only)
keys = set(d3.keys())
for key, val in d3.items():
if key.endswith('s'):
key_singular = key[:-1]
if key_singular in d3:
val_singular = d3[key_singular]
d3[key_singular] = val_singular + val
del d3[key]
words = sorted(d3.iteritems(), key=lambda x: x[1], reverse=True)
words = words[:max_features]
maximum = float(max(d3.values()))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment