我使用 nltk 来获取标记化关键字的列表。输出是
['Natural', 'Language', 'Processing', 'with', 'PythonNatural', 'Language', 'Processingwith', 'PythonNatural', 'Language', 'Processing', 'with', 'Python', 'Editor', ':', 'Production', 'Editor', ':', 'Copyeditor']
我有一个文本文件 keyword.txt,其中包含以下关键字:
Processing
Editor
Pyscripter
Language
Registry
Python
如何将通过标记化获得的关键字与我的 keyword.txt 文件匹配,以便为匹配的关键字创建第三个文件。
这是我一直在研究的程序,但它创建了这两个文件的联合:
import os
with open(r'D:\file3.txt', 'w') as fout:
keywords_seen = set()
for filename in r'D:\File1.txt', r'D:\Keyword.txt':
with open(filename) as fin:
for line in fin:
keyword = line.strip()
if keyword not in keywords_seen:
fout.write(line + "\n")
keywords_seen.add(keyword)