class_docstr: 构建词汇表,增加词汇，删除低频词汇
docstr: 当 word 词频低于 min_freq 时，从词库中删除
  Args:
      min_freq (int): 最低词频
      verbose (bool) : 是否打印日志
docstr_tok: ["\u5f53","word","\u8bcd\u9891\u4f4e\u4e8e","min_freq","\u65f6\uff0c\u4ece\u8bcd\u5e93\u4e2d\u5220\u9664","Args",":","min_freq","(","int",")",":","\u6700\u4f4e\u8bcd\u9891","verbose","(","bool",")",":","\u662f\u5426\u6253\u5370\u65e5\u5fd7"]
code: def trim(self, min_freq=2, verbose: Optional[bool] = True):
      """
      当 word 词频低于 min_freq 时，从词库中删除
      Args:
          min_freq (int): 最低词频
          verbose (bool) : 是否打印日志
      """
      assert min_freq == int(
          min_freq
      ), f"min_freq must be integer, can't be {min_freq}"
      min_freq = int(min_freq)
      if min_freq < 2:
          return
      if self.trimed:
          return
      self.trimed = True
  
      keep_words = []
      new_words = []
  
      for k, v in self.word2count.items():
          if v >= min_freq:
              keep_words.append(k)
              new_words.extend([k] * v)
      if verbose:
          before_len = len(keep_words)
          after_len = len(self.word2idx) - len(self.init_tokens)
          logger.info(
              "vocab after be trimmed, keep words [{} / {}] = {:.2f}%".format(
                  before_len, after_len, before_len / after_len * 100
              )
          )
  
      # Reinitialize dictionaries
      self.word2idx = {}
      self.word2count = {}
      self.idx2word = {}
      self.count = 0
      self._add_init_tokens()
      self.add_words(new_words)
  
file_path: DeepKE/src/deepke/relation_extraction/standard/tools/vocab.py
imports: import logging
  from collections import OrderedDict
  from typing import Sequence, Optional
label_desc: Use image node_id 5 for calling the Vocab obj's underlying member method code with example usage: obj.trim(min_freq, verbose) without return types