mirror of
https://github.com/gsi-upm/senpy
synced 2025-10-19 09:48:26 +00:00
* Added conversion plugins (API might change!) * Added conversion to the analysis pipeline * Changed behaviour of --default-plugins (it adds conversion plugins regardless) * Added emotionModel [sic] and emotionConversion models //TODO add conversion tests //TODO add conversion to docs
25 lines
739 B
Python
25 lines
739 B
Python
import random
|
|
|
|
from senpy.plugins import SentimentPlugin
|
|
from senpy.models import Sentiment
|
|
|
|
|
|
class RandPlugin(SentimentPlugin):
|
|
def analyse_entry(self, entry, params):
|
|
lang = params.get("language", "auto")
|
|
|
|
polarity_value = max(-1, min(1, random.gauss(0.2, 0.2)))
|
|
polarity = "marl:Neutral"
|
|
if polarity_value > 0:
|
|
polarity = "marl:Positive"
|
|
elif polarity_value < 0:
|
|
polarity = "marl:Negative"
|
|
sentiment = Sentiment({
|
|
"marl:hasPolarity": polarity,
|
|
"marl:polarityValue": polarity_value
|
|
})
|
|
sentiment["prov:wasGeneratedBy"] = self.id
|
|
entry.sentiments.append(sentiment)
|
|
entry.language = lang
|
|
yield entry
|