RussianSentimentAnalyzer API

Hello!

In this post we will show how easy it is to start using RussianSentimentAnalyzer API on mashape from your Java code.

Mashape

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 = "[PUT_YOUR_MASHAPE_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.mashape.com/rsa/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());
    }
}

In the code snippet above we’ve used the mashape’s Unirest API, that makes HTTP requesting in Java super easy.

All you really need to care about is to register at mashape.com, sign up for RussianSentimentAnalyzer API and insert your unique mashape key into the code, in place of “PUT_YOUR_MASHAPE_KEY_HERE”, as a value of the mashapeKey variable.

If everything has been set right, 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

Mashape

Keep calm and use an API