Merge pull request #10 from LuminosoInsight/returns-none-bugfix

word_frequency no longer returns None if it does not detect tokens

Former-commit-id: 97bbb97f63
This commit is contained in:
Robyn Speer 2015-06-24 17:04:36 -04:00
commit f8ac142bcf

View File

@ -227,7 +227,12 @@ def word_frequency(word, lang, wordlist='combined', default=0.):
"""
freqs = get_frequency_dict(lang, wordlist)
combined_value = None
for token in tokenize(word, lang):
tokens = tokenize(word, lang)
if len(tokens) == 0:
return default
for token in tokens:
if token not in freqs:
# If any word is missing, just return the default value
return default