本文整理匯總了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