Table Of Contents

Sentiment Analysis

To analyze the sentiment of some text, do an HTTP POST to http://text-processing.com/api/sentiment/ with form encoded data containg the text you want to analyze. You’ll get back a JSON object response with 2 attributes:

label:will be either pos if the text is determined to be positive, neg if the text is negative, or neutral if the text is neither pos nor neg.
probability:an object that contains the probability for each label. neg and pos will add up to 1, while neutral is standalone. If neutral is greater than 0.5 then the label will be neutral. Otherwise, the label will be pos or neg, whichever has the greater probability.

Here’s some examples using curl:

$ curl -d "text=great" http://text-processing.com/api/sentiment/
{
        "probability": {
                "neg": 0.39680315784838732,
                "neutral": 0.28207586364297021,
                "pos": 0.60319684215161262
        },
        "label": "pos"
}

$ curl -d "text=terrible" http://text-processing.com/api/sentiment/
{
        "probability": {
                "neg": 0.68846305481785608,
                "neutral": 0.38637609994709854,
                "pos": 0.31153694518214375
        },
        "label": "neg"
}

$ curl -d "text=hi friend" http://text-processing.com/api/sentiment/
{
        "probability": {
                "neg": 0.59797768649386562,
                "neutral": 0.74939503025120124,
                "pos": 0.40202231350613421
        },
        "label": "neutral"
}

You can also get sentiment for the dutch language:

$ curl -d "language=dutch&text=goed boek" http://text-processing.com/api/sentiment/
{
        "probability": {
                "neg": 0.22499999999999998,
                "neutral": 0.099999999999999978,
                "pos": 0.77500000000000002
        },
        "label": "pos"
}

Try the sentiment analysis demo to get a feel for the results.

Parameters

text:Required - the text you want to analyze. It must not exceed 80,000 characters.
language:The default language is english, but this API also supports dutch and french.

Return Value

On success, a 200 OK response will be returned containing a JSON object that looks like this:

{
        "label": "pos",
        "probability": {
                "pos": 0.85,
                "neg": 0.15,
                "neutral": 0.4
        }
}

Errors

A 400 Bad Request response will be returned under the following conditions:

  • no value for text is provided
  • text exceeds 80,000 characters

A 503 Throttled response will be returned if you exceed the daily request limit. Signup for the Mashape Text-Processing API to get a higher limit plan.