mirror of
https://github.com/rspeer/wordfreq.git
synced 2024-12-23 09:21:37 +00:00
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:
parent
3702a7c8d0
commit
44ccf40742
@ -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)
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user