basic.py 634 Bytes
Newer Older
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
1
2
3
4
#!/usr/local/bin/python
# coding: utf-8

emoticons = {
5
6
    'pos': [':)', ':]', '=)', ':D'],
    'neg': [':(', ':[', '=(']
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
7
8
9
}

emojis = {
10
11
    'pos': ['😁', '😂', '😃', '😄', '😆', '😅', '😄' '😍'],
    'neg': ['😢', '😡', '😠', '😞', '😖', '😔', '😓', '😒']
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
12
13
14
15
16
17
18
19
20
21
22
23
}


def get_polarity(text, dictionaries=[emoticons, emojis]):
    polarity = 'marl:Neutral'
    for dictionary in dictionaries:
        for label, values in dictionary.items():
            for emoticon in values:
                if emoticon and emoticon in text:
                    polarity = label
                    break
    return polarity