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
一致したキーワードに対して 3 番目のファイルが作成されるように、トークン化から取得したキーワードを自分の keyword.txt ファイルと一致させるにはどうすればよいですか。
これは私が取り組んできたプログラムですが、次の 2 つのファイルの和集合を作成します。
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)