import random


def create_neg_relations(entities, rels_between_entities, rel_type_count, neg_rel_count):
    """ Creates negative relation samples, i.e. pairs of entities that are unrelated according to ground truth """

    neg_unrelated = []

    # search unrelated entity pairs
    for i1, _ in enumerate(entities):
        for i2, _ in enumerate(entities):
            if i1 != i2:
                pair = (i1, i2)
                if pair not in rels_between_entities:
                    neg_unrelated.append(pair)

    # sample negative relations
    neg_unrelated = random.sample(neg_unrelated, min(len(neg_unrelated), neg_rel_count))
    neg_rel_entity_pairs, neg_rel_types = [], []

    for pair in neg_unrelated:
        one_hot = [0] * rel_type_count
        neg_rel_entity_pairs.append(pair)
        neg_rel_types.append(one_hot)

    return neg_rel_entity_pairs, neg_rel_types