【发布时间】:2011-12-29 03:05:45
【问题描述】:
我正在尝试使用 nltk 以非常低保真的方式对新闻文章进行自动分类。我创建了一个与我的类别相关的单词/标签对的自定义语料库(即教师/EDU、计算机/技术等)我一直在阅读,this question 让我非常接近,但我仍然卡住了。
根据我目前的代码,如何使用我的标记器来标记我的句子?
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'
这也很可能是一种糟糕的方式来做我想做的事情,但对于第一次运行来说似乎已经足够了。提前致谢。
【问题讨论】: