A different plan for the top-level word_frequency function.

When, before, I was importing wordfreq.query at the top level, this
created a dependency loop when installing wordfreq.

The new top-level __init__.py provides just a `word_frequency` function,
which imports the real function as needed and calls it. This should
avoid the dependency loop, at the cost of making
`wordfreq.word_frequency` slightly less efficient than
`wordfreq.query.word_frequency`.
This commit is contained in:
Rob Speer 2014-02-24 18:03:31 -05:00
parent 3702a7c8d0
commit 44ccf40742
2 changed files with 18 additions and 3 deletions

View File

@ -1,6 +1,7 @@
from __future__ import unicode_literals
from nose.tools import eq_, assert_almost_equal, assert_greater
from wordfreq.query import (word_frequency, average_frequency, wordlist_size,
from wordfreq import word_frequency
from wordfreq.query import (average_frequency, wordlist_size,
wordlist_info)

View File

@ -1,2 +1,16 @@
# Import some methods from wordfreq.query at the top level.
from wordfreq.query import word_frequency, iter_wordlist, random_words
# Make wordfreq.query available at the top level when needed.
def word_frequency(word, lang, wordlist='multi', offset=0.):
"""
Get the frequency of `word` in the language with code `lang`, from the
specified `wordlist`.
The offset gets added to all values, to monotonically account for the
fact that we have not observed all possible words.
This is a wrapper for the real word_frequency function, so that it can
be imported at the top level instead of from `wordfreq.query`.
"""
from wordfreq.query import word_frequency as _real_word_frequency
return _real_word_frequency(word, lang, wordlist=wordlist, offset=offset)