get_batch_sentiment: Sentiment Score Calculation

Description Usage Arguments Details Value References See Also Examples

View source: R/Sentiment.R

Description

The function send batch request (100 IDs per request) to microsoft sentiment analysis API and get a sentiment score between 0 to 1 for each textual data point. Each document/sentence size should not exceed 5,120 character.

Usage

1
get_batch_sentiment(data, auth_key, api_region, batch_size)

Arguments

data

dataframe with 2 columns - 'text' and 'language' - is necessary to get sentiment score. Other columns will be maintained as is in the returned dataframe. Check Microsoft API website for more information on language options available.

auth_key

Authorization key associated with Microsoft API

api_region

Provide region for which the authorization key is valid.

batch_size

Default batch size is 100 considering free API trial. Change accordingly based on your paid subscription.

Details

The API wrapper uses the Microsoft Cognitive Services - Text Analytics API. The API uses Sentiment Analysis - v2.1 version. API generates sentiment score between 0 and 1 with scores closer to 1 indicate positive sentiment and score close to 0 indicate negative sentiment.

Value

Function returns dataframe with additional 'Id' and 'Sentiment Score' columns for input data.

References

Microsoft Sentiment Analysis Website

See Also

API Documentation

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
require(httr)
require(jsonlite)

sent_data <- c('It was a beautiful day', 'I do not like this game')
sent_lang <- c('en', 'en')
dataset <- data.frame('text'=sent_data, 'language'=sent_lang)

# auth_key is your unique API access key and has region associated with it

#sentiment_data <- get_batch_sentiment(dataset, "eda0526b71ff44b29c", "westcentralus")

Ritayu09/Test_R_Package documentation built on June 6, 2020, 2:29 a.m.