Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
senpy
senpy-tutorial
Commits
7b310e3f
Commit
7b310e3f
authored
Mar 14, 2017
by
militarpancho
Browse files
Version 2.1
parent
8b2cf98b
Changes
2
Hide whitespace changes
Inline
Side-by-side
sentiment-smiley.py
View file @
7b310e3f
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
({
...
...
sentiment-smiley.senpy
View file @
7b310e3f
...
...
@@ -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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment