def convert_optional_str_by_type(str_val, type_func, default_val):
    """Converts an optional string using the type_func, else uses the default.
    """
    if (str_val == '<UNK>') or (str_val is None):
        return type_func(default_val)

    return type_func(str_val)