from typing import Counter
from typing import OrderedDict


def build_counter(df, key):
    """Build the distribution counter for labels

    Args:
        df (pandas.DataFrame): input DataFrame, must contain "Core Relations" or "slot_set" column
        key (str): either "Core Relations" or "slot_set"

    Returns:
        OrderedDict: Ordered counter for labels
    """
    counter = Counter()
    if key == "Core Relations":
        for label in df[key].dropna():
            labels = label.split()
            counter.update(labels)
    else:
        counter = Counter(df[key])
    return OrderedDict(counter.most_common())