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