将IOB格式的数据列表转换为简单的IOB格式的数据

时间:2019-06-26 14:08:34

标签: python python-3.x nlp format

我是nlp的初学者,想从句子列表中生成IOB格式。

我具有以下格式的IOB格式的数据:

[('in', 'O'), ('this', 'B-DATE'), ('week', 'I-DATE'), ('how', 'O'), ('many', 'O'), ('activities', 'O'), ('do', 'O'), ('i', 'O'), ('have', 'O'), ('?', 'O')]

预期输出为

in O
this B-DATE
week I-DATE
how O
many O
activities O
do O
i O
have O
? O

1 个答案:

答案 0 :(得分:0)

如果您需要一个仅包含由初始列表的成员组成的字符串的新list,则可以尝试以下操作:

initial = [('in', 'O'), ('this', 'B-DATE'), ('week', 'I-DATE'), ('how', 'O'), ('many', 'O'), ('activities', 'O'), ('do', 'O'), ('i', 'O'), ('have', 'O'), ('?', 'O')]

modified = [' '.join(z) for z in initial]

for row in modified:
    print(row)

输出:

in O
this B-DATE
week I-DATE
how O
many O
activities O
do O
i O
have O
? O