-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
test_mlask.py
59 lines (48 loc) · 3 KB
/
test_mlask.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from nose.tools import assert_equals, assert_true, assert_false, assert_raises
from mlask import MLAsk
mla = MLAsk()
def test__read_emodic():
assert_true('!' in mla.emodic['emotem']['exclamation'])
assert_true('嫌い' in mla.emodic['emotion']['iya'])
def test_analyze():
result = mla.analyze('彼は嫌いではない!(;´Д`)')
assert_equals(result['text'], '彼は嫌いではない!(;´Д`)')
result = mla.analyze('')
assert_equals(result, {'text': '', 'emotion': None})
def test__normalize():
assert_equals(mla._normalize('!'), '!')
assert_equals(mla._normalize('?'), '?')
def test__lexical_analysis():
assert_equals(mla._lexical_analysis('すごい'),
{'all': 'すごい', 'interjections': [], 'no_emotem': 'すごい', 'lemma_words': ['すごい']})
def test__find_emoticon():
assert_equals(mla._find_emoticon('(;´Д`)'), ['(;´Д`)'])
assert_equals(mla._find_emoticon('顔文字なし'), [])
def test__find_emotem():
assert_equals(mla._find_emotem({'no_emotem': '(;´Д`)', 'interjections': '!'}, []),
{'emotikony': ['´Д`', 'Д`', '´Д'], 'interjections': ['!']})
def test__find_emotion():
lemmas = {'all': '嫌い', 'lemma_words': ['嫌い']}
assert_equals(mla._find_emotion(lemmas), {'iya': ['嫌い']})
lemmas_with_interjections = {'all': 'え!嫌い', 'interjections': ['え'], 'lemma_words': ['え','!', '嫌い']}
assert_equals(mla._find_emotion(lemmas_with_interjections), {'iya': ['嫌い']})
empty_lemmas = {'all': [], 'interjections': [], 'no_emotem': [], 'lemma_words': []}
assert_equals(mla._find_emotion(empty_lemmas), None)
lemmas = {'all': '気持ちがよい', 'lemma_words': ['気持ち', 'が', 'よい']}
assert_equals(mla._find_emotion(lemmas), {'yorokobi': ['気持ちがよい']})
def test__estimate_sentiment_orientation():
assert_equals(mla._estimate_sentiment_orientation({'iya': ['嫌い', '嫌']}), 'NEGATIVE')
assert_equals(mla._estimate_sentiment_orientation({'yorokobi': ['嫌い*CVS']}), 'POSITIVE')
assert_equals(mla._estimate_sentiment_orientation({'yorokobi': ['嫌い*CVS'], 'iya': ['嫌い']}), 'NEUTRAL')
assert_equals(mla._estimate_sentiment_orientation({'iya': ['嫌い', '嫌'], 'aware': ['悲しい'],
'yorokobi': ['嬉しい']}), 'mostly_NEGATIVE')
def test__estimate_activation():
assert_equals(mla._estimate_activation({'kowa': ['怖い']}), 'ACTIVE')
assert_equals(mla._estimate_activation({'aware': ['悲しい']}), 'PASSIVE')
assert_equals(mla._estimate_activation({'iya': ['嫌い', '嫌']}), 'NEUTRAL')
assert_equals(mla._estimate_activation({'kowa': ['怖い'], 'yasu': ['安らぐ'], 'aware': ['悲しい']}),
'mostly_PASSIVE')
def test__get_representative_emotion():
assert_equals(mla._get_representative_emotion({'iya': ['嫌い', '嫌']}), ('iya', ['嫌い', '嫌']))