Commit 8b2cf98b authored by militarpancho's avatar militarpancho
Browse files

Version 1.1

parent ec8d55c0
import nltk
from nltk.sentiment.util import *
from nltk.tokenize.casual import casual_tokenize
from senpy.plugins import SentimentPlugin
from senpy.models import Sentiment
class SmileyPlugin(SentimentPlugin):
def activate(self):
nltk.download('punkt')
def analyse_entry(self, entry, params):
lang = params.get("language", "auto")
text = entry.get("text", None)
tokens = casual_tokenize(text)
polarity = "marl:Neutral"
polarity_value = 0
if ':)' in text:
polarity = "marl:Positive"
polarity_value = self.maxPolarityValue
elif ':(' in text:
polarity = "marl:Negative"
polarity_value = self.minPolarityValue
polarity_value = 0
for token in tokens:
if token in HAPPY:
polarity = "marl:Positive"
polarity_value = self.maxPolarityValue
elif token in SAD:
polarity = "marl:Negative"
polarity_value = self.minPolarityValue
sentiment = Sentiment({
"marl:hasPolarity": polarity,
"marl:polarityValue": polarity_value
})
"marl:hasPolarity": polarity,
"marl:polarityValue": polarity_value
})
entry.sentiments.append(sentiment)
yield entry
\ No newline at end of file
......@@ -3,10 +3,18 @@ name: sentiment-smiley
module: sentiment-smiley
description: Sentiment detector that depends on emojis to inquire the sentiment of some input.
author: "@militarpancho"
version: '0.1'
version: '1.1'
url: "https://github.com/gsi-upm/esto-es-una-url-falsa"
requirements: {}
requirements: {nltk}
maxPolarityValue: "1"
minPolarityValue: "-1"
extra_params:
language:
aliases:
- language
- l
required: false
options:
- es
- en
- auto
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment