forked from canademar/eurosentiment-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Exposing your application as a service.
Mario Muñoz edited this page Jun 27, 2014
·
1 revision
You have an available sample of exposing an HTTP service within the file lib/server.rb
. Usually, you only need to create a Sinatra POST method that wraps the call for the application you created in the previous step. You can customize the context where you want your service to be deployed:
set :port, 5000
post '/sentiment' do
content_type :json
data = JSON.load(request.body.read)
text = data["input"]
sentiment = sentiment_analyzer.calculate_sentiment(text)
p "Calculated sentiment: #{sentiment}"
response = {"@context"=> "http://eurosentiment.eu/contexts/basecontext.jsonld",
"@type"=> "marl:SentimentAnalysis",
"marl:polarityValue"=> sentiment}
response.to_json
end
In the given example, the final service will be exposed at http://0.0.0.0:5000/sentiment
(as specified in the code) and it will accept POST
requests, returning a JSON NIF result.