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: Merge item-id and entity-id into the same id-space.
docstr_tok: ["Merge","item-id","and","entity-id","into","the","same","id-space","."]
code: def _merge_item_and_entity(self):
      """Merge item-id and entity-id into the same id-space."""
      item_token = self.field2id_token[self.iid_field]
      entity_token = self.field2id_token[self.head_entity_field]
      item_num = len(item_token)
      link_num = len(self.item2entity)
      entity_num = len(entity_token)
  
      # reset item id
      item_priority = np.array(
          [token in self.item2entity for token in item_token]
      )
      item_order = np.argsort(item_priority, kind="stable")
      item_id_map = np.zeros_like(item_order)
      item_id_map[item_order] = np.arange(item_num)
      new_item_id2token = item_token[item_order]
      new_item_token2id = {
          t: i for i, t in enumerate(new_item_id2token)
      }
      for field in self.alias["item_id"]:
          self._reset_ent_remapID(
              field, item_id_map, new_item_id2token, new_item_token2id
          )
  
      # reset entity id
      entity_priority = np.array(
          [
              token != "[PAD]" and token not in self.entity2item
              for token in entity_token
          ]
      )
      entity_order = np.argsort(entity_priority, kind="stable")
      entity_id_map = np.zeros_like(entity_order)
      for i in entity_order[1 : link_num + 1]:
          entity_id_map[i] = new_item_token2id[
              self.entity2item[entity_token[i]]
          ]
      entity_id_map[entity_order[link_num + 1 :]] = np.arange(
          item_num, item_num + entity_num - link_num - 1
      )
      new_entity_id2token = np.concatenate(
          [
              new_item_id2token,
              entity_token[entity_order[link_num + 1 :]],
          ]
      )
      for i in range(item_num - link_num, item_num):
          new_entity_id2token[i] = self.item2entity[
              new_entity_id2token[i]
          ]
      new_entity_token2id = {
          t: i for i, t in enumerate(new_entity_id2token)
      }
      for field in self.alias["entity_id"]:
          self._reset_ent_remapID(
              field,
              entity_id_map,
              new_entity_id2token,
              new_entity_token2id,
          )
      self.field2id_token[self.entity_field] = new_entity_id2token
      self.field2token_id[self.entity_field] = new_entity_token2id
  
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 18 for calling the KnowledgeBasedDataset obj's underlying member method code with example usage: obj._merge_item_and_entity() without return types