我想知道如何通过NLTK标记一篇文章。根据bullet point 2.7解释 找出最常用的名词。在
def findtags(tag_prefix, tagged_text):
cfd = nltk.ConditionalFreqDist((tag, word) for (word, tag) in tagged_text
if tag.startswith(tag_prefix))
return dict((tag, cfd[tag].most_common(5)) for tag in cfd.conditions())
>>> tagdict = findtags('NN', nltk.corpus.brown.tagged_words(categories='news'))
>>> for tag in sorted(tagdict):
... print(tag, tagdict[tag])
但这真的很混乱,因为我看不出一段文本是如何被注入来找到标签的。而是使用预定义的数据结构(nltk.corpus.brown公司.tagged_单词)。不知道该怎么办。在
简而言之,:
要标记文本,请使用
nltk.pos_tag
,但要注意它的特殊之处(Python NLTK pos_tag not returning the correct part-of-speech tag):长:
NLTK数据集列表可通过以下方式找到:
^{pr2}$而
nltk.corpus.brown
语料库是自然语言处理或文本处理中最常用的语料库之一(行话参见What is the difference between corpus and lexicon in NLTK (python))。在在语料库中,所有的语料库都是标记的。要访问各种注释,请参见第1.3节http://www.nltk.org/howto/corpus.html,下面是几个示例:
结构:
nltk.corpus.brown.words()
是一个字符串列表,其中列表中的每一项都是一个单词nltk.corpus.brown.tagged_words()
是一个元组列表,第一个元素作为单词,第二个元素作为标记nltk.corpus.sents()
是一个字符串列表,其中另一个列表包含整个语料库,内部列表是一个句子nltk.corpus.tagged_sents()
是元组列表,它与nltk.corpus.sents()
相同,但内部列表是单词和标记的元组。在相关问题 更多 >
编程相关推荐