2018-01-03 08:39:30 +00:00
|
|
|
#!/usr/local/bin/python
|
2019-01-07 11:08:19 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-01-03 08:39:30 +00:00
|
|
|
|
|
|
|
from senpy import easy_test, models, plugins
|
|
|
|
|
|
|
|
import basic
|
|
|
|
|
|
|
|
|
|
|
|
class ParameterizedDictionary(plugins.SentimentPlugin):
|
2018-01-06 17:51:16 +00:00
|
|
|
'''This is a basic self-contained plugin'''
|
2018-01-03 08:39:30 +00:00
|
|
|
|
|
|
|
author = '@balkian'
|
|
|
|
version = '0.2'
|
|
|
|
|
|
|
|
extra_params = {
|
|
|
|
'positive-words': {
|
|
|
|
'description': 'Comma-separated list of words that are considered positive',
|
|
|
|
'aliases': ['positive'],
|
|
|
|
'required': True
|
|
|
|
},
|
|
|
|
'negative-words': {
|
|
|
|
'description': 'Comma-separated list of words that are considered negative',
|
|
|
|
'aliases': ['negative'],
|
|
|
|
'required': False
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-07 11:08:19 +00:00
|
|
|
def analyse_entry(self, entry, activity):
|
|
|
|
params = activity.params
|
2018-01-03 08:39:30 +00:00
|
|
|
positive_words = params['positive-words'].split(',')
|
|
|
|
negative_words = params['negative-words'].split(',')
|
|
|
|
dictionary = {
|
|
|
|
'marl:Positive': positive_words,
|
|
|
|
'marl:Negative': negative_words,
|
|
|
|
}
|
|
|
|
polarity = basic.get_polarity(entry.text, [dictionary])
|
|
|
|
|
|
|
|
s = models.Sentiment(marl__hasPolarity=polarity)
|
2019-01-07 11:08:19 +00:00
|
|
|
s.prov(activity)
|
2018-01-03 08:39:30 +00:00
|
|
|
entry.sentiments.append(s)
|
|
|
|
yield entry
|
|
|
|
|
|
|
|
test_cases = [
|
|
|
|
{
|
|
|
|
'input': 'Hello :)',
|
|
|
|
'polarity': 'marl:Positive',
|
|
|
|
'parameters': {
|
|
|
|
'positive': "Hello,:)",
|
|
|
|
'negative': "sad,:()"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'input': 'Hello :)',
|
|
|
|
'polarity': 'marl:Negative',
|
|
|
|
'parameters': {
|
|
|
|
'positive': "",
|
|
|
|
'negative': "Hello"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
easy_test()
|