本文整理汇总了Python中nltk.tag.perceptron.PerceptronTagger方法的典型用法代码示例。如果您正苦于以下问题:Python perceptron.PerceptronTagger方法的具体用法?Python perceptron.PerceptronTagger怎么用?Python perceptron.PerceptronTagger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nltk.tag.perceptron
的用法示例。
在下文中一共展示了perceptron.PerceptronTagger方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pos_tag
# 需要导入模块: from nltk.tag import perceptron [as 别名]
# 或者: from nltk.tag.perceptron import PerceptronTagger [as 别名]
def pos_tag(tokens, tagset=None):
"""
Use NLTK's currently recommended part of speech tagger to
tag the given list of tokens.
>>> from nltk.tag import pos_tag
>>> from nltk.tokenize import word_tokenize
>>> pos_tag(word_tokenize("John's big idea isn't all that bad."))
[('John', 'NNP'), ("'s", 'POS'), ('big', 'JJ'), ('idea', 'NN'), ('is', 'VBZ'),
("n't", 'RB'), ('all', 'PDT'), ('that', 'DT'), ('bad', 'JJ'), ('.', '.')]
>>> pos_tag(word_tokenize("John's big idea isn't all that bad."), tagset='universal')
[('John', 'NOUN'), ("'s", 'PRT'), ('big', 'ADJ'), ('idea', 'NOUN'), ('is', 'VERB'),
("n't", 'ADV'), ('all', 'DET'), ('that', 'DET'), ('bad', 'ADJ'), ('.', '.')]
NB. Use `pos_tag_sents()` for efficient tagging of more than one sentence.
:param tokens: Sequence of tokens to be tagged
:type tokens: list(str)
:param tagset: the tagset to be used, e.g. universal, wsj, brown
:type tagset: str
:return: The tagged tokens
:rtype: list(tuple(str, str))
"""
tagger = PerceptronTagger()
return _pos_tag(tokens, tagset, tagger)
示例2: pos_tag_sents
# 需要导入模块: from nltk.tag import perceptron [as 别名]
# 或者: from nltk.tag.perceptron import PerceptronTagger [as 别名]
def pos_tag_sents(list_of_tokenized_text):
"""
Averaged perceptron tagger from NLTK (originally from @honnibal)
"""
global _nltk_pos_tagger
try:
_nltk_pos_tagger
except NameError:
_nltk_pos_tagger = PerceptronTagger()
# Checks that the punkt tokenizer model was previously downloaded.
download('averaged_perceptron_tagger', quiet=True)
return _nltk_pos_tagger.tag_sents(list_of_tokenized_text)
示例3: pos_tag_sents
# 需要导入模块: from nltk.tag import perceptron [as 别名]
# 或者: from nltk.tag.perceptron import PerceptronTagger [as 别名]
def pos_tag_sents(sentences, tagset=None):
"""
Use NLTK's currently recommended part of speech tagger to tag the
given list of sentences, each consisting of a list of tokens.
:param tokens: List of sentences to be tagged
:type tokens: list(list(str))
:param tagset: the tagset to be used, e.g. universal, wsj, brown
:type tagset: str
:return: The list of tagged sentences
:rtype: list(list(tuple(str, str)))
"""
tagger = PerceptronTagger()
return [_pos_tag(sent, tagset, tagger) for sent in sentences]
示例4: _get_tagger
# 需要导入模块: from nltk.tag import perceptron [as 别名]
# 或者: from nltk.tag.perceptron import PerceptronTagger [as 别名]
def _get_tagger(lang=None):
if lang == 'rus':
tagger = PerceptronTagger(False)
ap_russian_model_loc = 'file:' + str(find(RUS_PICKLE))
tagger.load(ap_russian_model_loc)
elif lang == 'eng':
tagger = PerceptronTagger()
else:
tagger = PerceptronTagger()
return tagger