def get_rank_function(rank_method):
    """
    Gets the function to calculate the rank of a entity based on the
    `rank_method`. The function receives two inputs: (1) the number of entities
    whose rank is greater than the rank of the target entity; (2) the number
    of entities whose rank is equal to the rank of the target entity
    (without the target entity itself).

    :param rank_method: the rank method. If `pessimistic`, sums the number of
    entities with rank greater than or equals to the rank of the target
    entity; if `average`, sums the number of entities with rank greater than
    the rank of the target entities and half the number of entities with rank
    equals to the rank of the target entity; otherwise, returns the `optimistic`
    rank, which sums only the number of entities with rank greater than the
    rank of the target entity.
    :type rank_method: str
    :return: the function
    :rtype: function
    """
    if rank_method == "pessimistic":
        return lambda bigger_than, equals_to: bigger_than + equals_to + 1
    elif rank_method == "average":
        return lambda bigger_than, equals_to: \
            bigger_than + int(equals_to / 2) + 1
    else:
        return lambda bigger_than, equals_to: bigger_than + 1