📜 ⬆️ ⬇️

Analysis of tonality in social media in Russian using the RussianSentimentAnalyzer API

In this post I will show how to use the tonality analysis API in social media in Russian. One of the distinctive features of the system is the ability to determine the tonality with respect to a given monitoring object. I will illustrate with an example:

   X,   Y . 


It is logical to expect that if we are interested in X phones, then we want to get a positive mark of tonality. And negative for the phone Y. This is exactly the result you get by entering this offer on the site www.mashape.com/dmitrykey/russiansentimentanalyzer (registration is required) and specifying X or Y as objects.

Below you will find a sample code in Java that allows you to easily connect to the API, send a request and get the result. This and other examples of interaction with our systems can be found on our githaba .
')
 package com.semanticanalyzer; import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.JsonNode; import com.mashape.unirest.http.Unirest; import com.mashape.unirest.http.exceptions.UnirestException; public class RussianSentimentAnalyzerMashapeClient { private final static String mashapeKey = "_MASHAPE_KEY_"; public static void main(String[] args) throws UnirestException { String textToAnnotate = "'   )'"; String targetObject = "''"; // These code snippets use an open-source library. http://unirest.io/java HttpResponse response = Unirest.post("https://russiansentimentanalyzer.p.mashape.com/ru/sentiment/polarity/json/") .header("X-Mashape-Key", mashapeKey) .header("Content-Type", "application/json") .header("Accept", "application/json") .body("{'text':" + textToAnnotate + ",'object_keywords':" + targetObject + ",'output_format':'json'}") .asJson(); System.out.println("Input text = " + textToAnnotate + "\n" + "Target object: " + targetObject); System.out.println("RussianSentimentAnalyzer response:" + response.getBody().toString()); } } 

If the request is processed successfully, the system will produce the following result:

 Input text = '   )' Target object: '' RussianSentimentAnalyzer response:{"sentiment":"POSITIVE","synonyms":"[]"} 


In addition to Java, you can find examples for other languages ​​on the API site: Node, PHP, Python, Objective-C, Ruby and .NET.

Source: https://habr.com/ru/post/262213/


All Articles