(clusters: DefaultDict[int, List[Tuple[int, int]]])
return [list(c) for c in merged_clusters]
The CONLL 2012 data includes 2 annotatated spans which are identical,
    but have different ids. This checks all clusters for spans which are
    identical, and if it finds any, merges the clusters containing the
    identical spans.
The CONLL 2012 data includes 2 annotatated spans which are identical,
    but have different ids. This checks all clusters for spans which are
    identical, and if it finds any, merges the clusters containing the
    identical spans.
The CONLL 2012 data includes 2 annotatated spans which are identical but have different ids . This checks all clusters for spans which are identical and if it finds any merges the clusters containing the identical spans .
def canonicalize_clusters(clusters: DefaultDict[int, List[Tuple[int, int]]]) -> List[List[Tuple[int, int]]]:
    """
    The CONLL 2012 data includes 2 annotatated spans which are identical,
    but have different ids. This checks all clusters for spans which are
    identical, and if it finds any, merges the clusters containing the
    identical spans.
    """
    merged_clusters: List[Set[Tuple[int, int]]] = []
    for cluster in clusters.values():
        cluster_with_overlapping_mention = None
        for mention in cluster:
            # Look at clusters we have already processed to
            # see if they contain a mention in the current
            # cluster for comparison.
            for cluster2 in merged_clusters:
                if mention in cluster2:
                    # first cluster in merged clusters
                    # which contains this mention.
                    cluster_with_overlapping_mention = cluster2
                    break
            # Already encountered overlap - no need to keep looking.
            if cluster_with_overlapping_mention is not None:
                break
        if cluster_with_overlapping_mention is not None:
            # Merge cluster we are currently processing into
            # the cluster in the processed list.
            cluster_with_overlapping_mention.update(cluster)
        else:
            merged_clusters.append(set(cluster))
    return [list(c) for c in merged_clusters]
def canonicalize_clusters ( clusters : DefaultDict [ int , List [ Tuple [ int , int ] ] ] ) -> List [ List [ Tuple [ int , int ] ] ] : merged_clusters : List [ Set [ Tuple [ int , int ] ] ] = [ ] for cluster in clusters . values ( ) : cluster_with_overlapping_mention = None for mention in cluster : # Look at clusters we have already processed to # see if they contain a mention in the current # cluster for comparison. for cluster2 in merged_clusters : if mention in cluster2 : # first cluster in merged clusters # which contains this mention. cluster_with_overlapping_mention = cluster2 break # Already encountered overlap - no need to keep looking. if cluster_with_overlapping_mention is not None : break if cluster_with_overlapping_mention is not None : # Merge cluster we are currently processing into # the cluster in the processed list. cluster_with_overlapping_mention . update ( cluster ) else : merged_clusters . append ( set ( cluster ) ) return [ list ( c ) for c in merged_clusters ]