2017-10-26 8 views
0

私は、各単語が全コーパスに何回出現するかを数えようとしています。
しかし、私はエラーを取得しています:私は取得しています全コーパス中のすべての剣の頻度をカウントする

corpus_root = os.path.abspath('../nlp_urdu/out1_data') 
    mycorpus = nltk.corpus.reader.TaggedCorpusReader(corpus_root,'.*') 
    noun=[] 
    count_freq = defaultdict(int) 
    for infile in (mycorpus.fileids()): 
     print(infile) 
    for i in (mycorpus.tagged_sents()): 
     texts = [word for word, pos in i if (pos == 'NN')] 
     noun.append(texts) 
     count_freq[noun]+= 1 
     print(count_freq) 

エラーは次のとおりです。

count_freq [名詞] + = 1

TypeError:非ハッシュの種類: 'リスト'

+1

各キー必須と辞書です。 –

答えて

0

textsnoun
count_freqは、テキストマイニングしている場合は、CountVectorizerまたはTFIDFを見なければならない必要がありますnounstring

corpus_root = os.path.abspath('../nlp_urdu/out1_data') 
    mycorpus = nltk.corpus.reader.TaggedCorpusReader(corpus_root,'.*') 
    count_freq = defaultdict(int) 
    for infile in (mycorpus.fileids()): 
     print(infile) 
    for i in (mycorpus.tagged_sents()): 
     texts = [word for word, pos in i if (pos == 'NN')] 
     for noun in texts :    
      count_freq[noun]+= 1 

    print(count_freq) 
+0

実際に私は名詞である単語を使用しました。それらの単語は "テキスト"にあり、名詞のような名前のリストにあるコーパスからの全名詞が追加されました。 – user3778289

+0

これは正しいoutput.thereを表示していません13000名詞です。ちょうど1つのファイルを繰り返す – user3778289

関連する問題