SENTIMENT-ANALYSIS

SENTIMENT ANALYSIS

Sentiment

Extract the sentiment from a piece of text. Scores range from -1 (negative) to 1 (positive) with a score of 0 being "neutral". Emoticons, emoji, and internet short forms are given greater weight in the algorithm.

Request
path Parameters
apikey
required
string

Valid API key for your account

Request Body schema: multipart/form-data
text
required
string

A block of text to analyze. The sentiment score will be for the entire block of text.

lang
string

The two letter code of the language you want to analyze the sentiment in. The default is English (en); you do not need to specify anything if you're just scoring English text.

emoji
integer

If you'd like to ignore emoji when calculating sentiment, pass '0' as a value. Any other value or omitting this argument will result in emoji being considered when determining sentiment.

Responses
200

OK

400

error

post/{apikey}/score.json
Request samples
multipart/form-data
text=This is a great day to go for a run
Response samples
application/json
{
  • "score": 0.9229105562880748,
  • "status": "OK"
}

Sentiment (bulk)

If you plan on analyzing a large number of text documents then we suggest utilizing our bulk API. With this API call, you can POST up to 500 pieces of text a time when using English and 100 pieces of text at a time for other languages and Repustate will return a JSON list with a score for each block of text.

Request
path Parameters
apikey
required
string

Valid API key for your account

Request Body schema: multipart/form-data
text
required
string

One or more blocks of text. Each argument starting with 'text' will be scored. To help you reconcile scores with blocks of text, Repustate requires that you append some sort of ID to the POST argument. For example, if you had 50 blocks of text, you could enumerate them from 1 to 50 as text1, text2, ..., text50.

lang
string

The two letter code of the language you want to analyze the sentiment in. The default is English (en); you do not need to specify anything if you're just scoring English text.

emoji
integer

If you'd like to ignore emoji when calculating sentiment, pass '0' as a value. Any other value or omitting this argument will result in emoji being considered when determining sentiment.

Responses
200

OK

400

error

post/{apikey}/bulk-score.json
Request samples
curl -d "text1=This is one block of text&text2=This is another block of text" \
https://api.repustate.com/v4/{apikey}/bulk-score.json
Response samples
application/json
{
  • "status": "OK",
  • "results": {
    }
}

Sentiment (by topic)

Longer text can sometimes contain multiple topics or ideas. If you want the sentiment as it relates to a particular topic within a block of text, then this API call will scope the sentiment to one (or more) topics.

Request
path Parameters
apikey
required
string

Valid API key for your account

Request Body schema: multipart/form-data
text
required
string

The block or blocks of text you want to analyze sentiment for. If you want to include multiple blocks of text in one API call, enumerate this parameter (e.g. text1, text2, text3) and the response will include a reference to each text block's ID so you can reconcile scores on your end.

topics
required
string

Comma separated list of topics that you want to analyze the sentiment for.

lang
string

The two letter code of the language you want to analyze the sentiment in. The default is English (en); you do not need to specify anything if you're just scoring English text.

Responses
200

OK

400

error

post/{apikey}/topic.json
Request samples
curl -d "text=I love the cake, but hated the hats&topics=cake,hats" \
https://api.repustate.com/v4/{apikey}/topic.json
Response samples
application/json
{
  • "status": "OK",
  • "results": [
    ]
}

Chunking with sentiment

Often you might be interested in the individual portions of a document's sentiment, rather than the overall sentiment. Chunking is the process of breaking up a document into its more interesting parts and evaluating the sentiment on it. This API call chunks and returns the sentiment for each chunk.

Request
path Parameters
apikey
required
string

Valid API key for your account

Request Body schema: multipart/form-data
text
required
string

The block of text to analyze.

lang
string

The two letter code of the language you want to analyze the sentiment in. The default is English (en); you do not need to specify anything if you're just scoring English text.

Responses
200

OK

400

error

post/{apikey}/chunk.json
Request samples
curl -d "text=The service was great, the food was terrible" \
https://api.repustate.com/v4/{apikey}/chunk.json
Response samples
application/json
{
  • "status": "OK",
  • "chunks": [
    ]
}

List sentiment rules

List the custom sentiment rules you have created in a given language. Make note of the rule_id that is returned in the response, you'll need it if you want to delete a rule at a later point.

Request
path Parameters
apikey
required
string

Valid API key for your account

query Parameters
lang
string

List the rules created for the given language code. Defaults to "en" (English).

Responses
200

OK

400

error

get/{apikey}/sentiment-rules.json
Request samples
curl https://api.repustate.com/v4/{apikey}/sentiment-rules.json
Response samples
application/json
{
  • "rules": [
    ],
  • "status": "OK"
}

Add sentiment rule

If you'd like to add a custom rule for sentiment to either override how Repustate treats some words or to create domain specific language, this API call will do that for you.

Request
path Parameters
apikey
required
string

Valid API key for your account

Request Body schema: multipart/form-data
text
required
string

The word or phrase that you would like to alter the sentiment for. Use at most 3 words.

lang
string

The two letter code of the language you want to analyze the sentiment in. The default is English (en); you do not need to specify anything if you're just scoring English text.

sentiment
required
any

The sentiment this rule should be interpreted as having. Possible values include 'pos', 'neg', 'neu'.

Enum: "pos" "neg" "neu"
rule_id
string <= 79 characters

Repustate will generate a unique ID for each rule you create. However, if you would like to pass in your own rule ID's, you can via the rule_id argument. Repustate will not ensure uniqueness if you supply your own rule IDs, so please make sure you handle that on your end.

Valid values are any strings less than 80 characters in length.

Responses
200

OK

400

error

post/{apikey}/sentiment-rules.json
Request samples
curl -d "text=that is so sick&sentiment=pos" \
https://api.repustate.com/v4/{apikey}/sentiment-rules.json
Response samples
application/json
{
  • "status": "OK",
  • "rule_id": "afde1234ab"
}

Delete sentiment rule

Delete a sentiment rule that you've previously created.

Request
path Parameters
apikey
required
string

Valid API key for your account

query Parameters
lang
required
string

The language this sentiment rule applies to.

rule_id
required
string

The ID of the rule you'd like to delete. To obtain rule ID's, you'll have to first make a call to list all rules you've created.

Responses
200

OK

delete/{apikey}/sentiment-rules.json
Request samples
curl https://api.repustate.com/v4/{apikey}/sentiment-rules.json -X DELETE -G -d "rule_id=abcde12323&lang=ar"
Response samples
application/json
{
  • "status": "OK"
}