mirror of https://github.com/gsi-upm/senpy
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
9 years ago
|
import random
|
||
6 years ago
|
from senpy import SentimentPlugin, Sentiment, Entry
|
||
9 years ago
|
|
||
|
|
||
5 years ago
|
class RandSent(SentimentPlugin):
|
||
6 years ago
|
'''A sample plugin that returns a random sentiment annotation'''
|
||
5 years ago
|
name = 'sentiment-random'
|
||
6 years ago
|
author = "@balkian"
|
||
|
version = '0.1'
|
||
|
url = "https://github.com/gsi-upm/senpy-plugins-community"
|
||
|
marl__maxPolarityValue = '1'
|
||
|
marl__minPolarityValue = "-1"
|
||
9 years ago
|
|
||
5 years ago
|
def analyse_entry(self, entry, activity):
|
||
9 years ago
|
polarity_value = max(-1, min(1, random.gauss(0.2, 0.2)))
|
||
9 years ago
|
polarity = "marl:Neutral"
|
||
|
if polarity_value > 0:
|
||
|
polarity = "marl:Positive"
|
||
|
elif polarity_value < 0:
|
||
|
polarity = "marl:Negative"
|
||
6 years ago
|
sentiment = Sentiment(marl__hasPolarity=polarity,
|
||
|
marl__polarityValue=polarity_value)
|
||
5 years ago
|
sentiment.prov(activity)
|
||
8 years ago
|
entry.sentiments.append(sentiment)
|
||
7 years ago
|
yield entry
|
||
7 years ago
|
|
||
|
def test(self):
|
||
6 years ago
|
'''Run several random analyses.'''
|
||
7 years ago
|
params = dict()
|
||
|
results = list()
|
||
6 years ago
|
for i in range(50):
|
||
5 years ago
|
activity = self.activity(params)
|
||
6 years ago
|
res = next(self.analyse_entry(Entry(nif__isString="Hello"),
|
||
5 years ago
|
activity))
|
||
7 years ago
|
res.validate()
|
||
|
results.append(res.sentiments[0]['marl:hasPolarity'])
|
||
|
assert 'marl:Positive' in results
|
||
|
assert 'marl:Negative' in results
|