from typing import Dict
from typing import Set
import collections


def load_qrels(path: str) -> Dict[str, Set[str]]:
    """Loads qrels into a dict of key: query_id, value: set of relevant doc ids."""
    qrels = collections.defaultdict(set)
    with open(path) as f:
        for i, line in enumerate(f):
            line = ' '.join(line.split())
            query_id, _, doc_id, relevance = line.rstrip().split()
            qrels[query_id].add(doc_id)

    return qrels