Commit 59f66705 authored by militarpancho's avatar militarpancho
Browse files

Version 2.1

parent 8b2cf98b
{
"HAPPY": [
":-)", ":)", ";)", ":o)", ":]", ":3", ":c)", ":>", "=]", "8)", "=)", ":}",
":^)", ":-D", ":D", "8-D", "8D", "x-D", "xD", "X-D", "XD", "=-D", "=D",
"=-3", "=3", ":-))", ":'-)", ":*", ":^*", ">:P", ":-P", ":P", "X-P",
"x-p", "xp", "XP", ":-p", ":p", "=p", ":-b", ":b", ">:)", ">;)", ">:-)",
"<3"
],
"SAD": [
":L", ":-/", ">:/", ":S", ">:[", ":@", ":-(", ":[", ":-||", "=L", ":<",
":-[", ":-<", "=\\", "=/", ">:(", ":(", ">.<", ":'-(", ":'(", ":\\", ":-c",
":c", ":{", ">:\\", ";("
]
}
\ No newline at end of file
import nltk
from nltk.sentiment.util import *
from nltk.sentiment.util import HAPPY,SAD
from nltk.tokenize.casual import casual_tokenize
import json
from senpy.plugins import SentimentPlugin
from senpy.plugins import SentimentPlugin, ShelfMixin
from senpy.models import Sentiment
class SmileyPlugin(SentimentPlugin):
class SmileyPlugin(SentimentPlugin, ShelfMixin):
def activate(self):
nltk.download('punkt')
nltk.download('punkt', download_dir=self.download_path)
if 'emojis' not in self.sh:
with open(self.emojis_path, 'r') as f:
emojis = json.load(f)
self.sh['emojis'] = emojis
self._emojis = self.sh['emojis']
self.save()
def analyse_entry(self, entry, params):
lang = params.get("language", "auto")
......@@ -17,10 +24,10 @@ class SmileyPlugin(SentimentPlugin):
polarity = "marl:Neutral"
polarity_value = 0
for token in tokens:
if token in HAPPY:
if token in self._emojis['HAPPY']:
polarity = "marl:Positive"
polarity_value = self.maxPolarityValue
elif token in SAD:
elif token in self._emojis['SAD']:
polarity = "marl:Negative"
polarity_value = self.minPolarityValue
sentiment = Sentiment({
......
......@@ -18,3 +18,5 @@ extra_params:
- es
- en
- auto
emojis_path: "/data/emojis.json"
download_path: "/data/nltk_data"
\ No newline at end of file
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