import re


def _agg_removing_duplicates(agg_elem):
    """Aggregate while removing the duplicates.

    Aggregate the labels or alt labels together as a single element
    can have several Wikidata entities that need to be merged.

    Args:
        agg_elem (list of string): elem to aggregate

    Returns:
        string: aggregation with the deletion of the duplicates

    """
    str_elem = '|'.join(agg_elem)
    list_elem = str_elem.split('|')

    # Removing the name of WikiData when there is no labels in the languages
    regex = re.compile(r'Q[0-9]+')
    list_elem = [elem for elem in list_elem if not regex.match(elem)]

    list_elem_without_duplicates = list(set(list_elem))
    list_elem_without_duplicates.sort()
    elem_without_duplicates = '|'.join(list_elem_without_duplicates)

    return elem_without_duplicates