'Replace word indices below min_count with the pad index.
Arguments
words_compact: int array
Source array whose values will be replaced. This is assumed to
already be converted into a compact array with `to_compact`.
min_count : int
Replace words less frequently occuring than this count. This
defines the threshold for what words are very rare
max_count : int
Replace words occuring more frequently than this count. This
defines the threshold for very frequent words
min_replacement : int, default is out_of_vocabulary
Replace words less than min_count with this.
max_replacement : int, default is out_of_vocabulary
Replace words greater than max_count with this.
Examples
>>> corpus = Corpus()
>>> # Make 1000 word indices with index < 100 and
>>> # update the word counts.
>>> word_indices = np.random.randint(100, size=1000)
>>> corpus.update_word_count(word_indices)
>>> corpus.finalize()  # any word indices above 99 will be filtered
>>> # Now create a new text, but with some indices above 100
>>> word_indices = np.random.randint(200, size=1000)
>>> word_indices.max() < 100
False
>>> # Remove words that have never appeared in the original corpus.
>>> filtered = corpus.filter_count(word_indices, min_count=1)
>>> filtered.max() < 100
True
>>> # We can also remove highly frequent words.
>>> filtered = corpus.filter_count(word_indices, max_count=2)
>>> len(np.unique(word_indices)) > len(np.unique(filtered))
True'

def filter_count(self, words_compact, min_count=15, max_count=0, max_replacement=None, min_replacement=None):

    self._check_finalized()
    ret = words_compact.copy()
    if (min_replacement is None):
        min_replacement = self.specials_to_compact['out_of_vocabulary']
    if (max_replacement is None):
        max_replacement = self.specials_to_compact['out_of_vocabulary']
    not_specials = np.ones(self.keys_counts.shape[0], dtype='bool')
    not_specials[:self.n_specials] = False
    if min_count:
        min_idx = np.argmax((not_specials & (self.keys_counts < min_count)))
        ret[(ret > min_idx)] = min_replacement
    if max_count:
        max_idx = np.argmax((not_specials & (self.keys_counts < max_count)))
        ret[(ret < max_idx)] = max_replacement
    return ret
