import random


def split_seen(data, rand=False, prop_dev=0.2, rnd_sd=1489215):
    """

    Split data into separate sets with overlapping headlines

    Args:
        data: FNCData object
        rand: bool, True: random split and False: use seed for official baseline split
        prop_dev: float, proportion of data for dev set
        rnd_sd: int, random seed to use for split

    Returns:
        train: list, of dict per instance
        dev: list, of dict per instance

    """

    # Initialise
    list_bodies = [body for body in data.bodies]
    n_dev_bodies = round(len(list_bodies) * prop_dev)
    r = random.Random()
    if rand is False:
        r.seed(rnd_sd)
    train = []
    dev = []

    # Generate list of bodies for dev set
    r.shuffle(list_bodies)
    list_dev_bodies = list_bodies[-n_dev_bodies:]

    # Generate train and dev sets
    for stance in data.instances:
        if stance['Body ID'] not in list_dev_bodies:
            train.append(stance)
        else:
            dev.append(stance)

    return train, dev