-
Notifications
You must be signed in to change notification settings - Fork 0
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 conf/configuration.rb
with your own user token. In any case, you can change the default implementations in the module lib/clients.rb
:
class ServiceClient
def initialize(service_url, token)
@service_url = service_url
@token = token
end
def request(input)
body = JSON.dump(input)
headers = {'x-eurosentiment-token'=> @token}
response = HTTParty.post(@service_url, {:headers=> headers, :body=> body})
return JSON.load(response.body)
end
end
class ResourceClient
def initialize(resource_url, token)
@resource_url = resource_url
@token = token
end
def request(input)
body = JSON.dump(input)
headers = {'x-eurosentiment-token' => @token, 'Content-Type' => "application/json"}
response = HTTParty.post(@resource_url, {:headers=>headers, :body=>body})
return JSON.load(response.body)
end
end
Within the sample provided, you only need to instantiate a lib.ServiceClient
, passing the service URL and your user token in the constructor, and then performs calls to its request
method. You must pass dictionaries with NIF format to this method, and will receive dictionaries also in NIF format 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.
An example of service call can be found in lib/positive_words_matcher.rb
class:
# ...
@language_detector = ServiceClient.new(LANG_DETECTION_URL, TOKEN)
# ...
#...
lang_result = @language_detector.request({"text"=> text})
language = lang_result["dc:language"]
#...