Sentiment Analysis

Zia Sentiment Analysis is a part of Text Analytics that processes textual content to recognize the tone of the message, and the sentiments conveyed through it. It analyses each sentence in the text to determine if its tone is positive, negative, or neutral. It then determines the tone of the overall text as one of the these three sentiments, based on the sentiments recognized in each sentence.

The response also returns the confidence scores for the sentiments detected in each sentence, to showcase the accuracy of the analysis. The confidence score lies in the range of 0 to 1. A confidence score for the overall analysis is also returned.

You can pass a block of text as the input of upto 1500 characters in a single request. You can also pass optional keywords for the text. This will enable Sentiment Analysis to process only those sentences that contain these keywords, and determine their sentiments. Other sentences will be ignored.

The input text is passed to the getSentimentAnalysis() function of the ZCSentimentAnalysisData class. The code contains statements to fetch the sentiments and confidence score of each sentence, as well as the overall score.

Ensure the following packages are imported:

Copiedimport org.json.simple.JSONArray;
import com.catalyst.advanced.CatalystAdvancedIOHandler;
import com.zc.component.ml.ZCML;
import com.zc.component.ml.ZCSentenceAnalytics;
import com.zc.component.ml.ZCSentimentAnalysisData;
import com.zc.component.ml.ZCSentimentAnalysisDetails;
import com.zc.component.ml.ZCSentimentConfidenceScore;
CopiedJSONArray textArray = new JSONArray();

textArray.add("ZylkerDB is one of their best products. I've been Zylker's customer for over a decade now, and I've always had a great experience with them."); //Input text to be processed


JSONArray keywords = new JSONArray();  

keywords.add("Zylker"); //Optional keywords, if you wish to process the sentences containing only these keywords


List<ZCSentimentAnalysisData> listOfSentimentAnalysisData = ZCML.getInstance().getSentimentAnalysis(textArray,keywords); //Input text is passed

ZCSentimentAnalysisData  sentimentAnalysisData =  listOfSentimentAnalysisData.get(0);

List<ZCSentimentAnalysisDetails> SentimentAnalysisDetails =   sentimentAnalysisData .getSentimentAnalysisDetails();  
		
for (ZCSentimentAnalysisDetails sentimentAnalysis : SentimentAnalysisDetails) {

String sentiment = sentimentAnalysis.getDocumentSentiment(); //To obtain the overall sentiment of the text
					
double overallScore = sentimentAnalysis.getOverallScore(); //To obtain the confidence score of the overall analysis
					
List<ZCSentenceAnalytics> listOfSentenceAnalytics = sentimentAnalysis.getSentenceAnalytics(); //To obtain the sentiment of each sentence
					
ZCSentenceAnalytics  sentenceAnalytic = listOfSentenceAnalytics.get(0);
					
					
String sentenceSentiment = sentenceAnalytic.getSentiment(); 
					
String sentence = sentenceAnalytic.getSentence();
					
ZCSentimentConfidenceScore sentenceLevelConfidenceScore = sentenceAnalytic.getConfidenceScore(); //To obtain the confidence score of each sentence analysis
											
}