rand.py 739 Bytes
Newer Older
1
2
3
import random

from senpy.plugins import SentimentPlugin
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
4
from senpy.models import Sentiment
5
6


J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
7
8
class RandPlugin(SentimentPlugin):
    def analyse_entry(self, entry, params):
9
10
        lang = params.get("language", "auto")

11
        polarity_value = max(-1, min(1, random.gauss(0.2, 0.2)))
12
13
14
15
16
        polarity = "marl:Neutral"
        if polarity_value > 0:
            polarity = "marl:Positive"
        elif polarity_value < 0:
            polarity = "marl:Negative"
J. Fernando Sánchez's avatar
YAPFed    
J. Fernando Sánchez committed
17
18
19
20
        sentiment = Sentiment({
            "marl:hasPolarity": polarity,
            "marl:polarityValue": polarity_value
        })
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
21
22
        sentiment["prov:wasGeneratedBy"] = self.id
        entry.sentiments.append(sentiment)
23
        entry.language = lang
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
24
        yield entry