私は、PythonでNLTKツールを使用している非英語コーパス解析であるSindhiに取り組んでいます。私はPythonですべての関係する自由をインポートし、zipファイルを読み込むためのコードを処理しました。 zipファイルのコードが正常に動作し、データをロードしています。コードは以下の通りである:Python NLTK ngramコードで結果が得られません
with zipfile.ZipFile('D:\Sindhicorpus.zip') as z:
print (len(z.namelist()))
for filename in z.namelist():
if not os.path.isdir(filename):
# read the file
with z.open(filename, 'rU') as rf:
line = rf.readline().decode('utf8')
# print(line)
ngramsを生成するため、このI処理コードの後であるが、そのコードがエラーなしで示す結果をしません。コードは以下の通りである:
import nltk
from nltk.collocations import *
line = ""
for val in filename:
line += val
tokens = line.split()
bigram_measures = nltk.collocations.BigramAssocMeasures()
finder = BigramCollocationFinder.from_words(tokens)
finder.apply_freq_filter(3)
print(finder.nbest(bigram_measures.pmi, 100))
このコードは、単に、このコードの後、[]
ようなブラケットを示し、Iは、他のコードを処理し、それはまた、任意のエラーを示すことなく結果を示していません。コードは以下の通りです:
from nltk import ngrams
n = 2
sixgrams = ngrams(filename.split(), n)
for grams in sixgrams:
print(grams)
私の問題
Mazhar
第2の例では、 'nltk.ngrams(x、n)'は 'len(x)
lenz