-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.rb
35 lines (29 loc) · 716 Bytes
/
app.rb
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
require 'yaml'
class SentimentAnalyzer < Sinatra::Base
POSITIVE = File.open("./config/rt-polaritydata/rt-polarity.pos", "rb").to_a
NEGATIVE = File.open("./config/rt-polaritydata/rt-polarity.neg", "rb").to_a
helpers do
def prediction(sentence)
SentimentModel.classify(@sentence)
end
def assign_vars(sentence)
@sentence = sentence
@prediction = prediction(@description)
end
end
get '/' do
erb :home
end
post '/sentiment' do
assign_vars(params[:text_blob])
erb :sentiment
end
get '/random_positive' do
assign_vars(POSITIVE.sample)
erb :sentiment
end
get '/random_negative' do
assign_vars(NEGATIVE.sample)
erb :sentiment
end
end