class_docstr: :class:`KnowledgeBasedDataset` is based on :class:`~recbole.data.dataset.dataset.Dataset`,
  and load ``.kg`` and ``.link`` additionally.
  
  Entities are remapped together with ``item_id`` specially.
  All entities are remapped into three consecutive ID sections.
  
  - virtual entities that only exist in interaction data.
  - entities that exist both in interaction data and kg triplets.
  - entities only exist in kg triplets.
  
  It also provides several interfaces to transfer ``.kg`` features into coo sparse matrix,
  csr sparse matrix, :class:`DGL.Graph` or :class:`PyG.Data`.
  
  Attributes:
      head_entity_field (str): The same as ``config['HEAD_ENTITY_ID_FIELD']``.
  
      tail_entity_field (str): The same as ``config['TAIL_ENTITY_ID_FIELD']``.
  
      relation_field (str): The same as ``config['RELATION_ID_FIELD']``.
  
      entity_field (str): The same as ``config['ENTITY_ID_FIELD']``.
  
      kg_feat (pandas.DataFrame): Internal data structure stores the kg triplets.
          It's loaded from file ``.kg``.
  
      item2entity (dict): Dict maps ``item_id`` to ``entity``,
          which is loaded from  file ``.link``.
  
      entity2item (dict): Dict maps ``entity`` to ``item_id``,
          which is loaded from  file ``.link``.
  
  Note:
      :attr:`entity_field` doesn't exist exactly. It's only a symbol,
      representing entity features.
  
      ``[UI-Relation]`` is a special relation token.
docstr: Filter by number of triples.
  
  The interval of the number of triples can be set, and only entities/relations
  whose number of triples is in the specified interval can be retained.
  See :doc:`../user_guide/data/data_args` for detail arg setting.
  
  Note:
      Lower bound of the interval is also called k-core filtering, which means this method
      will filter loops until all the entities and relations has at least k triples.
docstr_tok: ["Filter","by","number","of","triples",".","The","interval","of","the","number","of","triples","can","be","set",",","and","only","entities\/relations","whose","number","of","triples","is","in","the","specified","interval","can","be","retained",".","See",":","doc",":","`","..","\/user_guide\/data\/data_args","`","for","detail","arg","setting",".","Note",":","Lower","bound","of","the","interval","is","also","called","k-core","filtering",",","which","means","this","method","will","filter","loops","until","all","the","entities","and","relations","has","at","least","k","triples","."]
code: def _filter_kg_by_triple_num(self):
      """Filter by number of triples.
  
      The interval of the number of triples can be set, and only entities/relations
      whose number of triples is in the specified interval can be retained.
      See :doc:`../user_guide/data/data_args` for detail arg setting.
  
      Note:
          Lower bound of the interval is also called k-core filtering, which means this method
          will filter loops until all the entities and relations has at least k triples.
      """
      entity_kg_num_interval = self._parse_intervals_str(
          self.config["entity_kg_num_interval"]
      )
      relation_kg_num_interval = self._parse_intervals_str(
          self.config["relation_kg_num_interval"]
      )
  
      if (
          entity_kg_num_interval is None
          and relation_kg_num_interval is None
      ):
          return
  
      entity_kg_num = Counter()
      if entity_kg_num_interval:
          head_entity_kg_num = Counter(
              self.kg_feat[self.head_entity_field].values
          )
          tail_entity_kg_num = Counter(
              self.kg_feat[self.tail_entity_field].values
          )
          entity_kg_num = head_entity_kg_num + tail_entity_kg_num
      relation_kg_num = (
          Counter(self.kg_feat[self.relation_field].values)
          if relation_kg_num_interval
          else Counter()
      )
  
      while True:
          ban_head_entities = self._get_illegal_ids_by_inter_num(
              field=self.head_entity_field,
              feat=None,
              inter_num=entity_kg_num,
              inter_interval=entity_kg_num_interval,
          )
          ban_tail_entities = self._get_illegal_ids_by_inter_num(
              field=self.tail_entity_field,
              feat=None,
              inter_num=entity_kg_num,
              inter_interval=entity_kg_num_interval,
          )
          ban_entities = ban_head_entities | ban_tail_entities
          ban_relations = self._get_illegal_ids_by_inter_num(
              field=self.relation_field,
              feat=None,
              inter_num=relation_kg_num,
              inter_interval=relation_kg_num_interval,
          )
          if len(ban_entities) == 0 and len(ban_relations) == 0:
              break
  
          dropped_kg = pd.Series(False, index=self.kg_feat.index)
          head_entity_kg = self.kg_feat[self.head_entity_field]
          tail_entity_kg = self.kg_feat[self.tail_entity_field]
          relation_kg = self.kg_feat[self.relation_field]
          dropped_kg |= head_entity_kg.isin(ban_entities)
          dropped_kg |= tail_entity_kg.isin(ban_entities)
          dropped_kg |= relation_kg.isin(ban_relations)
  
          entity_kg_num -= Counter(head_entity_kg[dropped_kg].values)
          entity_kg_num -= Counter(tail_entity_kg[dropped_kg].values)
          relation_kg_num -= Counter(relation_kg[dropped_kg].values)
  
          dropped_index = self.kg_feat.index[dropped_kg]
          self.logger.debug(f"[{len(dropped_index)}] dropped triples.")
          self.kg_feat.drop(dropped_index, inplace=True)
  
imports: import os
  from collections import Counter
  import numpy
  import pandas
  import torch
  from scipy.sparse import coo_matrix
  from recbole.data.dataset import Dataset
  from recbole.utils import FeatureSource, FeatureType, set_color
  from recbole.utils.url import decide_download, download_url, extract_zip
label_desc: Use image node_id 4 for calling the KnowledgeBasedDataset obj's underlying member method code with example usage: obj._filter_kg_by_triple_num() without return types