Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nltk
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
nltk
Commits
f94f4af4
Commit
f94f4af4
authored
Apr 26, 2015
by
Ewan Klein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extracted text preprocessing into separate method
parent
e3fd5f05
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
14 deletions
+20
-14
nltk/sentiment/vader.py
+20
-14
No files found.
nltk/sentiment/vader.py
View file @
f94f4af4
...
...
@@ -320,15 +320,11 @@ class SentimentIntensityDetector(object):
lex_dict
[
w
]
=
float
(
m
)
return
lex_dict
def
preprocess
(
self
,
text
):
text_dict
=
{}
def
sentiment
(
self
,
text
):
def
preprocess
(
self
,
text
):
"""
Returns a float for sentiment strength based on the input text.
Positive values are positive valence, negative value are negative
valence.
Identify sentiment-relevant string-level properties of input text.
"""
if
not
isinstance
(
text
,
str
):
text
=
str
(
text
)
...
...
@@ -380,6 +376,15 @@ class SentimentIntensityDetector(object):
# check for negation
is_cap_diff
=
allcap_differential
(
words_and_emoticons
)
return
text
,
words_and_emoticons
,
is_cap_diff
def
sentiment
(
self
,
text
):
"""
Returns a float for sentiment strength based on the input text.
Positive values are positive valence, negative value are negative
valence.
"""
text
,
words_and_emoticons
,
is_cap_diff
=
self
.
preprocess
(
text
)
sentiments
=
[]
for
item
in
words_and_emoticons
:
...
...
@@ -494,7 +499,7 @@ class SentimentIntensityDetector(object):
if
'but'
in
words_and_emoticons
or
'BUT'
in
words_and_emoticons
:
try
:
bi
=
words_and_emoticons
.
index
(
'but'
)
except
Index
Error
:
except
Value
Error
:
bi
=
words_and_emoticons
.
index
(
'BUT'
)
for
sentiment
in
sentiments
:
si
=
sentiments
.
index
(
sentiment
)
...
...
@@ -570,6 +575,8 @@ class SentimentIntensityDetector(object):
return
sentiment_dict
def
demo
():
text1
=
"At least (I think...) it isn't a HORRIBLE :-) book!"
text2
=
"Today kinda sux! But I'll get by, lol"
...
...
@@ -604,14 +611,13 @@ def demo():
"""
DEMO
=
0
if
__name__
==
'__main__'
:
#import doctest
#doctest.testmod(optionflags=doctest.NORMALIZE_WHITESPACE)
demo
()
if
DEMO
:
demo
()
else
:
import
doctest
doctest
.
testmod
(
optionflags
=
doctest
.
NORMALIZE_WHITESPACE
)
Write
Preview
Markdown
is supported
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