NLTK 中单个单词的标记器

Tagger for single words in NLTK

是否有标记器可以 return 在任何上下文中为单词添加单个标记?

我的要求是我需要从句子没有结构化语法的非结构化文本中提取单词。

词性标注器旨在处理句子,并且会 return 根据单词在句子中的上下文为单词添加标签。因此,我要么必须使用另一个标记器,它每次都会为特定单词提供相同的标记,要么在分块时为一个单词使用所有可能的标记。

任何其他解决方案将不胜感激。另外,您如何查看可以为特定单词分配的所有标签?

参见:http://www.nltk.org/_modules/nltk/tag.html

特别是:

>>> from nltk.corpus import brown
>>> from nltk.tag import UnigramTagger
>>> tagger = UnigramTagger(brown.tagged_sents(categories='news')[:500])
>>> sent = ['Mitchell', 'decried', 'the', 'high', 'rate', 'of', 'unemployment']
>>> for word, tag in tagger.tag(sent):
...     print(word, '->', tag)
Mitchell -> NP
decried -> None
the -> AT
high -> JJ
rate -> NN
of -> IN
unemployment -> None

UnigramTagger 的想法是它始终为训练语料库中的特定单词分配最突出的标签。或者(就在文档中的代码段上方:

This package defines several taggers, which take a token list (typically a sentence), assign a tag to each token, and return the resulting list of tagged tokens. Most of the taggers are built automatically based on a training corpus. For example, the unigram tagger tags each word w by checking what the most frequent tag for w was in a training corpus:

不确定是否有内置方法来查看可以分配给特定单词的所有标签。而且;这在理论上可能与识别的标签总数一样长,因为它取决于上下文。 如果你想得到一个想法;我要做的就是标记你的整个词汇表,并打印出你的词汇表,其中包含在该特定语料库中分配的所有不同标签。