本文整理汇总了Python中afinn.Afinn类的典型用法代码示例。如果您正苦于以下问题:Python Afinn类的具体用法?Python Afinn怎么用?Python Afinn使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Afinn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_score
def test_score():
afinn = Afinn()
score = afinn.score('bad')
assert score < 0
score = afinn.score('')
assert score == 0.0
示例2: test_split
def test_split():
afinn = Afinn()
words = afinn.split('Hello, World')
assert words == ['Hello', 'World']
words = afinn.split(u('Hell\xf8, \xc5rld'))
assert words == [u('Hell\xf8'), u('\xc5rld')]
示例3: test_score_with_wordlist
def test_score_with_wordlist():
afinn = Afinn()
score = afinn.score('Rather good.')
assert score > 0
score = afinn.score('Rather GOOD.')
assert score > 0
示例4: test_words_and_emoticons
def test_words_and_emoticons():
afinn = Afinn(emoticons=True)
score = afinn.score(':-)')
assert score > 0
score = afinn.score('BAD BAD BAD :-)')
assert score < 0
示例5: test_score_language
def test_score_language():
afinn = Afinn(language='en')
score = afinn.score('bad')
assert score < 0
afinn = Afinn('en')
score = afinn.score('bad')
assert score < 0
示例6: sentiment
def sentiment(body):
"""
calculate sentiment using Afinn model
:type body: unicode str
:rtype: int
"""
afinn = Afinn()
return afinn.score(body)
示例7: afinnSentiScore
def afinnSentiScore(self, doc, emoticons = True):
"""
The output is a float variable that if larger than zero indicates a
positive sentiment and less than zero indicates negative sentiment.
"""
afinn = Afinn(emoticons=emoticons)
result = afinn.score(doc)
return result
示例8: test_danish
def test_danish():
afinn = Afinn(language='da')
score = afinn.score('bedrageri')
assert score < 0
score = afinn.score(u('besv\xe6r'))
assert score < 0
score = afinn.score(u('D\xc5RLIG!!!'))
assert score < 0
示例9: extract
def extract(self):
"""
Extracts location and sentiment from an article.
"""
afinn = Afinn()
target = self.title + " " + self.summary
target = target.encode("ascii", "ignore")
self.sentiment = afinn.score(target)
self.countries = extract_countries(target)
示例10: afinn_sentiment
def afinn_sentiment(filename):
from afinn import Afinn
afinn = Afinn()
with open (my_file, "r") as myfile:
text = myfile.read().replace('\n', ' ')
sentences = tokenize.sent_tokenize(text)
sentiments = []
for sentence in sentences:
sentsent = afinn.score(sentence)
sentiments.append(sentsent)
return sentiments
示例11: test_data
def test_data():
"""Test data files for format."""
afinn = Afinn()
filenames = listdir(afinn.data_dir())
for filename in filenames:
if not filename.endswith('.txt'):
continue
full_filename = join(afinn.data_dir(), filename)
with io.open(full_filename, encoding='UTF-8') as fid:
for line in fid:
# There should be the phrase and the score
# and nothing more
assert len(line.split('\t')) == 2
# The score should be interpretable as an int
phrase, score = line.split('\t')
assert type(int(score)) == int
示例12: SentimentBolt
class SentimentBolt(storm.BasicBolt):
def __init__(self):
self.afinn = Afinn(language='da', emoticons=True)
def process(self, tup):
#storm.logInfo(tup.values[0])
score = self.afinn.score(tup.values[0])
#storm.logInfo(str(score))
storm.emit([str(score)])
示例13: test_emoticon
def test_emoticon():
afinn = Afinn()
afinn.setup_from_file(join(afinn.data_dir(), 'AFINN-emoticon-8.txt'),
with_word_boundary=False)
score = afinn.score(':-)')
assert score > 0
score = afinn.score('This is a :-) smiley')
assert score > 0
score = afinn.score('Just so XOXO.')
assert score > 0
示例14: test_emoticon_upper_case
def test_emoticon_upper_case():
afinn = Afinn()
afinn.setup_from_file(join(afinn.data_dir(), 'AFINN-emoticon-8.txt'),
word_boundary=False)
score = afinn.score(':d')
assert score == 0
# TODO
score = afinn.score(':D')
# assert score > 0
score = afinn.score('It is so: :D')
示例15: test_score_with_pattern
def test_score_with_pattern():
afinn = Afinn(language='da')
score = afinn.score('ikke god')
assert score < 0
score = afinn.score('ikke god.')
assert score < 0
score = afinn.score('IKKE GOD-')
assert score < 0
score = afinn.score('ikke god')
assert score < 0
score = afinn.score('En tv-succes sidste gang.')
assert score > 0
score = afinn.score('')
assert score == 0.0