【发布时间】:2019-01-01 12:42:53
【问题描述】:
我有两个 txt 文件,一个非常大(txt 文件 1)有 15000 个句子,每行都以固定的格式(句子索引、单词、标签)分解。我有另一个文本文件(txt 文件 2),其中大约 500 个句子被分解为格式(句子索引、单词)。我想从“txt file 2”中找到“txt file 1”中的句子,但我还需要提取标签。
txt 文件 1 的格式:
1 Flurazepam O
2 thus O
3 appears O
4 to O
5 be O
6 an O
7 effective O
8 hypnotic O
9 drug O
10 with O
txt 文件 2 的格式:
1 More
2 importantly
3 ,
4 this
5 fusion
6 converted
7 a
8 less
9 effective
10 vaccine
最初,我只是尝试了一些愚蠢的事情:
txtfile1=open("/Users/Desktop/Final.txt").read().split('\n')
with open ('/Users/Desktop/sentenceineed.txt','r') as txtfile2:
whatineed=[]
for line in txtfile2:
for part in txtfile1:
if line == part:
whatineed.append(part)
这次尝试我什么也没得到,实际上是一个空列表。任何建议都会很棒。
【问题讨论】:
-
你给textfile1中的tags的值为0,tags的格式是什么?或者您也可以共享所需的输出类型。
-
这是 IOB 标记,唯一可能的标记是 O、B 或 I。我想要的输出是我句子中的单词和标记。我不太关心索引。
标签: python