2011-12-28 16 views
0

nltkを使用して、ニュース記事を非常にlo-fiの方法で自動分類しようとしています。私は私のカテゴリ(すなわち、教師/ EDU、コンピュータ/ TECHなど)に関連する単語/タグのペアのカスタムコーパスを作成しました。this questionは私をかなり近づけましたが、私はまだ固執しています。nltkのTaggedCorpusReaderとUnigramTagger(Python)

これまでの私のコードに基づいて、タグを使って私の文にタグを付けるにはどうすればよいですか?

import nltk 

# Loads my custom word/tag corpus 
from nltk.corpus.reader import TaggedCorpusReader 
reader = TaggedCorpusReader('taggers','.*') 

#Sets up the UnigramTagger 
default_tagger = nltk.data.load(nltk.tag._POS_TAGGER) 
tagger = nltk.tag.UnigramTagger(model=reader.tagged_words(), backoff=default_tagger) 

#Sample content 
sent = 'The students went to school to ask their teacher what the homework for the day was but she told them to check their email.' 
tokens = nltk.tokenize.word_tokenize(sent) 

# Sad Panda 
tagged = tagger.tag(tokens) 
#^produces AttributeError: 'ConcatenatedCorpusView' object has no attribute 'get' 

これは私が何をしようとしていることについて移動する貧弱な方法であることも非常に可能ですが、それは最初の実行のために十分に良いようです。前もって感謝します。

答えて

2

タグ付けは、テキストの分類ではなく、品詞タグ付けのためのものです。ロイターコーパスを見てみましょう - ニュース記事をカテゴリファイルを使用して複数のカテゴリに分類します。次に、nltk.classifyモジュールを見て、テキスト分類子を訓練する方法を読んでください。

+0

ありがとう、Jacob、あなたは正しい方向に私を指摘しました。用語は、正しい経路を見つけるための鍵でした。ありがとう! –

関連する問題