code: def get_relation_pattern_types_df(
      dataset: Dataset,
      *,
      min_support: int = 0,
      min_confidence: float = 0.95,
      drop_confidence: bool = False,
      parts: Optional[Collection[str]] = None,
      force: bool = False,
      add_labels: bool = True,
  ) -> pd.DataFrame:
      r"""
      Categorize relations based on patterns from RotatE [sun2019]_.
  
      The relation classifications are based upon checking whether the corresponding rules hold with sufficient support
      and confidence. By default, we do not require a minimum support, however, a relatively high confidence.
  
      The following four non-exclusive classes for relations are considered:
  
      - symmetry
      - anti-symmetry
      - inversion
      - composition
  
      This method generally follows the terminology of association rule mining. The patterns are expressed as
  
      .. math ::
  
          X_1 \land \cdot \land X_k \implies Y
  
      where $X_i$ is of the form $r_i(h_i, t_i)$, and some of the $h_i / t_i$ might re-occur in other atoms.
      The *support* of a pattern is the number of distinct instantiations of all variables for the left hand side.
      The *confidence* is the proportion of these instantiations where the right-hand side is also true.
  
      :param dataset:
          The dataset to investigate.
      :param min_support:
          A minimum support for patterns.
      :param min_confidence:
          A minimum confidence for the tested patterns.
      :param drop_confidence:
          Whether to drop the support/confidence information from the result frame, and also drop duplicates.
      :param parts:
          Only use certain parts of the dataset, e.g., train triples. Defaults to using all triples, i.e.
          {"training", "validation", "testing}.
      :param force:
          Whether to enforce re-calculation even if a cached version is available.
      :param add_labels:
          Whether to add relation labels (if available).
  
      .. warning ::
  
          If you intend to use the relation categorization as input to your model, or hyper-parameter selection, do *not*
          include testing triples to avoid leakage!
  
      :return:
          A dataframe with columns {"relation_id", "pattern", "support"?, "confidence"?}.
      """
      # TODO: Merge with _common?
      parts = _normalize_parts(dataset, parts)
      mapped_triples = _get_mapped_triples(dataset, parts)
  
      # include hash over triples into cache-file name
      ph = triple_analysis.triple_set_hash(
          mapped_triples=mapped_triples
      )[:16]
  
      # include part hash into cache-file name
      cache_path = PYKEEN_DATASETS.joinpath(
          dataset.__class__.__name__.lower(),
          f"relation_patterns_{ph}.tsv.xz",
      )
  
      # re-use cached file if possible
      if not cache_path.is_file() or force:
          # select triples
          mapped_triples = torch.cat(
              [
                  dataset.factory_dict[part].mapped_triples
                  for part in parts
              ],
              dim=0,
          ).tolist()
  
          df = triple_analysis.relation_pattern_types(
              mapped_triples=mapped_triples
          )
  
          # save to file
          cache_path.parent.mkdir(exist_ok=True, parents=True)
          df.to_csv(cache_path, sep="\t", index=False)
          logger.info(
              f"Cached {len(df)} relational pattern entries to {cache_path.as_uri()}"
          )
      else:
          df = pd.read_csv(cache_path, sep="\t")
          logger.info(
              f"Loaded {len(df)} precomputed relational patterns from {cache_path.as_uri()}"
          )
  
      # Prune by support and confidence
      sufficient_support = (
          df[triple_analysis.SUPPORT_COLUMN_NAME] >= min_support
      )
      sufficient_confidence = (
          df[triple_analysis.CONFIDENCE_COLUMN_NAME] >= min_confidence
      )
      df = df[sufficient_support & sufficient_confidence]
  
      if drop_confidence:
          df = df[
              [
                  triple_analysis.RELATION_ID_COLUMN_NAME,
                  triple_analysis.PATTERN_TYPE_COLUMN_NAME,
              ]
          ].drop_duplicates()
  
      return triple_analysis.add_relation_labels(
          df=df,
          add_labels=add_labels,
          label_to_id=dataset.relation_to_id,
      )
  
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 7 for calling a global function with example usage: get_relation_pattern_types_df(dataset) and returns: triple_analysis