code: def links_from_clusters(
      clusters: ty.Iterable[ty.Set],
  ) -> ty.Tuple[
      ty.Set[ty.Tuple[ty.Hashable, ty.Hashable]],
      ty.Set[ty.Tuple[ty.Hashable, ty.Hashable]],
  ]:
      r"""
      Return a `(coreference_links, non-coreference_links)` tuple corresponding to a clustering.
  
      The links are given as sorted couples for uniqueness
      """
      clusters_lst = [list(c) for c in clusters]
      C = set()
      N = set()
      for i, c in enumerate(clusters_lst[:-1]):
          for j, e in enumerate(c[:-1]):
              # Since the links are symmetric, we only add the links between `e` and
              # the following mentions
              for f in c[j + 1 :]:
                  C.add((e, f) if e <= f else (f, e))
          for other in clusters_lst[i + 1 :]:
              for e in c:
                  for f in other:
                      N.add((e, f) if e <= f else (f, e))
      #  We missed the coreference links for the last cluster, add them here
      last_cluster = clusters_lst[-1]
      for j, e in enumerate(last_cluster):
          for f in last_cluster[j + 1 :]:
              C.add((e, f) if e <= f else (f, e))
      return C, N
  
file_path: DeepKE/src/deepke/triple_extraction/ASP/metrics/blanc.py
imports: import math
  import typing
  import numpy
label_desc: Use image node_id 4 for calling a global function with example usage: links_from_clusters(clusters) and returns: C,  N