import io
import json


def collect_data(*paths):
    """
    Collect set of relations occurring in given samples.
    :param paths: Paths of json files containing samples.
    :return: Set of relation tuples.
    """
    # First, we read json samples to learn relations from
    samples = []
    for path in paths:
        with io.open(path, 'r', encoding='utf-8') as f:
            samples += json.load(f)

    # Collect all the occurring relations
    relations = set()
    for sample in samples:
        entities = sample['entities']
        for interaction in sample['interactions']:
            i, j = interaction['participants']
            for a in entities[i]['names']:
                for b in entities[j]['names']:
                    relations.add((a, b))
                    relations.add((b, a))

    return relations