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


Python afinn.Afinn类代码示例

本文整理汇总了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
开发者ID:johanneswachs,项目名称:afinn,代码行数:7,代码来源:test_afinn.py

示例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')]
开发者ID:johanneswachs,项目名称:afinn,代码行数:7,代码来源:test_afinn.py

示例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
开发者ID:johanneswachs,项目名称:afinn,代码行数:7,代码来源:test_afinn.py

示例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
开发者ID:DominicBurkart,项目名称:afinn,代码行数:8,代码来源:test_afinn.py

示例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
开发者ID:johanneswachs,项目名称:afinn,代码行数:8,代码来源:test_afinn.py

示例6: sentiment

def sentiment(body):
    """
    calculate sentiment using Afinn model
    :type body:  unicode str
    :rtype: int
    """
    afinn = Afinn()
    return afinn.score(body)
开发者ID:jonneff,项目名称:textfitXL,代码行数:8,代码来源:helpers.py

示例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
开发者ID:latchireddyambati,项目名称:api,代码行数:9,代码来源:Sentiment.py

示例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
开发者ID:johanneswachs,项目名称:afinn,代码行数:10,代码来源:test_afinn.py

示例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)
开发者ID:rkuykendall,项目名称:map-world-news,代码行数:11,代码来源:article.py

示例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
开发者ID:johnlaudun,项目名称:tedtalks,代码行数:11,代码来源:sentiments.py

示例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
开发者ID:johanneswachs,项目名称:afinn,代码行数:17,代码来源:test_afinn.py

示例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)])
开发者ID:utrejch,项目名称:HotTopics,代码行数:10,代码来源:SentimentBolt.py

示例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
开发者ID:johanneswachs,项目名称:afinn,代码行数:12,代码来源:test_afinn.py

示例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')
开发者ID:DominicBurkart,项目名称:afinn,代码行数:13,代码来源:test_afinn.py

示例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
开发者ID:johanneswachs,项目名称:afinn,代码行数:19,代码来源:test_afinn.py


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