code: def _common(
      dataset: Dataset,
      triple_func: Callable[[MappedTriples], pd.DataFrame],
      merge_sides: bool = True,
      merge_subsets: bool = True,
      add_labels: bool = True,
  ) -> pd.DataFrame:
      """
      Execute triple analysis over a dataset.
  
      :param dataset:
          The dataset.
      :param triple_func:
          The analysis function on the triples.
      :param merge_sides:
          Whether to merge sides, i.e., entity positions: head vs. tail.
      :param merge_subsets:
          Whether to merge subsets, i.e., train/validation/test.
      :param add_labels:
          Whether to add entity / relation labels.
  
      :return:
          An aggregated dataframe.
      """
      # compute over all triples
      data = []
      for subset_name, triples_factory in dataset.factory_dict.items():
          df = triple_func(triples_factory.mapped_triples)
          df[SUBSET_COLUMN_NAME] = subset_name
          data.append(df)
      df = pd.concat(data, ignore_index=True)
  
      # Determine group key
      group_key = []
      for key, condition in (
          (triple_analysis.ENTITY_ID_COLUMN_NAME, True),
          (triple_analysis.RELATION_ID_COLUMN_NAME, True),
          (
              triple_analysis.ENTITY_POSITION_COLUMN_NAME,
              not merge_sides,
          ),
          (SUBSET_COLUMN_NAME, not merge_subsets),
      ):
          if condition and key in df.columns:
              group_key.append(key)
      df = (
          df.groupby(by=group_key)[triple_analysis.COUNT_COLUMN_NAME]
          .sum()
          .reset_index()
      )
  
      # Add labels if requested
      if (
          add_labels
          and triple_analysis.ENTITY_ID_COLUMN_NAME in df.columns
      ):
          df = triple_analysis.add_entity_labels(
              df=df,
              add_labels=add_labels,
              label_to_id=dataset.entity_to_id,
          )
      if (
          add_labels
          and triple_analysis.RELATION_ID_COLUMN_NAME in df.columns
      ):
          df = triple_analysis.add_relation_labels(
              df=df,
              add_labels=add_labels,
              label_to_id=dataset.relation_to_id,
          )
      return df
  
file_path: pykeen/src/pykeen/datasets/analysis.py
imports: import logging
  from typing import Callable, Collection, Optional, Tuple, Union
  import pandas
  import torch
  from .base import Dataset
  from ..constants import PYKEEN_DATASETS
  from ..triples import analysis
  from ..typing import MappedTriples
label_desc: Use image node_id 3 for calling a global function with example usage: _common(dataset, triple_func, merge_sides, merge_subsets, add_labels) and returns: df