def apply_threshold(weights, goal):
    """ Returns a set of keywords such that the set is of minimal size,
    but the goal is met. The goal should be a float from 0 to 1.0 representing
    the fraction of the total body of keywords that should be represented
    by the keyword set. Currently weights are a simple fraction, so keywords
    are added until the sum of the added keyword weights meets or exceeds
    the goal."""
    all_keys = iter(sorted(weights.keys(), key=lambda k: weights[k],
        reverse=True))

    result = {}
    current = 0

    while current < goal:
        key = next(all_keys, None)
        if not key:
            break
        current += weights[key]
        result[key] = weights[key]

    return result