from typing import Dict
from typing import Tuple
from typing import Set


def precision_recall_k(benchmark: Dict, results: Dict,
                       repo: str, k: int) -> Tuple[float, float, int, Set[str]]:
    """
    Calculate the precision, recall, and "found" of first K predictions for a repo.
    :param benchmark: dictionary with the real libraries from benchmark.
    :param results: dictionary with the predicted libraries.
    :param repo: full name of the repo.
    :param k: number of first predictions to consider.
    :return: tuple (precision, recall, found, correct guesses)
    """
    true_libraries = benchmark[repo]
    suggestions = results[repo][:k]
    positive_guesses = set(true_libraries).intersection(set(suggestions))
    precision = len(positive_guesses) / len(suggestions)
    recall = len(positive_guesses) / len(true_libraries)
    found = len(positive_guesses)
    return precision, recall, found, positive_guesses