code: def iter_ternary_patterns(
      mapped_triples: Collection[Tuple[int, int, int]],
      pairs: Mapping[int, Set[Tuple[int, int]]],
  ) -> Iterable[PatternMatch]:
      r"""
      Yield ternary patterns from pre-indexed triples.
  
      ===========  ===========================================
      Pattern      Equation
      ===========  ===========================================
      Composition  $r'(x, y) \land r''(y, z) \implies r(x, z)$
      ===========  ===========================================
  
      :param mapped_triples:
          A collection of ID-based triples.
      :param pairs:
          A mapping from relations to the set of entity pairs.
  
      :yields: A pattern match tuple of relation_id, pattern_type, support, and confidence.
      """
      logger.debug("Evaluating ternary patterns: {composition}")
      # composition r1(x, y) & r2(y, z) => r(x, z)
      adj = get_adjacency_dict(mapped_triples)
  
      # actual evaluation of the pattern
      for r1, r2 in tqdm(
          composition_candidates(mapped_triples),
          desc="Checking ternary patterns",
          unit="pattern",
          unit_scale=True,
      ):
          lhs = {(x, z) for x, y in pairs[r1] for z in adj[r2][y]}
          support = len(lhs)
          # skip empty support
          # TODO: Can this happen after pre-filtering?
          if not support:
              continue
          for r, ht in pairs.items():
              confidence = len(lhs.intersection(ht)) / support
              yield PatternMatch(
                  r, PATTERN_TYPE_COMPOSITION, support, confidence
              )
  
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 10 for calling a global function with example usage: iter_ternary_patterns(mapped_triples, pairs) without return types