Hello!
In this post we will show how easy it is to start using RussianSentimentAnalyzer API on rapidapi in Java.
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 rapidApiKey = "[PUT_YOUR_RAPIDAPI_KEY_HERE]"; 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.rapidapi.com/rsa/sentiment/polarity/json/") .header("x-rapidapi-host", "russiansentimentanalyzer.p.rapidapi.com") .header("x-rapidapi-key", rapidApiKey) .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()); } }
In the code snippet above we’ve used the mashape’s Unirest API, that makes HTTP requesting in Java super easy. To make use of it, use the following maven dependency:
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.9</version>
</dependency>
All you really need to care about is to register at rapidapi.com, sign up for RussianSentimentAnalyzer API and insert your unique rapidapi key into the code, in place of “PUT_YOUR_RAPIDAPI_KEY_HERE”, as a value of the rapidapiKey variable.
If everything has been set right and you have an active account on rapidapi, execute the code and you should see the following output:
Input text = 'ВТБ кстати неплохой банк)' Target object:'ВТБ' RussianSentimentAnalyzer response:{"sentiment":"POSITIVE","synonyms":"[ВТБ]"}
Now you can easily hook the API up into your cool Java app and annotate texts in Russian for sentiment!
You’ll find the code on our github here: https://github.com/semanticanalyzer/nlproc_sdk_sample_code