예제 #1
0
def get_sentiment_polarity_score(text):
    analyzer = oseti.Analyzer()
    score = analyzer.analyze(text)
    if (len(score) > 0):
        return sum(score) / len(score)
    else:
        return 0
def pn_oseti(text):
    analyzer = oseti.Analyzer()
    tmp = analyzer.analyze(text)
    pn_sum = sum(tmp)
    pn_average = sum(tmp) / len(tmp)

    return pn_sum, pn_average
예제 #3
0
 def test_analyze(self):
     a = oseti.Analyzer()
     text = '遅刻したけど楽しかったし嬉しかった。すごく充実した!'
     actual = a.analyze(text)
     assert_equal(actual, [0.3333333333333333, 1.0])
     text = 'そこにはいつもと変わらない日常があった。'
     actual = a.analyze(text)
     assert_equal(actual, [0.0])
예제 #4
0
 def test_lookup_wago(self):
     a = oseti.Analyzer()
     actual = a._lookup_wago('うんざり', [])
     assert_equal(actual, 'うんざり')
     actual = a._lookup_wago('軽い', ['尻', 'が'])
     assert_equal(actual, '尻 が 軽い')
     actual = a._lookup_wago('どうでもいい', [])
     assert_equal(actual, '')
예제 #5
0
파일: test_oseti.py 프로젝트: yskn67/oseti
 def test_calc_sentiment_polarity(self):
     a = oseti.Analyzer()
     actual = a._calc_sentiment_polarity('最高な仕事')
     assert_equal(actual, 1)
     actual = a._calc_sentiment_polarity('貪欲じゃないじゃない。')
     assert_equal(actual, -1)
     actual = a._calc_sentiment_polarity('どうでもいい')
     assert_equal(actual, 0)
예제 #6
0
 def test_count_polarity(self):
     a = oseti.Analyzer()
     text = '遅刻したけど楽しかったし嬉しかった。すごく充実した!'
     actual = a.count_polarity(text)
     assert_equal(actual, [{'positive': 2, 'negative': 1}, {'positive': 1, 'negative': 0}])
     text = 'そこにはいつもと変わらない日常があった。'
     actual = a.count_polarity(text)
     assert_equal(actual, [{'positive': 0, 'negative': 0}])
예제 #7
0
def calculate_score():
    sentence = request.args.get('q')
    print('Sentence', sentence)
    analyzer = oseti.Analyzer()
    score_list = analyzer.analyze(sentence)
    score = sum(score_list) / len(score_list)
    print('Score:', score)

    return (jsonify(score=score))
예제 #8
0
 def test_analyze_detail(self):
     a = oseti.Analyzer()
     text = '遅刻したけど楽しかったし嬉しかった。すごく充実した!'
     actual = a.analyze_detail(text)
     assert_equal(actual, [{'positive': ['楽しい', '嬉しい'], 'negative': ['遅刻'], 'score': 0.3333333333333333},
                           {'positive': ['充実'], 'negative': [], 'score': 1.0}])
     actual = a.analyze_detail('お金も希望もない!')
     assert_equal(actual, [{'positive': [], 'negative': ['お金-NEGATION', '希望-NEGATION'], 'score': -1.0}])
     actual = a.analyze_detail('お金がないわけではない')
     assert_equal(actual, [{'positive': ['お金'], 'negative': [], 'score': 1.0}])
예제 #9
0
    def posi_nega_jud(self):
        analyzer = oseti.Analyzer()  # type: Analyzer
        posinega_text_list = analyzer.count_polarity(self.text)  # type: list

        for i in range(len(posinega_text_list)):
            if posinega_text_list[i]['positive'] > 0:
                self.posinega_score += posinega_text_list[i]['positive']
            if posinega_text_list[i]['negative'] > 0:
                self.posinega_score -= posinega_text_list[i]['negative']

        self.tangoNum = len(posinega_text_list)

        return self.posinega_score, self.tangoNum
예제 #10
0
def score(texts):
    # see: https://github.com/ikegami-yukino/oseti
    analyzer = oseti.Analyzer()
    count = 0
    total_score = 0
    for text in texts:
        try:
            txt_scores = analyzer.analyze(text.get('text'))
            if len(txt_scores) == 0:
                continue
            total_score += np.average(txt_scores)
        except IndexError:
            print("error起きたけどながしとくわ!")
    return total_score
예제 #11
0
 def test_calc_sentiment_polarity(self):
     a = oseti.Analyzer()
     actual = a._calc_sentiment_polarity('最高な仕事')
     assert_equal(actual, [['最高', 1]])
     actual = a._calc_sentiment_polarity('貪欲じゃないじゃない。')
     assert_equal(actual, [['貪欲', -1]])
     actual = a._calc_sentiment_polarity('どうでもいい')
     assert_equal(actual, [])
     actual = a._calc_sentiment_polarity('お金も希望もある')
     assert_equal(actual, [['お金', 1], ['希望', 1]])
     actual = a._calc_sentiment_polarity('お金とか希望なりない')
     assert_equal(actual, [['お金-NEGATION', -1], ['希望-NEGATION', -1]])
     actual = a._calc_sentiment_polarity('お金だの希望だの喜びだのない')
     assert_equal(actual, [['お金-NEGATION', -1], ['希望-NEGATION', -1], ['喜び-NEGATION', -1]])
     actual = a._calc_sentiment_polarity('お金と希望や喜びがない')
     assert_equal(actual, [['お金-NEGATION', -1], ['希望-NEGATION', -1], ['喜び-NEGATION', -1]])
     actual = a._calc_sentiment_polarity('お金があるじゃない')
     assert_equal(actual, [['お金', 1]])
예제 #12
0
 def __init__(self, reload=True, RT_count=3000, print_rep=False):
     self.oseti_analyzer = oseti.Analyzer()  #極性判定
     self.CK = config.CONSUMER_KEY
     self.CS = config.CONSUMER_SECRET
     self.AT = config.ACCESS_TOKEN
     self.AS = config.ACCESS_TOKEN_SECRET
     self.ew = "配信スタート #キャンペーン リツイートキャンペーン WWWWWWWWW wwwwwwwwww"
     self.print_cnt = 0
     self.print_rep = print_rep
     self.rt = str(RT_count)
     self.columns = [
         "Id", "Date", "Name", "Full_text", "Judge", "Posi_score",
         "Nega_score", "Followers", "link"
     ]
     self.posi_pd = pd.DataFrame([], columns=self.columns)
     self.nega_pd = pd.DataFrame([], columns=self.columns)
     self.fire_pd = pd.DataFrame([], columns=self.columns)
     self.wait = 0
     self.reload = reload
     day = str(input("ツイートを取得する日付を入力(過去1週間以内/入力形式:YYYY-M-D):"))
     day = datetime.strptime(day, '%Y-%m-%d')
     self.day = day.strftime('%Y-%m-%d')
     #最大2200件のツイートを取得するためのページ
     self.pages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
예제 #13
0
import seaborn as sns
sns.set(style="whitegrid")
import pandas as pd
import re
import MeCab
from . import make_csv as mc
import codecs
from numpy import mean
import oseti
from . import word_search as ws
from . import jum_analize as jua
import sqlite3
# MeCabインスタンス作成
m = MeCab.Tagger('')
# osetiインスタンス作成
analyzer = oseti.Analyzer()


@login_required
def top_page(request):
    user = UserSocialAuth.objects.get(user_id=request.user.id)
    #全ツイート取得
    mc.mk_twcsv(request)
    #csv読み込み
    with codecs.open('all_tweets.csv', 'r', 'utf-8', 'ignore') as file:
        tw_df = pd.read_csv(file)
    #改行を除く
    text_list = list(tw_df['tweet_text'])
    for i in range(len(text_list)):
        text_list[i] = text_list[i].replace('\n', ' ')
예제 #14
0
파일: test_oseti.py 프로젝트: yskn67/oseti
 def test_split_per_sentence(self):
     a = oseti.Analyzer()
     actual = a._split_per_sentence('今日は雨。明日は雪?')
     assert_equal(len(list(actual)), 2)
예제 #15
0
def oseti_motivation_score(text):
    analyzer = oseti.Analyzer()
    score_list = analyzer.analyze(text)
    return round(score_list[0], 4)
예제 #16
0
def tes_oseti():
    analyzer = oseti.Analyzer()
    score = analyzer.analyze_detail('このイヤホンは重低音が良いです')
    print(score)
예제 #17
0
    def __init__(self):

        self.analyzer = oseti.Analyzer()
        self.evaluate = []
        self.sum_posi = 0.0
        self.sum_nega = 0.0
예제 #18
0
def analyze(jeer):
    analyzer = oseti.Analyzer()
    scores = analyzer.analyze(jeer)
    logging.info(scores)
    mean_score = mean(scores)
    return mean_score
예제 #19
0
 def test_has_arujanai(self):
     a = oseti.Analyzer()
     actual = a._has_arujanai('やる気あるじゃない')
     assert_equal(actual, True)
     actual = a._has_arujanai('やる気ないじゃない')
     assert_equal(actual, False)