diff options
author | Patrick Simianer <p@simianer.de> | 2015-04-02 13:58:20 +0200 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2015-04-02 13:58:20 +0200 |
commit | 0f10af77140704a969073e0718c2eb3ba1f99ead (patch) | |
tree | 0c1093b81171ae5e1d8dbcc02dcfbbe44ac72ba3 /server.rb | |
parent | c2ce37c7c49bc17420a1bbe8a0ae50aa10e78207 (diff) |
learning
Diffstat (limited to 'server.rb')
-rw-r--r-- | server.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/server.rb b/server.rb new file mode 100644 index 0000000..fac51d1 --- /dev/null +++ b/server.rb @@ -0,0 +1,57 @@ +#!/usr/bin/env ruby + +require 'sinatra' +require 'sinatra/cross_origin' +require 'nanomsg' +require 'zipf' + +set :bind, '0.0.0.0' +set :port, 31337 + +set :allow_origin, :any +set :allow_methods, [:get, :post, :options] +set :allow_credentials, true +set :max_age, "1728000" +set :expose_headers, ['Content-Type'] + +sock = NanoMsg::PairSocket.new +addr = "ipc:///tmp/dtrain.ipc" +sock.bind addr + +input = ReadFile.readlines_strip "model/src.gz" +input_ = Array.new input + +get '/' do + cross_origin + "Nothing to see here." +end + +get '/next' do + cross_origin + if params[:example] + sock.send params[:example].strip + puts params.to_s + sock.recv # dummy + end + src = input.shift + if !src + puts "end of input, sending 'fi'" + "fi" + else + puts "sending source '#{src}' ..." + sock.send "act:translate ||| #{src}" + puts "done" + sleep 1 + puts "waiting for translation ..." + t = sock.recv + puts "got translation '#{t}'" + "#{src}\t#{t}" + end +end + +get '/reset' do + cross_origin + input = Array.new input_ + "done" +end + |