def METHOD_NAME(qid, ranking, args_positives, depth, permissive, biased):
    """
        Requires that the ranks are sorted per qid.
    """
    positives, negatives, triples = [], [], []
    for pid, rank, *_, label in ranking:
        assert rank >= 1, f"ranks should start at 1 \t\t got rank = {rank}"
        assert label in [0, 1]
        if rank > depth:
            break
        if label:
            take_this_positive = any(rank <= maxDepth and len(positives) < maxBest for maxBest, maxDepth in args_positives)
            if take_this_positive:
                positives.append((pid, 0))
            elif permissive:
                positives.append((pid, rank))  # utilize with a few negatives, starting at (next) rank
        else:
            negatives.append(pid)
    for pos, neg_start in positives:
        num_sampled = 100 if neg_start == 0 else 5
        negatives_ = negatives[neg_start:]
        biased_ = biased if neg_start == 0 else None
        for neg in sample_negatives(negatives_, num_sampled, biased=biased_):
            triples.append((qid, pos, neg))
    return triples