code: def relation_injectivity(
      mapped_triples: Collection[Tuple[int, int, int]],
      add_labels: bool = True,
      label_to_id: Optional[Mapping[str, int]] = None,
  ) -> pd.DataFrame:
      """
      Calculate "soft" injectivity scores for each relation.
  
      :param mapped_triples:
          The ID-based triples.
      :param add_labels:
          Whether to add labels.
      :param label_to_id:
          The label to index mapping.
  
      :return:
          A dataframe with one row per relation, its number of occurrences and head / tail injectivity scores.
      """
      it = _help_iter_relation_cardinality_types(mapped_triples)
      df = pd.DataFrame(
          data=it,
          columns=[
              RELATION_ID_COLUMN_NAME,
              SUPPORT_COLUMN_NAME,
              LABEL_HEAD,
              LABEL_TAIL,
          ],
      )
      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 22 for calling a global function with example usage: relation_injectivity(mapped_triples, add_labels, label_to_id) and returns: add_relation_labels