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 rows of :attr:`item2entity` and :attr:`entity2item`,
  whose ``entity_id`` doesn't occur in kg triplets and
  ``item_id`` doesn't occur in interaction records.
docstr_tok: ["Filter","rows","of",":","attr",":","`","item2entity","`","and",":","attr",":","`","entity2item","`",",","whose","``","entity_id","``","does","n't","occur","in","kg","triplets","and","``","item_id","``","does","n't","occur","in","interaction","records","."]
code: def _filter_link(self):
      """Filter rows of :attr:`item2entity` and :attr:`entity2item`,
      whose ``entity_id`` doesn't occur in kg triplets and
      ``item_id`` doesn't occur in interaction records.
      """
      item_tokens = self._get_rec_item_token()
      ent_tokens = self._get_entity_token()
      illegal_item = set()
      illegal_ent = set()
      for item in self.item2entity:
          ent = self.item2entity[item]
          if item not in item_tokens or ent not in ent_tokens:
              illegal_item.add(item)
              illegal_ent.add(ent)
      for item in illegal_item:
          del self.item2entity[item]
      for ent in illegal_ent:
          del self.entity2item[ent]
      remained_inter = pd.Series(True, index=self.inter_feat.index)
      remained_inter &= self.inter_feat[self.iid_field].isin(
          self.item2entity.keys()
      )
      self.inter_feat.drop(
          self.inter_feat.index[~remained_inter], 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 5 for calling the KnowledgeBasedDataset obj's underlying member method code with example usage: obj._filter_link() without return types