Class: SentimentAnalysisService

SentimentAnalysisService()

This module processes the text to measure whether it is negative, positive or neutral. The text is processed in segments of user-defined length and it provides scores for each segment as well as the overall score of the whole text.

Constructor

new SentimentAnalysisService()

Source:

Methods

call(user, text, sentence_splitopt, sentence_overlapopt, engineopt) → {Promise.<Object>}

Parameters:
Name Type Attributes Default Description
user string The ID of the user accessing the Soffos API. Soffos assumes that the owner of the api is an application (app) and that app has users. Soffos API will accept any string.
text string Text to be analyzed for sentiment.
sentence_split number <optional>
3 The number of sentences of each chunk when splitting the input text.
sentence_overlap boolean <optional>
false Whether to overlap adjacent chunks by 1 sentence. For example, with sentence_split 3 and sentence_overlap=true : [[s1, s2, s3], [s3, s4, s5], [s5, s6, s7]]
engine string <optional>
null The LLM engine to be used.
Source:
Returns:
sentiment_breakdown - dictionary list
A list of dictionaries representing the score of each segment of text. Each dictionary contains the following fields:
text: The text of the segment.
start: The starting character index of the segment in the original text.
end: The ending character index of the segment in the original text.
sentiment: A dictionary containing the scores for negative, neutral and positive.
sentiment_overall - dictionary
Contains the overall negative, neutral and positive score for the provided text.
Type
Promise.<Object>
Example
import { SoffosServices } from "soffosai";

const my_apiKey = "Token <put your api key here>";
const service = new SoffosServices.SentimentAnalysisService({apiKey:my_apiKey});
let response = await service.call(
    "client 54321",
    "What I love about Soffosai is the availability of its documentation; both in code and on-site.",
    1, false
);
console.log(JSON.stringify(response, null, 2));

// returns
// {
//     "sentiment_breakdown": [
//       {
//         "text": "What I love about Soffosai is the availability of its documentation; both in code and on-site.",
//         "start": 0,
//         "end": 94,
//         "sentiment": {
//           "negative": 0.0020085338037461042,
//           "neutral": 0.017729898914694786,
//           "positive": 0.9802615642547607
//         }
//       }
//     ],
//     "sentiment_overall": {
//       "negative": 0.0020085338037461042,
//       "neutral": 0.017729898914694786,
//       "positive": 0.9802615642547607
//     },
//     "cost": {
//       "api_call_cost": 0.005,
//       "character_volume_cost": 0.005,
//       "total_cost": 0.01
//     },
//     "charged_character_count": 100,
//     "unit_price": "0.000050"
// }

setInputConfigs(name, text, sentence_splitopt, sentence_overlapopt, engineopt)

Parameters:
Name Type Attributes Default Description
name string Reference name of this Service. It will be used by the Pipeline to reference this Service.
text string | InputConfig Text to be analyzed for sentiment.
sentence_split number | InputConfig <optional>
4 The number of sentences of each chunk when splitting the input text.
sentence_overlap boolean | InputConfig <optional>
false Whether to overlap adjacent chunks by 1 sentence. For example, with sentence_split 3 and sentence_overlap=true : [[s1, s2, s3], [s3, s4, s5], [s5, s6, s7]]
engine string <optional>
null The LLM engine to be used.
Source: