-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.rb
More file actions
41 lines (32 loc) · 869 Bytes
/
app.rb
File metadata and controls
41 lines (32 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# require essential libraries
require 'sinatra'
require 'http'
# require other helper libraries
require_relative './helpers/helper.rb'
# adds configurations
require './config/environment'
# API setup
class RubyStarter < Sinatra::Base
# add helpers
helpers Helpers
API_URL = ENV['API_URL']
# routes
get '/?' do
haml :index
end
# classify piece of text
get '/classify' do
@api_url = API_URL
response = HTTP.post(@api_url, :json => {:lang=>"und", :text =>"#{params['text']}"})
emotion_content = JSON.parse(response)
# collection all emotion classes returned
if emotion_content["groups"]
@emotion_groups = emotion_content["groups"].map {|g| g["name"]}
end
# check if ambiguous
if emotion_content["ambiguous"]
@emotion_ambiguity_status = emotion_content["ambiguous"]
end
haml :result
end
end