class_docstr: This combinator merges all matching entity pairs into a single ID.
class_docstr_tok: ["This","combinator","merges","all","matching","entity","pairs","into","a","single","ID","."]
code: def process(
      self,
      mapped_triples: MappedTriples,
      alignment: torch.LongTensor,
      offsets: torch.LongTensor,
  ) -> ProcessedTuple:  # noqa: D102
      # determine connected components regarding the same-as relation (i.e., applies transitivity)
      entity_id_mapping = torch.arange(
          mapped_triples[:, 0::2].max().item() + 1
      )
      for cc in get_connected_components(pairs=alignment.t().tolist()):
          cc = list(cc)
          entity_id_mapping[cc] = min(cc)
      # apply id mapping
      h, r, t = mapped_triples.t()
      h_new, t_new = entity_id_mapping[h], entity_id_mapping[t]
      # ensure consecutive IDs
      inverse = torch.cat([h_new, t_new]).unique(return_inverse=True)[1]
      h_new, t_new = inverse.split((len(h), len(t)))
      mapped_triples = torch.stack([h_new, r, t_new], dim=-1)
      # only use training alignments?
      return ProcessedTuple(
          mapped_triples,
          torch.empty(size=(2, 0), dtype=torch.long),
          dict(
              entity_mappings=list(
                  iter_entity_mappings(
                      (h, h_new), (t, t_new), offsets=offsets[:, 0]
                  )
              ),
              relation_offsets=offsets[:, 1],
          ),
      )
  
imports: import logging
  from abc import ABC, abstractmethod
  from collections import defaultdict
  from typing import Any, ClassVar, DefaultDict, Dict, Iterable, Mapping, NamedTuple, Optional, Sequence, Set, Tuple, Union
  import numpy
  import pandas
  import torch
  from class_resolver import ClassResolver
  from pandas.api.types import is_numeric_dtype, is_string_dtype
  from ...triples import CoreTriplesFactory, TriplesFactory
  from ...typing import COLUMN_HEAD, COLUMN_TAIL, EA_SIDE_LEFT, EA_SIDE_RIGHT, EA_SIDES, MappedTriples, TargetColumn
  from ...utils import format_relative_comparison, get_connected_components
label_desc: Use image node_id 1 for calling the CollapseGraphPairCombinator obj's underlying member method code with example usage: obj.process(mapped_triples, alignment, offsets) and returns: ProcessedTuple