当前位置: 首页>>代码示例>>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;未经允许,请勿转载。