-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.rb
53 lines (43 loc) · 1.05 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require 'sinatra'
require 'json'
require 'yaml'
require 'confstruct'
require 'tokenizer'
require './lib/gender.rb'
require './lib/pronouns.rb'
require './lib/entities.rb'
config = Confstruct::Configuration.new(
YAML.load_file(
File.expand_path(
File.join(File.dirname(__FILE__), 'config.yaml')
)
)
)
set :data_path, 'data/'
gender = Gender.new({:country => 'us'})
get '/' do
erb :index
end
# /gender?name GET or POST a full name -- return a gender probability
get '/gender' do
content_type :json
{ :name => params[:name], :gender => gender.guess(params[:name]) }.to_json
end
# POST text=fulltext -- return pronoun gender
post '/content' do
content_type :json
t = Tokenizer::Tokenizer.new
tokens = t.tokenize params[:text]
p = Metrics::Pronouns.new(config)
p.process(tokens).to_json
end
# GET OR POST fulltext -- return list of tokens and their likely gender
post '/people' do
content_type :json
e = Metrics::Entities.new
e.gender(params[:text]).to_json
end
__END__
@@index
" /gender?name to get the gender for the name.
"