def update_tag_scheme(sentences, tag_scheme):
    """
    更新为制定编码 BIO->BIOES
    :param sentences:
    :param tag_scheme:
    :return:
    """
    # 首先是检测编码是否为BIO
    for i, s in enumerate(sentences):
        tags = [w[-1] for w in s]
        # 首先是检测编码是否为BIO
        if not data_utils.check_bio(tags):
            s_str = "\n".join(" ".join(w) for w in s)  # "\n".join(" ".join(w) for w in s)
            raise Exception("输入的句子应为BIO编码,请检查输入句子%i:\n%s" % (i, s_str))

        if tag_scheme == "BIO":
            for word, new_tag in zip(s, tags):
                word[-1] = new_tag

        if tag_scheme == "BIOES":
            new_tags = data_utils.bio_to_bioes(tags)
            for word, new_tag in zip(s, new_tags):
                word[-1] = new_tag
        else:
            raise Exception("非法目标编码!既不是BIO也不是BIOES")
Exemple #2
0
def update_tag_scheme(sentences, tag_scheme):
    """
    更新为指定编码
    :param sentences:
    :param tag_scheme:
    :return:
    """
    for i, s in enumerate(sentences):
        tags = [w[-1] for w in s]
        if not du.check_bio(tags):
            s_str = '\n'.join(" ".join(w) for w in s)
            raise Exception("输入的句子应为BIO编码,请检查输入句子%i:\n%s" % (i, s_str))
        if tag_scheme == 'BIOES':
            new_tags = du.bio_to_bioes(tags)
            for word, new_tag in zip(s, new_tags):
                word[-1] = new_tag
def update_tag_scheme(sentences, tag_scheme):
    """
    更新为指定标签
    :param sentences:
    :param tag_scheme:
    :return:
    """
    for i, s in enumerate(sentences):
        tags = [w[-1] for w in s]
        if not data_utils.check_bio(tags):
            raise Exception('输入的句子应为BIO标注法,请检查%i句' % i)

        if tag_scheme == 'BIO':
            for word, new_tag in zip(s, tags):
                word[-1] = new_tag

        if tag_scheme == 'BIOES':
            new_tags = data_utils.bio_to_bioes(tags)
            for word, new_tag in zip(s, new_tags):
                word[-1] = new_tag
        else:
            raise Exception('非法编码')
def update_tag_scheme(sentences, tag_scheme):
    """
    将BIO编码更新为BIOES编码
    :param sentences:
    :param tag_scheme:
    :return:
    """
    for i, s in enumerate(sentences):
        tags = [w[-1] for w in s]
        if not data_utils.check_bio(tags):
            s_str = '\n'.join(' '.join(w) for w in s)
            raise Exception('输入的句子应为BIO编码, 请检查句子%i:\n%s' % (i, s_str))

        if tag_scheme == 'BIO':
            for word, tag in zip(s, tags):
                word[-1] = tag

        elif tag_scheme == 'BIOES':
            new_tags = data_utils.bio_to_bioes(tags)
            for word, new_tag in zip(s, new_tags):
                word[-1] = new_tag

        else:
            raise Exception('非法编码')