def _is_transition_allowed(from_tag: str,
                           from_entity: str,
                           to_tag: str,
                           to_entity: str):
    """
    BIO 是否被允许转移。比如: "B-Per" "I-Per" 这是被允许的; 而 "B-Per" "I-Loc" 或者 "O", "I-Per" 这是不被允许的
    :param from_tag: The tag that the transition originates from. For example, if the
        label is ``I-PER``, the ``from_tag`` is ``I``.
    :param from_entity: The entity corresponding to the ``from_tag``. For example, if the
        label is ``I-PER``, the ``from_entity`` is ``PER``.
    :param to_tag: The tag that the transition leads to. For example, if the
        label is ``I-PER``, the ``to_tag`` is ``I``.
    :param to_entity: The entity corresponding to the ``to_tag``. For example, if the
        label is ``I-PER``, the ``to_entity`` is ``PER``.
    :return: True: 该转移是被允许的; False: 该转移是不被允许的。
    """

    if to_tag == "START" or from_tag == "END":
        # Cannot transition into START or from END
        return False

    if from_tag == "START":
        return to_tag in ('O', 'B')

    if to_tag == "END":
        return from_tag in ('O', 'B', 'I')

    return any([
        # Can always transition to O or B-x
        to_tag in ('O', 'B'),
        # Can only transition to I-x from B-x or I-x
        to_tag == 'I' and from_tag in ('B', 'I') and from_entity == to_entity
    ])