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
fecd664b
Commit
fecd664b
authored
May 03, 2015
by
Ewan Klein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PEP 8 fixes. Updated lexicon reader to use utf-8.
parent
05dd7e19
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
11 deletions
+13
-11
nltk/sentiment/vader.py
+13
-11
No files found.
nltk/sentiment/vader.py
View file @
fecd664b
...
...
@@ -274,8 +274,8 @@ def allcap_differential(words):
"""
is_different
=
False
allcap_words
=
0
for
w
in
words
:
if
w
.
isupper
():
for
w
ord
in
words
:
if
w
ord
.
isupper
():
allcap_words
+=
1
cap_differential
=
len
(
words
)
-
allcap_words
if
cap_differential
>
0
and
cap_differential
<
len
(
words
):
...
...
@@ -331,8 +331,8 @@ class SentiText(object):
wes
=
[
we
for
we
in
wes
if
len
(
we
)
>
1
]
for
word
in
self
.
_words_only
():
for
p
in
PUNC_LIST
:
pword
=
p
+
word
for
p
unct
in
PUNC_LIST
:
pword
=
p
unct
+
word
x1
=
wes
.
count
(
pword
)
while
x1
>
0
:
i
=
wes
.
index
(
pword
)
...
...
@@ -340,7 +340,7 @@ class SentiText(object):
wes
.
insert
(
i
,
word
)
x1
=
wes
.
count
(
pword
)
wordp
=
word
+
p
wordp
=
word
+
p
unct
x2
=
wes
.
count
(
wordp
)
while
x2
>
0
:
i
=
wes
.
index
(
wordp
)
...
...
@@ -357,7 +357,7 @@ class SentimentIntensityAnalyzer(object):
"""
Give a sentiment intensity score to sentences.
"""
def
__init__
(
self
,
lexicon_file
=
"vader_
sentiment_
lexicon.txt"
):
def
__init__
(
self
,
lexicon_file
=
"vader_lexicon.txt"
):
self
.
lexicon_file
=
lexicon_file
self
.
lexicon
=
self
.
make_lex_dict
()
...
...
@@ -366,10 +366,10 @@ class SentimentIntensityAnalyzer(object):
Convert lexicon file to a dictionary
"""
lex_dict
=
{}
with
open
(
self
.
lexicon_file
,
encoding
=
'
latin-1
'
)
as
infile
:
with
open
(
self
.
lexicon_file
,
encoding
=
'
utf8
'
)
as
infile
:
for
line
in
infile
:
(
w
,
m
)
=
line
.
strip
()
.
split
(
'
\t
'
)[
0
:
2
]
lex_dict
[
w
]
=
float
(
m
)
(
w
ord
,
measure
)
=
line
.
strip
()
.
split
(
'
\t
'
)[
0
:
2
]
lex_dict
[
w
ord
]
=
float
(
measure
)
return
lex_dict
def
polarity_scores
(
self
,
text
):
...
...
@@ -574,7 +574,10 @@ class SentimentIntensityAnalyzer(object):
neu
=
math
.
fabs
(
neu_count
/
total
)
else
:
compound
=
0.0
;
pos
=
0.0
;
neg
=
0.0
;
neu
=
0.0
compound
=
0.0
pos
=
0.0
neg
=
0.0
neu
=
0.0
sentiment_dict
=
\
{
"neg"
:
round
(
neg
,
3
),
...
...
@@ -586,7 +589,6 @@ class SentimentIntensityAnalyzer(object):
def
demo
():
text1
=
"At least (I think...) it isn't a HORRIBLE :-) book!"
text2
=
"Today kinda sux! But I'll get by, lol"
...
...
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