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
ac5d538c
Commit
ac5d538c
authored
Apr 30, 2015
by
Ewan Klein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some renaming of classes, methods
parent
cd638344
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
126 additions
and
11 deletions
+126
-11
nltk/sentiment/__init__.py
+16
-2
nltk/sentiment/vader.py
+7
-7
nltk/test/sentiment.ipynb
+103
-2
No files found.
nltk/sentiment/__init__.py
View file @
ac5d538c
#!/usr/bin/python
\ No newline at end of file
# -*- coding: utf-8 -*-
# Natural Language Toolkit: Twitter
#
# Copyright (C) 2001-2015 NLTK Project
# Author: Ewan Klein <ewan@inf.ed.ac.uk>
# URL: <http://nltk.org/>
# For license information, see LICENSE.TXT
"""
NLTK Sentiment Analysis Package
"""
from
nltk.sentiment.vader
import
SentimentIntensityAnalyzer
nltk/sentiment/vader.py
View file @
ac5d538c
...
...
@@ -67,10 +67,10 @@ Weblogs and Social Media (ICWSM-14). Ann Arbor, MI, June 2014.
... "However, Mr. Carter solemnly argues, his client carried out the kidnapping under orders and in the ''least offensive way possible.''"
... ]
>>> sentences.extend(tricky_sentences)
>>> sid = SentimentIntensity
Detecto
r()
>>> sid = SentimentIntensity
Analyze
r()
>>> for sentence in sentences:
... print(sentence)
... ss = sid.
sentiment
(sentence)
... ss = sid.
polarity_scores
(sentence)
... for k in sorted(ss):
... print('{0}: {1}, '.format(k, ss[k]), end='')
... print()
...
...
@@ -353,7 +353,7 @@ class SentiText(object):
class
SentimentIntensity
Detecto
r
(
object
):
class
SentimentIntensity
Analyze
r
(
object
):
"""
Give a sentiment intensity score to sentences.
"""
...
...
@@ -372,7 +372,7 @@ class SentimentIntensityDetector(object):
lex_dict
[
w
]
=
float
(
m
)
return
lex_dict
def
sentiment
(
self
,
text
):
def
polarity_scores
(
self
,
text
):
"""
Returns a float for sentiment strength based on the input text.
Positive values are positive valence, negative value are negative
...
...
@@ -590,8 +590,8 @@ class SentimentIntensityDetector(object):
def
demo
():
text1
=
"At least (I think...) it isn't a HORRIBLE :-) book!"
text2
=
"Today kinda sux! But I'll get by, lol"
sid
=
SentimentIntensity
Detecto
r
()
ss1
=
sid
.
sentiment
(
text1
)
sid
=
SentimentIntensity
Analyze
r
()
ss1
=
sid
.
polarity_scores
(
text1
)
print
(
text1
)
print
(
ss1
)
...
...
@@ -606,7 +606,7 @@ def demo():
"""
ss2
=
sid
.
sentiment
(
text2
)
ss2
=
sid
.
polarity_scores
(
text2
)
print
(
text2
)
print
(
ss2
)
...
...
nltk/test/sentiment.ipynb
View file @
ac5d538c
...
...
@@ -2,13 +2,114 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"IPython will make a temporary file named: /var/folders/ph/kjvyk6lw8xj5dc0059b22tr80000gn/T/ipython_edit_homi0r4u/ipython_edit_yj5p5w9f.py\n"
]
}
],
"source": [
"%edit"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"{'Apple_PubSub_Socket_Render': '/private/tmp/com.apple.launchd.X3UI5cWZcx/Render',\n",
" 'BIBINPUTS': '.:/Users/ewan/sync/bib::',\n",
" 'CLICOLOR': '1',\n",
" 'COLUMNS': '153',\n",
" 'COMMAND_MODE': 'unix2003',\n",
" 'CPPFLAGS': '-no-cpp-precomp',\n",
" 'CVS_RSH': 'ssh',\n",
" 'DESTINATION': '/var/folders/ph/kjvyk6lw8xj5dc0059b22tr80000gn/T/iTerm 2.0.0.20150412 Update',\n",
" 'DISPLAY': ':0.0',\n",
" 'DOCBOOKDTD': '/opt/local/share/xml/docbook/4.4/docbookx.dtd',\n",
" 'GIT_PAGER': 'cat',\n",
" 'GNUTERM': 'aqua',\n",
" 'GNUTERMAPP': '/Applications/AquaTerm.app',\n",
" 'GPG_AGENT_INFO': '/Users/ewan/.gnupg/S.gpg-agent:447:1',\n",
" 'HOME': '/Users/ewan',\n",
" 'INFANDANGO_CONFIGFILE': '/Users/ewan/hg/inf1op-docs/src/labs/config/infandango_conf.py',\n",
" 'INFANDANGO_ROOT': '/Users/ewan/hg/infandango',\n",
" 'INFOPATH': '/opt/local/share/info',\n",
" 'ITERM_PROFILE': 'git',\n",
" 'ITERM_SESSION_ID': 'w0t3p0',\n",
" 'JAVACMD': '/Library/Java/Home//bin/java',\n",
" 'JAVA_HOME': '/Library/Java/Home/',\n",
" 'JENAROOT': '/Library/Java/Jena-2.6.2',\n",
" 'JPY_PARENT_PID': '1873',\n",
" 'LANG': 'en_GB.UTF-8',\n",
" 'LDFLAGS': '-flat_namespace',\n",
" 'LOGNAME': 'ewan',\n",
" 'MANPATH': '/usr/share/man:/usr/X11R6/man:/opt/man:/opt/local/man:/usr/local/man:/usr/local/share/man:/Users/ewan/usr/local/man://Users/ewan/man',\n",
" 'NLTK_LITE_CORPORA': '/usr/share/nltk_lite/corpora',\n",
" 'OLDPWD': '/Users/ewan/git/v-nltk-sentiment/nltk',\n",
" 'PAGER': 'cat',\n",
" 'PATH': '/Users/ewan/git/v-nltk-sentiment/bin:/usr/texbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/ewan/bin:/usr/local/sbin:/usr/local/bin:/usr/local/WordNet-3.0/bin:/usr/X11R6/bin:/Developer/Tools:/Library/Java/Jena-2.6.2/bin:/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin:/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin:/Applications/acquia-drupal/mysql/bin:/Users/ewan/hg/infandango:',\n",
" 'PS1': '(v-nltk-sentiment) \\\\[\\\\a\\\\e]2;${PWD}\\\\a\\\\]\\\\\\n[\\\\W]\\\\n \\\\#% ',\n",
" 'PWD': '/Users/ewan/git/v-nltk-sentiment/nltk/nltk/test',\n",
" 'RSYNC_RSH': 'ssh',\n",
" 'SECURITYSESSIONID': '186a7',\n",
" 'SHELL': '/bin/bash',\n",
" 'SHLVL': '1',\n",
" 'SSH_AUTH_SOCK': '/private/tmp/com.apple.launchd.FzHVJGVYk9/Listeners',\n",
" 'TERM': 'xterm-color',\n",
" 'TERM_PROGRAM': 'iTerm.app',\n",
" 'TMPDIR': '/var/folders/ph/kjvyk6lw8xj5dc0059b22tr80000gn/T/',\n",
" 'USER': 'ewan',\n",
" 'VIRTUAL_ENV': '/Users/ewan/git/v-nltk-sentiment',\n",
" 'WNHOME': '/usr/local/WordNet-3.0',\n",
" 'XPC_FLAGS': '0x0',\n",
" 'XPC_SERVICE_NAME': '0',\n",
" '_': '/Users/ewan/git/v-nltk-sentiment/bin/ipython',\n",
" '__CF_USER_TEXT_ENCODING': '0x1F5:0x0:0x0',\n",
" '__PYVENV_LAUNCHER__': '/Users/ewan/git/v-nltk-sentiment/bin/python3.4'}"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%env"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from nltk.sentiment import SentimentIntensityAnalyzer"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from nltk.corpus import
sentiwordnet as swn
"
"from nltk.corpus import
tweets
"
]
},
{
...
...
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