code: def relation_cardinality_types(
      mapped_triples: Collection[Tuple[int, int, int]],
      add_labels: bool = True,
      label_to_id: Optional[Mapping[str, int]] = None,
  ) -> pd.DataFrame:
      r"""
      Determine the relation cardinality types.
  
      The possible types are given in relation_cardinality_types.
  
      .. note ::
          In the current implementation, we have by definition
  
          .. math ::
              1 = \sum_{type} conf(relation, type)
  
      .. note ::
         These relation types are also mentioned in [wang2014]_. However, the paper does not provide any details on
         their definition, nor is any code provided. Thus, their exact procedure is unknown and may not coincide with this
         implementation.
  
      :param mapped_triples:
          The ID-based triples.
      :param add_labels:
          Whether to add relation labels (if available).
      :param label_to_id:
          The label to index mapping.
  
      :return:
          A dataframe with columns ( relation_id | relation_type )
      """
      # iterate relation types
      base = iter_relation_cardinality_types(
          mapped_triples=mapped_triples
      )
  
      # drop zero-confidence
      base = (pattern for pattern in base if pattern.confidence > 0)
  
      # keep only skyline
      # does not make much sense, since there is always exactly one entry per (relation, pattern) pair
      # base = skyline(base)
  
      # create data frame
      df = pd.DataFrame(
          data=base,
          columns=[
              RELATION_ID_COLUMN_NAME,
              CARDINALITY_TYPE_COLUMN_NAME,
              SUPPORT_COLUMN_NAME,
              CONFIDENCE_COLUMN_NAME,
          ],
      )
      return add_relation_labels(
          df, add_labels=add_labels, label_to_id=label_to_id
      )
  
imports: import hashlib
  import itertools
  import logging
  from collections import defaultdict
  from typing import Collection, DefaultDict, Iterable, Mapping, NamedTuple, Optional, Sequence, Set, Tuple, Union
  import numpy
  import pandas
  from tqdm.auto import tqdm
  from .None import TriplesFactory
  from ..constants import COLUMN_LABELS, TARGET_TO_INDEX
  from ..typing import COLUMN_HEAD, COLUMN_RELATION, COLUMN_TAIL, LABEL_HEAD, LABEL_RELATION, LABEL_TAIL, MappedTriples
label_desc: Use image node_id 23 for calling a global function with example usage: relation_cardinality_types(mapped_triples, add_labels, label_to_id) and returns: add_relation_labels