2017-03-15 13 views
-1

私は、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

+0

第2の例では、 'nltk.ngrams(x、n)'は 'len(x) lenz

答えて

0

ファイルを読んでいないの解決に私を助けてください。

代わりに、ファイル名を連結し、それを解析しようとします。

これを修正する必要があります。

+0

私は解決策が必要です – user103987

+0

あなたが必要なものはすべてあります。変数を正しく取得するだけです。 –

関連する問題