本文整理汇总了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
示例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)
示例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)