from typing import Iterable
import torch
from typing import Dict
from typing import List


def cluster_strings(strings: Iterable[str]) -> torch.Tensor:
    """
    given a list of strings, assigns a clustering, where
    each pair of identical ground truth strings is in the same
    cluster
    return a torch.LongTensor containing the cluster id of
    each ground truth
    """
    cluster_id_by_truth: Dict[str, int] = {}
    cluster_l: List[int] = []
    for n, truth in enumerate(strings):
        cluster_id = cluster_id_by_truth.setdefault(truth, len(cluster_id_by_truth))
        cluster_l.append(cluster_id)
    return torch.tensor(cluster_l, dtype=torch.int64)