from typing import Sequence
from typing import Tuple


def count_origins(
    generated_texts: Sequence[Tuple[str, ...]],
    train_texts: Sequence[Tuple[str, ...]],
    dev_texts: Sequence[Tuple[str, ...]],
) -> Tuple[int, int, int]:
    """Count the proportion of generated texts that are in the train or dev
    sets, or are novel texts.

    This can be useful when training a language model to get a sense of
    whether the model has just memorized the training set. This wouldn't be
    useful for a large domain where texts are unlikely to repeat themselves
    entirely (e.g. generated paragraphs of text) but could be useful in a
    much more constrained domain like words of less than 15 characters.

    Args:
    - generated_texts: a Sequence of texts, each of which is a tuple of tokens.
    - train_texts: same format as `generated_texts`.
    - dev_texts: same format as `generated_texts`.

    Returns a triple, which is the proportion of generated texts that are:
    1. in the train set
    2. in the dev set
    3. novel
    """
    train = dev = novel = 0
    for text in generated_texts:
        if text in train_texts:
            train += 1
        elif text in dev_texts:
            dev += 1
        else:
            novel += 1

    total = len(generated_texts)
    return (int(train / total * 100), int(dev / total * 100), int(novel / total * 100))