Aylien – Sentiment Analysis – Basic

Requires: Python, Pip

 

Setup

 

mh2@ws-mh2-16 /projects/aylien

$ pip install httpretty

Collecting httpretty

Downloading httpretty-0.8.14-py2-none-any.whl

Installing collected packages: httpretty

Successfully installed httpretty-0.8.14

 

mh2@ws-mh2-16 /projects/aylien

$ pip install unittest2

Collecting unittest2

Downloading unittest2-1.1.0-py2.py3-none-any.whl (96kB)

100% |████████████████████████████████| 102kB 1.4MB/s

Collecting traceback2 (from unittest2)

Downloading traceback2-1.4.0-py2.py3-none-any.whl

Requirement already satisfied: six>=1.4 in /usr/lib/python2.7/site-packages (from unittest2)

Collecting argparse (from unittest2)

Downloading argparse-1.4.0-py2.py3-none-any.whl

Collecting linecache2 (from traceback2->unittest2)

Downloading linecache2-1.0.0-py2.py3-none-any.whl

Installing collected packages: linecache2, traceback2, argparse, unittest2

Successfully installed argparse-1.4.0 linecache2-1.0.0 traceback2-1.4.0 unittest2-1.1.0

 

mh2@ws-mh2-16 /projects/aylien

$ pip install nose

Collecting nose

Downloading nose-1.3.7-py2-none-any.whl (154kB)

100% |████████████████████████████████| 163kB 1.3MB/s

Installing collected packages: nose

Successfully installed nose-1.3.7

 

mh2@ws-mh2-16 /projects/aylien

$ pip install httplib2

Collecting httplib2

Downloading httplib2-0.10.3.tar.gz (204kB)

100% |████████████████████████████████| 204kB 1.5MB/s

Building wheels for collected packages: httplib2

Running setup.py bdist_wheel for httplib2 … done

Stored in directory: /home/mh2/.cache/pip/wheels/ca/ac/5f/749651f7925b231103f5316cacca82a487810c22d30f011c0c

Successfully built httplib2

Installing collected packages: httplib2

Successfully installed httplib2-0.10.3

 

mh2@ws-mh2-16 /projects/aylien

$ pip install –upgrade aylien-apiclient

Collecting aylien-apiclient

Downloading aylien-apiclient-0.6.0.tar.gz

Requirement already up-to-date: httplib2>=0.9 in /usr/lib/python2.7/site-packages (from aylien-apiclient)

Building wheels for collected packages: aylien-apiclient

Running setup.py bdist_wheel for aylien-apiclient … done

Stored in directory: /home/mh2/.cache/pip/wheels/fb/a9/e8/afb6f1924e90a8c2694facb86a3ac58e8a891c2e91bf416512

Successfully built aylien-apiclient

Installing collected packages: aylien-apiclient

Successfully installed aylien-apiclient-0.6.0

 

Script:

~~~~~~ test1.py ~~~~~~~~~

#!/usr/bin/env python

 

“””

test1.py: Demonstrates calling the remote sentiment analysis api with

simple text and prints the result. Language support is included for a

select few Western European languages.

Something like this could potentially be used in an adhoc text collection

scenario, such as an interview.

Quote re sentiment: “whether the tone is positive, neutral or negative,

and whether the text is subjective (meaning it’s reflecting the author’s

opinion) or objective (meaning it’s expressing a fact)”

Source: http://docs.aylien.com/docs/sentiment

Aylien: 4th Floor, Equity House, Upper Ormand Quay, Dublin 7, Ireland

“””

 

import json

from aylienapiclient import textapi

 

__author__ = “Matthew Hogan”

__status__ = “Demo”

 

sentiment = {


‘mode’ : ‘tweet’,


‘text’ : ‘I had hoped that you didn\’t say No, and you said Yes.’,


‘language’ : ‘en’

}

 

client = textapi.Client(“……”, “………………………………………”)

result = client.Sentiment(sentiment)

 

print json.dumps(result, indent=4, sort_keys=True)

 

~~~~~~ test1.py ~~~~~~~~~

Running in Visual Studio Code with a Python extension.

Java

If using Maven:-

<dependency>

<groupId>com.aylien.textapi</groupId>

<artifactId>client</artifactId>

<version>0.6.0</version>

</dependency>

 

The call is simple:-

 

SentimentParams params = SentimentParams.newBuilder().setMode(“tweet”).setText(text).build();

TextAPIClient client = new TextAPIClient(“3af81c77”, “97d6013e54853be7bea03f99506f6194”);

 

References

http://docs.aylien.com/docs/sentiment