當前位置: 首頁>>代碼示例>>Python>>正文


Python perceptron.PerceptronTagger方法代碼示例

本文整理匯總了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) 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:27,代碼來源:__init__.py

示例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) 
開發者ID:alvations,項目名稱:earthy,代碼行數:14,代碼來源:__init__.py

示例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] 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:16,代碼來源:__init__.py

示例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 
開發者ID:sdoran35,項目名稱:hate-to-hugs,代碼行數:12,代碼來源:__init__.py


注:本文中的nltk.tag.perceptron.PerceptronTagger方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。