1
私は、posタグが存在するposタグを持つファイルからそれらの単語だけを抽出するプログラムを持っています。私のプログラムは何のエラーも出さないが、何も表示されない。実行するだけです。ここに私のサンプル入力は次のとおりです。ここで名詞タグを持つファイルからそれらの単語だけを取り出す方法は?
[['For,IN', ',,,', 'We,PRP', 'the,DT', 'divine,NN', 'caused,VBD', 'apostle,NN', 'We,PRP', 'vouchsafed,VBD', 'unto,JJ', 'Jesus,NNP', 'the,DT', 'son,NN', 'of,IN', 'Mary,NNP', 'all,DT', 'evidence,NN', 'of,IN', 'the,DT', 'truth,NN', ',,,', 'and,CC', 'strengthened,VBD', 'him,PRP', 'with,IN', 'holy,JJ'], [ 'be,VB', 'nor,CC', 'ransom,NN', 'taken,VBN', 'from,IN', 'them,PRP', 'and,CC', 'none,NN', '\n']]
は私のコードは次のとおりです。ここで
import nltk
import os.path
import re
import os
sample_text4='E://QuranCopies45.txt'
file2 = open(sample_text4,'r',encoding='utf8')
arr=[]
for line in file2.readlines():
words=re.split(' ',line)
words=[line.replace('/',",")for line in words]
arr.append(words)
pos_tags = ('NN', 'NNP', 'NNS', 'NNPS')
nouns=[s.split(',')[0] for sub in arr for s in sub if s.endswith(pos_tags)]
print(nouns)
は私の予想出力されます。
[ 'divine', 'apostle','Jesus', 'son','Mary', 'evidence', 'truth', 'ransom', 'none']
まだ何もしていません。 – Nisa
@ニサスクリプトを保存してみてください... –
私はそれを保存しましたが、何のエラーもなく実行され、何も表示されません。 – Nisa