def get_brand_triplets(item_metas, brand2id, iid2id, relation_id):
    """
    Builds triplets based on brands.
    For each item: (item, has_brand, brand)

    :param item_metas: list of amazon metadata objects
    :param brand2id: dict of brand ids
    :param iid2id: dict of item ids
    :param relation_id: relation index for has_brand relation
    :return: list of triplets
    """
    triplets = set()
    for it_meta in item_metas:
        if it_meta.brand:
            item_id = iid2id[it_meta.id]
            brand_id = brand2id[it_meta.brand]
            triplets.add((item_id, relation_id, brand_id))
    return list(triplets)