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


Python util.untag方法代碼示例

本文整理匯總了Python中nltk.tag.util.untag方法的典型用法代碼示例。如果您正苦於以下問題:Python util.untag方法的具體用法?Python util.untag怎麽用?Python util.untag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在nltk.tag.util的用法示例。


在下文中一共展示了util.untag方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: person_connotation

# 需要導入模塊: from nltk.tag import util [as 別名]
# 或者: from nltk.tag.util import untag [as 別名]
def person_connotation(tweet, name):
    """
    Decide whether a person is talked favorably about or not, based on the
    tone of the sentences in which their name appears
    """
    twtcontent = sent_tokenize(tweet)
    overall = {'compound': 0, 'neg': 0, 'neu': 0, 'pos': 0}
    mentions = 0
    # analyze each sentence talking about `name` person
    for s in twtcontent:
        tags = get_tweet_tags(s)
        # if the name appears in the tagged sentence, get its tone
        if (name, 'NNP') in tags:
            sentence = util.untag(tags)
            scores = tweet_connotation(' '.join(sentence))
            # add it up to the overall tweet's tone
            for i, z in enumerate(scores):
                overall[z] += scores[z]
            mentions += 1
    # averaging all sentences' scores. don't wanna divide by zero now do we
    if mentions != 0:
        for v in overall:
            overall[v] = round(overall[v] / mentions, 3)
    return overall 
開發者ID:SocialNPHS,項目名稱:SocialNPHS,代碼行數:26,代碼來源:tweet.py

示例2: evaluate

# 需要導入模塊: from nltk.tag import util [as 別名]
# 或者: from nltk.tag.util import untag [as 別名]
def evaluate(self, gold):
        """
        Score the accuracy of the tagger against the gold standard.
        Strip the tags from the gold standard text, retag it using
        the tagger, then compute the accuracy score.

        :type gold: list(list(tuple(str, str)))
        :param gold: The list of tagged sentences to score the tagger on.
        :rtype: float
        """

        tagged_sents = self.tag_sents(untag(sent) for sent in gold)
        gold_tokens = sum(gold, [])
        test_tokens = sum(tagged_sents, [])
        return accuracy(gold_tokens, test_tokens) 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:17,代碼來源:api.py

示例3: evaluate

# 需要導入模塊: from nltk.tag import util [as 別名]
# 或者: from nltk.tag.util import untag [as 別名]
def evaluate(self, gold):
        """
        Score the accuracy of the tagger against the gold standard.
        Strip the tags from the gold standard text, retag it using
        the tagger, then compute the accuracy score.

        :type gold: list(list(tuple(str, str)))
        :param gold: The list of tagged sentences to score the tagger on.
        :rtype: float
        """

        tagged_sents = self.tag_sents(untag(sent) for sent in gold)
        gold_tokens = list(chain(*gold))
        test_tokens = list(chain(*tagged_sents))
        return accuracy(gold_tokens, test_tokens) 
開發者ID:sdoran35,項目名稱:hate-to-hugs,代碼行數:17,代碼來源:api.py


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