-
Notifications
You must be signed in to change notification settings - Fork 8
Using Eurosentiment LRP services.
One of Eurosentiment main advantages is that you can use and combine other providers' services for creating your own linguistic services. You only need to be registered in the platform and use your authentication token.
Once you're registered in the Eurosentiment LRP you are given an authentication token for accessing the resources and services available in the portal. This token is initially sent to you with your confirmation e-mail, but you can see it accessing the Subscription Details Menu or even request a new one in the Reset Token Menu.
Every request to Eurosentiment services and resources must be authenticated with an user token. Every resource is accessed via an HTTP request, which must contain an extra x-eurosentiment-token
header containing the user token.
This sample perform this authentication for you, provided that you fill the file src/main/resources/application.properties
with your own user token. In any case, you can change the default implementation in the class client/ServiceClient.java
:
public class ServiceClient {
private String serviceUrl;
private String token;
private WebResource resource;
public ServiceClient(String serviceUrl, String token) {
this.serviceUrl = serviceUrl;
this.token = token;
Client client = Client.create();
this.resource = client.resource(serviceUrl);
}
public NifOutput request(NifInput input) {
WebResource.Builder builder = this.resource.header("x-eurosentiment-token", this.token)
.header("content-type", "application/json");
ClientResponse response = builder.post(ClientResponse.class, input.asJson());
String result = response.getEntity(String.class);
return new NifOutput(result);
}
}
Within the sample provide, you only need to instantiate a samples/ServiceClient
, passing the service URL and your user token in the constructor, and then performs calls to its request
method. You must pass instances of the NifInput
class, and will receive NifOutput
instances as a response (or an Exception if something goes wrong). You can check the details and the URLs of the available resources in the LRPMA.
NifInput
and NifOutput
are just wrappers for JSON data that must follow the NIF standard. An example of service call can be found in the samples/PositiveWordsMatcher.java
class:
// ...
this.languageDetector = new ServiceClient(this.languageDetectionServiceUrl, this.token);
// ...
//...
NifOutput languageResult = this.languageDetector.request(new NifInput("{'text':" + text + "}"));
String language = languageResult.getJson().getString("dc:language");
//...
EUROSENTIMENT PROJECT (Grant Agreement no: 296277, Starting date: 01/09/2012, Project duration: 24 months)