def get_co_triplets(item_metas, get_aspect_func, iid2id, relation_id):
    """
    Creates triplets based on co_buy or co_view relations taken from metadata
    :param item_metas: list of amazon metadata objects
    :param get_aspect_func: a function that extract either co_buy or co_view data
    :param iid2id: dict of item ids
    :param relation_id: relation index
    :return: list of triplets
    """
    triplets = set()
    for item in item_metas:
        head_id = iid2id[item.id]
        for co_rel_id in get_aspect_func(item):
            if co_rel_id in iid2id:
                tail_id = iid2id[co_rel_id]
                triplets.add((head_id, relation_id, tail_id))
    return list(triplets)