当前位置: 首页>>代码示例>>Python>>正文


Python Afinn.score方法代码示例

本文整理汇总了Python中afinn.Afinn.score方法的典型用法代码示例。如果您正苦于以下问题:Python Afinn.score方法的具体用法?Python Afinn.score怎么用?Python Afinn.score使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在afinn.Afinn的用法示例。


在下文中一共展示了Afinn.score方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_score

# 需要导入模块: from afinn import Afinn [as 别名]
# 或者: from afinn.Afinn import score [as 别名]
def test_score():
    afinn = Afinn()
    score = afinn.score('bad')
    assert score < 0

    score = afinn.score('')
    assert score == 0.0
开发者ID:johanneswachs,项目名称:afinn,代码行数:9,代码来源:test_afinn.py

示例2: test_score_with_wordlist

# 需要导入模块: from afinn import Afinn [as 别名]
# 或者: from afinn.Afinn import score [as 别名]
def test_score_with_wordlist():
    afinn = Afinn()
    score = afinn.score('Rather good.')
    assert score > 0

    score = afinn.score('Rather GOOD.')
    assert score > 0
开发者ID:johanneswachs,项目名称:afinn,代码行数:9,代码来源:test_afinn.py

示例3: test_score_language

# 需要导入模块: from afinn import Afinn [as 别名]
# 或者: from afinn.Afinn import score [as 别名]
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
开发者ID:johanneswachs,项目名称:afinn,代码行数:10,代码来源:test_afinn.py

示例4: test_words_and_emoticons

# 需要导入模块: from afinn import Afinn [as 别名]
# 或者: from afinn.Afinn import score [as 别名]
def test_words_and_emoticons():
    afinn = Afinn(emoticons=True)

    score = afinn.score(':-)')
    assert score > 0

    score = afinn.score('BAD BAD BAD :-)')
    assert score < 0
开发者ID:DominicBurkart,项目名称:afinn,代码行数:10,代码来源:test_afinn.py

示例5: test_danish

# 需要导入模块: from afinn import Afinn [as 别名]
# 或者: from afinn.Afinn import score [as 别名]
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
开发者ID:johanneswachs,项目名称:afinn,代码行数:12,代码来源:test_afinn.py

示例6: test_emoticon

# 需要导入模块: from afinn import Afinn [as 别名]
# 或者: from afinn.Afinn import score [as 别名]
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
开发者ID:johanneswachs,项目名称:afinn,代码行数:14,代码来源:test_afinn.py

示例7: test_emoticon_upper_case

# 需要导入模块: from afinn import Afinn [as 别名]
# 或者: from afinn.Afinn import score [as 别名]
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')
开发者ID:DominicBurkart,项目名称:afinn,代码行数:15,代码来源:test_afinn.py

示例8: sentiment

# 需要导入模块: from afinn import Afinn [as 别名]
# 或者: from afinn.Afinn import score [as 别名]
def sentiment(body):
    """
    calculate sentiment using Afinn model
    :type body:  unicode str
    :rtype: int
    """
    afinn = Afinn()
    return afinn.score(body)
开发者ID:jonneff,项目名称:textfitXL,代码行数:10,代码来源:helpers.py

示例9: afinnSentiScore

# 需要导入模块: from afinn import Afinn [as 别名]
# 或者: from afinn.Afinn import score [as 别名]
 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
开发者ID:latchireddyambati,项目名称:api,代码行数:11,代码来源:Sentiment.py

示例10: SentimentBolt

# 需要导入模块: from afinn import Afinn [as 别名]
# 或者: from afinn.Afinn import score [as 别名]
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)])
开发者ID:utrejch,项目名称:HotTopics,代码行数:12,代码来源:SentimentBolt.py

示例11: extract

# 需要导入模块: from afinn import Afinn [as 别名]
# 或者: from afinn.Afinn import score [as 别名]
    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)
开发者ID:rkuykendall,项目名称:map-world-news,代码行数:13,代码来源:article.py

示例12: afinn_sentiment

# 需要导入模块: from afinn import Afinn [as 别名]
# 或者: from afinn.Afinn import score [as 别名]
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
开发者ID:johnlaudun,项目名称:tedtalks,代码行数:13,代码来源:sentiments.py

示例13: test_score_with_pattern

# 需要导入模块: from afinn import Afinn [as 别名]
# 或者: from afinn.Afinn import score [as 别名]
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
开发者ID:johanneswachs,项目名称:afinn,代码行数:21,代码来源:test_afinn.py

示例14: Afinn

# 需要导入模块: from afinn import Afinn [as 别名]
# 或者: from afinn.Afinn import score [as 别名]
from afinn import Afinn
from builtins import str
afinn = Afinn()
score = afinn.score('this site is not very good')
print(score)
开发者ID:garrypas,项目名称:afinn,代码行数:7,代码来源:program.py

示例15: Afinn

# 需要导入模块: from afinn import Afinn [as 别名]
# 或者: from afinn.Afinn import score [as 别名]
# In[3]:

from afinn import Afinn

afn = Afinn(emoticons=True) 


# ## Predict sentiment for sample reviews

# In[4]:

for review, sentiment in zip(test_reviews[sample_review_ids], test_sentiments[sample_review_ids]):
    print('REVIEW:', review)
    print('Actual Sentiment:', sentiment)
    print('Predicted Sentiment polarity:', afn.score(review))
    print('-'*60)


# ## Predict sentiment for test dataset

# In[5]:

sentiment_polarity = [afn.score(review) for review in test_reviews]
predicted_sentiments = ['positive' if score >= 1.0 else 'negative' for score in sentiment_polarity]


# ## Evaluate model performance

# In[6]:
开发者ID:Zoery,项目名称:practical-machine-learning-with-python,代码行数:31,代码来源:unsupervised_sentiment_analysis.py


注:本文中的afinn.Afinn.score方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。