2. Three simple steps to develop your own sentiment analysis service using
our language resources and/or services:
1. Sign up on
the project
website
http://portal.eurosentiment.eu/accoun
ts/signin/
2. Obtain an
access token
e.g., 78cab860-d17d-4afa-b1ac-
d6ff84e942d7
3. Sign in with
your
credentials
Fill in a form with the
following fields:
name
surname
e-mail
type of user
...
3. List tha available services and resources:
Resource: http://140.203.155.231:8890/sparql/{resource_id},
where “resource_id” is a code, e.g., c1eb1886-b3a1-4435-9284-fa1ecd9a8d55
Service: http://217.26.90.243:8080/EuroSentimentServices/services/server/access/{service_id},
where “service_id” is code, e.g., 11eb1886-b3a1-4435-9284-fa1ecd9a8d55
Note that all the HTTP method are POST and all the input parameters are in JSON formats.
Click on the selected service that you want to use to see more info (for instance, input parameters).
e.g., {"input": “The hotel was fantastic. The restaurant was cheap and the room was comfortable."}
4. import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.WebResource.Builder;
public class Services_Client {
public String postClient(String service, String req){
String results = "";
try {
Client client = Client.create();
WebResource webResource = client.resource(service);
Builder b = webResource.header("x-eurosentiment-token", "78cab860-d17d-4afa-
b1ac-d6ff84e942d7 ");
ClientResponse response = b.post(ClientResponse.class, req);
results = response.getEntity(String.class);
} catch (Exception e) {
e.printStackTrace();
}
return results;
}
}
Consume an EUROSENTIMENT service via REST APIs
Suppose that we have chosen the S/E analyzer service from the previous list, which performs sentiment
and emotion analysis on a text. The service performs sentiment analysis with automatic language
detection (for English, Italian, German, Spanish, Catalan, Portuguese) and domain detection (e.g. for hotel
and electronics).
The following shows the Java code to implement a simple REST client. In order to make a request to
EuroSentiment LRP, you must include a new HTTP header field, named x-eurosentiment-token, with the
value of your access-token (e.g., 78cab860-d17d-4afa-b1ac-d6ff84e942d7), as shown below.
Note: in the code above we use Jersey APIs: https://jersey.java.net/download.html
5. Use the created REST client
At this point, in the “main” class you have to put the text that you want to analyze, i.e., “La stanza dell'hotel era spaziosa
e pulita, sono molto contento. La colazione era abbondante e molto soddisfacente!”, in JSON format.
Input:
JSONObject j = new JSONObject();
j.put("input", "The hotel was fantastic. The restaurant was cheap and the room was comfortable!");
Perform the request to the REST endpoint of the S/E analyzer service that has id, e.g., “sesse0328”.
Call:
String results = Client.postClient(http://217.26.90.243:8080/EuroSentimentServices/services/server/access/sesse0308, j.toString());
{
"@context": "http://eurosentiment.eu/contexts/basecontext.jsonld",
"dc:language": "en",
"domain": "es:Hotel",
"analysis": [ {
"@id":"ex:Analysis",
"@type": [
"marl:SentimentAnalysis",
"onyx:EmotionAnalysis" ],
"marl:minPolarityValue": 0,
"marl:maxPolarityValue": 100,
"onyx:usesEmotionModel": "es:EmotionModel" } ],
"entries": [ {
"nif:isString": "The hotel was fantastic",
"dc:language": "en",
"domain": "es:Hotel",
"opinions": [ {
"@id": "_:Opinion1",
"marl:hasPolarity": "marl:Positive",
"marl:PolarityValue":100,
"marl:describesObject":"hotel" } ],
"emotions": [ ],
"strings": [ {
"nif:anchorOf":"hotel",
"entities": [ "hotel" ] } ] },
The results of the request are shown in JSON and are ready to be used in every service that you will want to implement!
Output:
{
"nif:isString": " The restaurant was cheap and the room was comfortable",
"dc:language": "en",
"domain": "es:Hotel",
"opinions": [ {
"@id": "_:Opinion1",
"marl:hasPolarity": "marl:Positive",
"marl:PolarityValue": 100,
"marl:describesObject": "restaurant" },
{
"@id": "_:Opinion2",
"marl:hasPolarity": "marl:Positive",
"marl:PolarityValue": 100,
"marl:describesObject": "room" } ],
"emotions": [ ],
"strings": [ {
"nif:anchorOf": "restaurant",
"entities": [
"restaurant" ] },
{
"nif:anchorOf": "room",
"entities": [
"room" ] } ] } ]}
6. public void service_test(){
Services_Client client = new Services_Client();
JSONObject j = new JSONObject();
j.put("input","The hotel was fantastic. The restaurant was cheap and the room was comfortable!");
String results =
client.postClient(“http://217.26.90.243:8080/EuroSentimentServices/services/server/access/sesse0308",
j.toString());
}
Conclusions
The following code is the method resulting from the previous steps; a simple piece of Java code to
consume the S/E analyzer service. You can use this code for accessing every EuroSentiment service by
simply changing the id of the URL.
Now, you can create your own services, using the pre-existing services in the EuroSentiment Language
Resource Pool (LRP)!
Moreover, you can register your own services on the EuroSentiment LRP platform, to:
• Increase visibility and recognition of your services
• Increase ROI of your services
• Increase the value of your services