def _determine_sentence_id(sentence, new_id, id_name, old_id):
    """
    Determine the appropriate id for this sentence.

    Ids here means doc id or par id.

    Args:
    sentence: The sentence whose ids to check.
    new_id: The key that the id can come up as without the id key word.
    id_name: The id in the comments to modify. One of 'newpar id', or
        'newdoc id'.
    old_id: The id of the previous sentence.

    Returns:
    The value of the id of the sentence.
    """
    if sentence.meta_present(id_name):
        return sentence.meta_value(id_name)
    elif sentence.meta_present(new_id):
        return None
    else:
        return old_id