ajax-cat 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +8 -0
- data/Gemfile.lock +28 -0
- data/Rakefile +11 -6
- data/VERSION +1 -1
- data/ajax-cat.gemspec +52 -18
- data/bin/ajax-cat +14 -0
- data/lib/.DS_Store +0 -0
- data/lib/ajax-cat.rb +36 -3
- data/lib/ajax-cat/ajax_cat_server.rb +21 -0
- data/lib/ajax-cat/logger.rb +33 -0
- data/lib/ajax-cat/moses_pair.rb +62 -0
- data/lib/{public → ajax-cat/public}/AjaxCatList.coffee +0 -0
- data/lib/{public → ajax-cat/public}/AjaxCatTranslation.coffee +0 -0
- data/lib/{public → ajax-cat/public}/Suggestions.coffee +0 -0
- data/lib/{public → ajax-cat/public}/TranslationTable.coffee +0 -0
- data/lib/{public → ajax-cat/public}/Utils.coffee +0 -0
- data/lib/{public → ajax-cat/public}/ajax-cat.coffee +0 -0
- data/lib/{public → ajax-cat/public}/ajax-cat.js +0 -0
- data/lib/{public → ajax-cat/public}/bootstrap.css +0 -0
- data/lib/{public → ajax-cat/public}/bootstrap.js +0 -0
- data/lib/{public → ajax-cat/public}/index.html +0 -0
- data/lib/{public → ajax-cat/public}/index.js +0 -0
- data/lib/{public → ajax-cat/public}/jquery.js +0 -0
- data/lib/{public → ajax-cat/public}/style.css +0 -0
- data/lib/{public → ajax-cat/public}/translation.html +0 -0
- data/lib/{public → ajax-cat/public}/translation.js +0 -0
- data/lib/ajax-cat/request/raw.rb +36 -0
- data/lib/ajax-cat/request/simple.rb +27 -0
- data/test/fixtures/europarl.srilm.gz +0 -0
- data/test/fixtures/moses.ini +42 -0
- data/test/fixtures/phrase-table +22 -0
- data/test/fixtures/translation_table +10 -0
- data/test/helper.rb +55 -2
- data/test/integration/test_start_and_stop.rb +28 -0
- data/test/unit/.DS_Store +0 -0
- data/test/unit/test_logger.rb +21 -0
- data/test/unit/test_moses_pair.rb +19 -0
- data/test/unit/test_raw_request.rb +39 -0
- data/test/unit/test_simple_request.rb +25 -0
- metadata +108 -26
- data/test/test_ajax-cat.rb +0 -7
data/Gemfile
CHANGED
@@ -5,8 +5,16 @@ source "http://rubygems.org"
|
|
5
5
|
|
6
6
|
# Add dependencies to develop your gem here.
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
|
9
|
+
gem 'sinatra', "~> 1.3.2"
|
10
|
+
gem 'colorize', "~> 0.5.8"
|
11
|
+
gem "thin", "~> 1.3.1"
|
12
|
+
gem "thor", "~> 0.15.2"
|
13
|
+
|
8
14
|
group :development do
|
9
15
|
gem "rdoc", "~> 3.12"
|
10
16
|
gem "bundler", "~> 1.0.0"
|
11
17
|
gem "jeweler", "~> 1.8.3"
|
18
|
+
gem "shoulda", "~> 3.0.1"
|
19
|
+
gem "curb", "~> 0.8.0"
|
12
20
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
colorize (0.5.8)
|
5
|
+
curb (0.8.0)
|
6
|
+
daemons (1.1.8)
|
7
|
+
eventmachine (0.12.10)
|
4
8
|
git (1.2.5)
|
5
9
|
jeweler (1.8.3)
|
6
10
|
bundler (~> 1.0)
|
@@ -8,14 +12,38 @@ GEM
|
|
8
12
|
rake
|
9
13
|
rdoc
|
10
14
|
json (1.6.6)
|
15
|
+
rack (1.4.1)
|
16
|
+
rack-protection (1.2.0)
|
17
|
+
rack
|
11
18
|
rake (0.9.2.2)
|
12
19
|
rdoc (3.12)
|
13
20
|
json (~> 1.4)
|
21
|
+
shoulda (3.0.1)
|
22
|
+
shoulda-context (~> 1.0.0)
|
23
|
+
shoulda-matchers (~> 1.0.0)
|
24
|
+
shoulda-context (1.0.0)
|
25
|
+
shoulda-matchers (1.0.0)
|
26
|
+
sinatra (1.3.2)
|
27
|
+
rack (~> 1.3, >= 1.3.6)
|
28
|
+
rack-protection (~> 1.2)
|
29
|
+
tilt (~> 1.3, >= 1.3.3)
|
30
|
+
thin (1.3.1)
|
31
|
+
daemons (>= 1.0.9)
|
32
|
+
eventmachine (>= 0.12.6)
|
33
|
+
rack (>= 1.0.0)
|
34
|
+
thor (0.15.2)
|
35
|
+
tilt (1.3.3)
|
14
36
|
|
15
37
|
PLATFORMS
|
16
38
|
ruby
|
17
39
|
|
18
40
|
DEPENDENCIES
|
19
41
|
bundler (~> 1.0.0)
|
42
|
+
colorize (~> 0.5.8)
|
43
|
+
curb (~> 0.8.0)
|
20
44
|
jeweler (~> 1.8.3)
|
21
45
|
rdoc (~> 3.12)
|
46
|
+
shoulda (~> 3.0.1)
|
47
|
+
sinatra (~> 1.3.2)
|
48
|
+
thin (~> 1.3.1)
|
49
|
+
thor (~> 0.15.2)
|
data/Rakefile
CHANGED
@@ -13,7 +13,6 @@ require 'rake'
|
|
13
13
|
|
14
14
|
require 'jeweler'
|
15
15
|
Jeweler::Tasks.new do |gem|
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
16
|
gem.name = "ajax-cat"
|
18
17
|
gem.homepage = "http://github.com/hypertornado/ajax-cat"
|
19
18
|
gem.license = "MIT"
|
@@ -21,15 +20,21 @@ Jeweler::Tasks.new do |gem|
|
|
21
20
|
gem.description = %Q{computer-aided translation backed by machine translation}
|
22
21
|
gem.email = "odchazel@gmail.com"
|
23
22
|
gem.authors = ["Ondrej Odchazel"]
|
24
|
-
# dependencies defined in Gemfile
|
25
23
|
end
|
26
24
|
Jeweler::RubygemsDotOrgTasks.new
|
27
25
|
|
28
26
|
require 'rake/testtask'
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
namespace :test do
|
28
|
+
Rake::TestTask.new(:unit) do |test|
|
29
|
+
test.libs << 'lib' << 'test'
|
30
|
+
test.test_files = FileList['test/unit/test_*.rb','test/integration/*.rb']
|
31
|
+
test.verbose = false
|
32
|
+
end
|
33
|
+
Rake::TestTask.new(:integration) do |test|
|
34
|
+
test.libs << 'lib' << 'test'
|
35
|
+
test.test_files = FileList['test/integration/*.rb']
|
36
|
+
test.verbose = false
|
37
|
+
end
|
33
38
|
end
|
34
39
|
|
35
40
|
task :default => :test
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/ajax-cat.gemspec
CHANGED
@@ -5,13 +5,14 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "ajax-cat"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ondrej Odchazel"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-05-16"
|
13
13
|
s.description = "computer-aided translation backed by machine translation"
|
14
14
|
s.email = "odchazel@gmail.com"
|
15
|
+
s.executables = ["ajax-cat"]
|
15
16
|
s.extra_rdoc_files = [
|
16
17
|
"LICENSE.txt",
|
17
18
|
"README.rdoc"
|
@@ -25,25 +26,40 @@ Gem::Specification.new do |s|
|
|
25
26
|
"Rakefile",
|
26
27
|
"VERSION",
|
27
28
|
"ajax-cat.gemspec",
|
29
|
+
"bin/ajax-cat",
|
28
30
|
"lib/.DS_Store",
|
29
31
|
"lib/ajax-cat.rb",
|
30
|
-
"lib/
|
31
|
-
"lib/
|
32
|
-
"lib/
|
33
|
-
"lib/public/
|
34
|
-
"lib/public/
|
35
|
-
"lib/
|
36
|
-
"lib/
|
37
|
-
"lib/public/
|
38
|
-
"lib/public/
|
39
|
-
"lib/public/
|
40
|
-
"lib/public/
|
41
|
-
"lib/public/
|
42
|
-
"lib/public/
|
43
|
-
"lib/public/
|
44
|
-
"lib/public/
|
32
|
+
"lib/ajax-cat/ajax_cat_server.rb",
|
33
|
+
"lib/ajax-cat/logger.rb",
|
34
|
+
"lib/ajax-cat/moses_pair.rb",
|
35
|
+
"lib/ajax-cat/public/AjaxCatList.coffee",
|
36
|
+
"lib/ajax-cat/public/AjaxCatTranslation.coffee",
|
37
|
+
"lib/ajax-cat/public/Suggestions.coffee",
|
38
|
+
"lib/ajax-cat/public/TranslationTable.coffee",
|
39
|
+
"lib/ajax-cat/public/Utils.coffee",
|
40
|
+
"lib/ajax-cat/public/ajax-cat.coffee",
|
41
|
+
"lib/ajax-cat/public/ajax-cat.js",
|
42
|
+
"lib/ajax-cat/public/bootstrap.css",
|
43
|
+
"lib/ajax-cat/public/bootstrap.js",
|
44
|
+
"lib/ajax-cat/public/index.html",
|
45
|
+
"lib/ajax-cat/public/index.js",
|
46
|
+
"lib/ajax-cat/public/jquery.js",
|
47
|
+
"lib/ajax-cat/public/style.css",
|
48
|
+
"lib/ajax-cat/public/translation.html",
|
49
|
+
"lib/ajax-cat/public/translation.js",
|
50
|
+
"lib/ajax-cat/request/raw.rb",
|
51
|
+
"lib/ajax-cat/request/simple.rb",
|
52
|
+
"test/fixtures/europarl.srilm.gz",
|
53
|
+
"test/fixtures/moses.ini",
|
54
|
+
"test/fixtures/phrase-table",
|
55
|
+
"test/fixtures/translation_table",
|
45
56
|
"test/helper.rb",
|
46
|
-
"test/
|
57
|
+
"test/integration/test_start_and_stop.rb",
|
58
|
+
"test/unit/.DS_Store",
|
59
|
+
"test/unit/test_logger.rb",
|
60
|
+
"test/unit/test_moses_pair.rb",
|
61
|
+
"test/unit/test_raw_request.rb",
|
62
|
+
"test/unit/test_simple_request.rb"
|
47
63
|
]
|
48
64
|
s.homepage = "http://github.com/hypertornado/ajax-cat"
|
49
65
|
s.licenses = ["MIT"]
|
@@ -55,18 +71,36 @@ Gem::Specification.new do |s|
|
|
55
71
|
s.specification_version = 3
|
56
72
|
|
57
73
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
74
|
+
s.add_runtime_dependency(%q<sinatra>, ["~> 1.3.2"])
|
75
|
+
s.add_runtime_dependency(%q<colorize>, ["~> 0.5.8"])
|
76
|
+
s.add_runtime_dependency(%q<thin>, ["~> 1.3.1"])
|
77
|
+
s.add_runtime_dependency(%q<thor>, ["~> 0.15.2"])
|
58
78
|
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
59
79
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
60
80
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
81
|
+
s.add_development_dependency(%q<shoulda>, ["~> 3.0.1"])
|
82
|
+
s.add_development_dependency(%q<curb>, ["~> 0.8.0"])
|
61
83
|
else
|
84
|
+
s.add_dependency(%q<sinatra>, ["~> 1.3.2"])
|
85
|
+
s.add_dependency(%q<colorize>, ["~> 0.5.8"])
|
86
|
+
s.add_dependency(%q<thin>, ["~> 1.3.1"])
|
87
|
+
s.add_dependency(%q<thor>, ["~> 0.15.2"])
|
62
88
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
63
89
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
64
90
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
91
|
+
s.add_dependency(%q<shoulda>, ["~> 3.0.1"])
|
92
|
+
s.add_dependency(%q<curb>, ["~> 0.8.0"])
|
65
93
|
end
|
66
94
|
else
|
95
|
+
s.add_dependency(%q<sinatra>, ["~> 1.3.2"])
|
96
|
+
s.add_dependency(%q<colorize>, ["~> 0.5.8"])
|
97
|
+
s.add_dependency(%q<thin>, ["~> 1.3.1"])
|
98
|
+
s.add_dependency(%q<thor>, ["~> 0.15.2"])
|
67
99
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
68
100
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
69
101
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
102
|
+
s.add_dependency(%q<shoulda>, ["~> 3.0.1"])
|
103
|
+
s.add_dependency(%q<curb>, ["~> 0.8.0"])
|
70
104
|
end
|
71
105
|
end
|
72
106
|
|
data/bin/ajax-cat
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/bin/ruby
|
2
|
+
|
3
|
+
require_relative('../lib/ajax-cat.rb')
|
4
|
+
|
5
|
+
case ARGV.first
|
6
|
+
when "start"
|
7
|
+
AjaxCat::Starter.start(8585, true)
|
8
|
+
when "stop"
|
9
|
+
puts "Stopping ajax-cat server."
|
10
|
+
AjaxCat::Starter.stop
|
11
|
+
puts "Server stopped."
|
12
|
+
else
|
13
|
+
puts "Unknown command."
|
14
|
+
end
|
data/lib/.DS_Store
CHANGED
Binary file
|
data/lib/ajax-cat.rb
CHANGED
@@ -1,5 +1,38 @@
|
|
1
|
-
|
1
|
+
#echo "i think that this house is small" | ./moses -f en-cs/moses.ini -n-best-list - 10 distinct -include-alignment-in-n-best true 2>/dev/null
|
2
|
+
|
3
|
+
require 'sinatra/base'
|
4
|
+
require 'thin'
|
5
|
+
require 'json'
|
6
|
+
require 'thread'
|
7
|
+
require 'colorize'
|
8
|
+
require_relative 'ajax-cat/moses_pair.rb'
|
9
|
+
require_relative 'ajax-cat/request/raw.rb'
|
10
|
+
require_relative 'ajax-cat/request/simple.rb'
|
11
|
+
require_relative 'ajax-cat/ajax_cat_server.rb'
|
12
|
+
require_relative 'ajax-cat/logger.rb'
|
13
|
+
|
14
|
+
module AjaxCat
|
15
|
+
|
16
|
+
class Starter
|
17
|
+
|
18
|
+
def self.pair
|
19
|
+
@@pair
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.start(port = 8585, silent = false)
|
23
|
+
logger = Logger.new
|
24
|
+
logger.log "starting ajax-cat"
|
25
|
+
Thin::Logging.silent = silent
|
26
|
+
@@pair = MosesPair.new('cs-en',"moses","/Users/ondrejodchazel/projects/ajax-cat/ajax-cat-new/test/fixtures/moses.ini")
|
27
|
+
Dir.chdir(Dir.home)
|
28
|
+
Dir.mkdir('.ajax-cat') unless Dir.exist?('.ajax-cat')
|
29
|
+
builder = Rack::Builder.new do
|
30
|
+
map('/'){ run AjaxCatServer }
|
31
|
+
end
|
32
|
+
logger.log "starting server on port #{port}"
|
33
|
+
Rack::Handler::Thin.run builder, :Port => port
|
34
|
+
logger.log "shutting down ajax-cat server"
|
35
|
+
end
|
36
|
+
end
|
2
37
|
|
3
|
-
get '/' do
|
4
|
-
redirect '/index.html'
|
5
38
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
module AjaxCat
|
3
|
+
|
4
|
+
class AjaxCatServer < Sinatra::Base
|
5
|
+
|
6
|
+
configure :production, :development do
|
7
|
+
disable :logging
|
8
|
+
end
|
9
|
+
|
10
|
+
get '/' do
|
11
|
+
"hello world"
|
12
|
+
end
|
13
|
+
|
14
|
+
get '/api/raw' do
|
15
|
+
req = Request::Raw.new(params[:q])
|
16
|
+
Starter.pair.process_request(req)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module AjaxCat
|
2
|
+
class Logger
|
3
|
+
|
4
|
+
@@print = true
|
5
|
+
|
6
|
+
def self.print_log(val)
|
7
|
+
@@print = val
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(prefix = false)
|
11
|
+
@prefix = prefix
|
12
|
+
end
|
13
|
+
|
14
|
+
def log(message)
|
15
|
+
return unless @@print
|
16
|
+
puts compose_message(message)
|
17
|
+
end
|
18
|
+
|
19
|
+
def compose_message(message)
|
20
|
+
t = Time.now
|
21
|
+
milliseconds = (t.to_f * 1000 % 1000).to_i
|
22
|
+
ret = (t.strftime("%Y-%d-%m %H:%M:%S.#{milliseconds}") + " ")
|
23
|
+
(3 - milliseconds.to_s.length).times {ret += " "}
|
24
|
+
if @prefix
|
25
|
+
ret = "#{ret}#{@prefix.red}: #{message}"
|
26
|
+
else
|
27
|
+
ret = "#{ret}#{message.green}"
|
28
|
+
end
|
29
|
+
ret
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module AjaxCat
|
2
|
+
class MosesPair
|
3
|
+
|
4
|
+
def initialize(name, moses_path, moses_ini_path)
|
5
|
+
@logger = Logger.new(name)
|
6
|
+
@logger.log "starting pair".green
|
7
|
+
@request_queue = []
|
8
|
+
@name = name
|
9
|
+
@queue_lock = Mutex.new
|
10
|
+
Dir.chdir(Dir.home + "/.ajax-cat")
|
11
|
+
@fifo_path = "#{Dir.home}/.ajax-cat/#{name}_fifo.fifo"
|
12
|
+
system("rm #{@fifo_path}; mkfifo #{@fifo_path}")
|
13
|
+
t1 = Thread.new{reader()}
|
14
|
+
@pipe = IO.popen("#{moses_path} -f #{moses_ini_path} -n-best-list - 300 distinct > #{@fifo_path} 2>/dev/null", "w")
|
15
|
+
process_request(Request::Raw.new("start_test"))
|
16
|
+
@logger.log "pair started".green
|
17
|
+
end
|
18
|
+
|
19
|
+
def process_string(str)
|
20
|
+
@pipe.write("#{str}\nxxxxnonsensestringxxx\n")
|
21
|
+
@pipe.flush
|
22
|
+
end
|
23
|
+
|
24
|
+
def process_request(request)
|
25
|
+
@logger.log "processing #{request.class.name} '#{request.sentence.blue}'"
|
26
|
+
@queue_lock.synchronize do
|
27
|
+
request.lock.lock
|
28
|
+
@request_queue.push(request)
|
29
|
+
process_string(request.sentence)
|
30
|
+
end
|
31
|
+
#TODO: avoid active waiting somehow
|
32
|
+
until request.processed
|
33
|
+
sleep 0.001
|
34
|
+
end
|
35
|
+
@logger.log "processed #{request.class.name} '#{request.sentence.blue}'"
|
36
|
+
request.result
|
37
|
+
end
|
38
|
+
|
39
|
+
def reader
|
40
|
+
f = open @fifo_path, File::RDWR|File::NONBLOCK
|
41
|
+
last_position = -1
|
42
|
+
|
43
|
+
while l = f.readline
|
44
|
+
position = Request::Raw.parse_position(l)
|
45
|
+
if position != last_position
|
46
|
+
if (last_position % 2 == 0)
|
47
|
+
@current_request.processed = true
|
48
|
+
@current_request = nil
|
49
|
+
else
|
50
|
+
@queue_lock.synchronize do
|
51
|
+
@current_request = @request_queue.shift
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
@current_request.process_line(l) if @current_request
|
56
|
+
last_position = position
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module AjaxCat
|
4
|
+
|
5
|
+
module Request
|
6
|
+
|
7
|
+
class Raw
|
8
|
+
|
9
|
+
attr_accessor :sentence, :lock, :processed
|
10
|
+
|
11
|
+
def initialize(sentence)
|
12
|
+
@sentence = sentence
|
13
|
+
@lines = []
|
14
|
+
@lock = Mutex.new
|
15
|
+
@processed = false
|
16
|
+
#@lock.lock
|
17
|
+
end
|
18
|
+
|
19
|
+
def result
|
20
|
+
@lines.join("\n")
|
21
|
+
end
|
22
|
+
|
23
|
+
def process_line(line)
|
24
|
+
@lines << line.chomp
|
25
|
+
end
|
26
|
+
|
27
|
+
def Raw.parse_position(line)
|
28
|
+
Integer(line.split(" ||| ").first)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module AjaxCat
|
4
|
+
|
5
|
+
module Request
|
6
|
+
|
7
|
+
class Simple < Raw
|
8
|
+
|
9
|
+
def initialize(sentence)
|
10
|
+
super(sentence)
|
11
|
+
@best_translation = false
|
12
|
+
end
|
13
|
+
|
14
|
+
def result
|
15
|
+
@best_translation
|
16
|
+
end
|
17
|
+
|
18
|
+
def process_line(line)
|
19
|
+
@best_translation = line.split(" ||| ")[1] unless @best_translation
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
end
|
Binary file
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#########################
|
2
|
+
### MOSES CONFIG FILE ###
|
3
|
+
#########################
|
4
|
+
|
5
|
+
# input factors
|
6
|
+
[input-factors]
|
7
|
+
0
|
8
|
+
|
9
|
+
# mapping steps, either (T) translation or (G) generation
|
10
|
+
[mapping]
|
11
|
+
T 0
|
12
|
+
|
13
|
+
# translation tables: source-factors, target-factors, number of scores, file
|
14
|
+
[ttable-file]
|
15
|
+
0 0 0 1 /Users/ondrejodchazel/projects/ajax-cat/ajax-cat-new/test/fixtures/phrase-table
|
16
|
+
|
17
|
+
# language models: type(srilm/irstlm/kenlm), factors, order, file
|
18
|
+
[lmodel-file]
|
19
|
+
8 0 3 /Users/ondrejodchazel/projects/ajax-cat/ajax-cat-new/test/fixtures/europarl.srilm.gz
|
20
|
+
|
21
|
+
# limit on how many phrase translations e for each phrase f are loaded
|
22
|
+
[ttable-limit]
|
23
|
+
10
|
24
|
+
|
25
|
+
# distortion (reordering) weight
|
26
|
+
[weight-d]
|
27
|
+
1
|
28
|
+
|
29
|
+
# language model weights
|
30
|
+
[weight-l]
|
31
|
+
1
|
32
|
+
|
33
|
+
# translation model weights
|
34
|
+
[weight-t]
|
35
|
+
1
|
36
|
+
|
37
|
+
# word penalty
|
38
|
+
[weight-w]
|
39
|
+
0
|
40
|
+
|
41
|
+
|
42
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
der ||| the ||| 0.3 ||| |||
|
2
|
+
das ||| the ||| 0.4 ||| |||
|
3
|
+
das ||| it ||| 0.1 ||| |||
|
4
|
+
das ||| this ||| 0.1 ||| |||
|
5
|
+
die ||| the ||| 0.3 ||| |||
|
6
|
+
ist ||| is ||| 1.0 ||| |||
|
7
|
+
ist ||| 's ||| 1.0 ||| |||
|
8
|
+
das ist ||| it is ||| 0.2 ||| |||
|
9
|
+
das ist ||| this is ||| 0.8 ||| |||
|
10
|
+
es ist ||| it is ||| 0.8 ||| |||
|
11
|
+
es ist ||| this is ||| 0.2 ||| |||
|
12
|
+
ein ||| a ||| 1.0 ||| |||
|
13
|
+
ein ||| an ||| 1.0 ||| |||
|
14
|
+
klein ||| small ||| 0.8 ||| |||
|
15
|
+
klein ||| little ||| 0.8 ||| |||
|
16
|
+
kleines ||| small ||| 0.2 ||| |||
|
17
|
+
kleines ||| little ||| 0.2 ||| |||
|
18
|
+
haus ||| house ||| 1.0 ||| |||
|
19
|
+
alt ||| old ||| 0.8 ||| |||
|
20
|
+
altes ||| old ||| 0.2 ||| |||
|
21
|
+
gibt ||| gives ||| 1.0 ||| |||
|
22
|
+
es gibt ||| there is ||| 1.0 ||| |||
|
@@ -0,0 +1,10 @@
|
|
1
|
+
10 ||| myslím , že tento dům je malá ||| d: 0 lm: -33.2059 w: -7 tm: -3.67773 -6.51247 -6.97174 -12.6506 3.99959 ||| -4.63843 ||| 0-1=0 2=1-2 3-5=3-5 6=6
|
2
|
+
10 ||| myslím , že tento dům je malý ||| d: 0 lm: -34.3365 w: -7 tm: -3.64414 -6.48191 -4.03682 -12.2464 2.99969 ||| -4.69029 ||| 0-1=0-1 2-4=2-4 5-6=5-6
|
3
|
+
10 ||| myslím si , že tento dům je malá ||| d: 0 lm: -34.5709 w: -8 tm: -3.97815 -7.51106 -6.04539 -15.5693 2.99969 ||| -4.83337 ||| 0-2=0-3 3-5=4-6 6=7
|
4
|
+
10 ||| myslím , že tento dům je malé ||| d: 0 lm: -36.2431 w: -7 tm: -3.06731 -6.01768 -5.40147 -11.3428 3.99959 ||| -4.8618 ||| 0-1=0 2=1-2 3-5=3-5 6=6
|
5
|
+
10 ||| myslím si , že tento dům je malý ||| d: 0 lm: -35.7015 w: -8 tm: -4.0827 -7.4805 -5.13395 -15.1651 2.99969 ||| -4.93817 ||| 0-2=0-3 3-4=4-5 5-6=6-7
|
6
|
+
10 ||| myslím si , že tento dům je malé ||| d: 0 lm: -37.6081 w: -8 tm: -3.36773 -7.01628 -4.47512 -14.2614 2.99969 ||| -5.05673 ||| 0-2=0-3 3-5=4-6 6=7
|
7
|
+
10 ||| myslím , že ten dům je malá ||| d: 0 lm: -33.8666 w: -7 tm: -3.96541 -8.63605 -6.97174 -14.701 3.99959 ||| -5.06442 ||| 0-1=0 2=1-2 3-5=3-5 6=6
|
8
|
+
10 ||| já si myslím , že tento dům je malá ||| d: 0 lm: -36.2835 w: -9 tm: -4.37879 -7.00264 -11.7897 -17.6029 4.99948 ||| -5.07232 ||| 0=0 1=1-3 2=4 3-5=5-7 6=8
|
9
|
+
10 ||| já si myslím , že tento dům je malý ||| d: 0 lm: -37.414 w: -9 tm: -4.48335 -6.97208 -10.8782 -17.1987 4.99948 ||| -5.17712 ||| 0=0 1=1-3 2=4 3-4=5-6 5-6=7-8
|
10
|
+
10 ||| myslím , že ten dům je malý ||| d: 0 lm: -34.9971 w: -7 tm: -3.9666 -8.60549 -6.49189 -14.2969 3.99959 ||| -5.18705 ||| 0-1=0 2=1-2 3-5=3-5 6=6
|
data/test/helper.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler'
|
3
|
+
|
3
4
|
begin
|
4
5
|
Bundler.setup(:default, :development)
|
5
6
|
rescue Bundler::BundlerError => e
|
@@ -8,10 +9,62 @@ rescue Bundler::BundlerError => e
|
|
8
9
|
exit e.status_code
|
9
10
|
end
|
10
11
|
require 'test/unit'
|
12
|
+
require 'shoulda'
|
13
|
+
require 'curb'
|
11
14
|
|
12
15
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
13
16
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
17
|
require 'ajax-cat'
|
15
18
|
|
16
|
-
|
17
|
-
|
19
|
+
@moses_ini = <<-END
|
20
|
+
#########################
|
21
|
+
### MOSES CONFIG FILE ###
|
22
|
+
#########################
|
23
|
+
|
24
|
+
# input factors
|
25
|
+
[input-factors]
|
26
|
+
0
|
27
|
+
|
28
|
+
# mapping steps, either (T) translation or (G) generation
|
29
|
+
[mapping]
|
30
|
+
T 0
|
31
|
+
|
32
|
+
# translation tables: source-factors, target-factors, number of scores, file
|
33
|
+
[ttable-file]
|
34
|
+
0 0 0 1 #{Dir.pwd}/test/fixtures/phrase-table
|
35
|
+
|
36
|
+
# language models: type(srilm/irstlm/kenlm), factors, order, file
|
37
|
+
[lmodel-file]
|
38
|
+
8 0 3 #{Dir.pwd}/test/fixtures/europarl.srilm.gz
|
39
|
+
|
40
|
+
# limit on how many phrase translations e for each phrase f are loaded
|
41
|
+
[ttable-limit]
|
42
|
+
10
|
43
|
+
|
44
|
+
# distortion (reordering) weight
|
45
|
+
[weight-d]
|
46
|
+
1
|
47
|
+
|
48
|
+
# language model weights
|
49
|
+
[weight-l]
|
50
|
+
1
|
51
|
+
|
52
|
+
# translation model weights
|
53
|
+
[weight-t]
|
54
|
+
1
|
55
|
+
|
56
|
+
# word penalty
|
57
|
+
[weight-w]
|
58
|
+
0
|
59
|
+
|
60
|
+
[n-best-list]
|
61
|
+
nbest.txt
|
62
|
+
100
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
END
|
67
|
+
|
68
|
+
f = File.new(File.dirname(__FILE__) + "/fixtures/moses.ini", "w")
|
69
|
+
f.write(@moses_ini)
|
70
|
+
f.close
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module AjaxCat
|
4
|
+
|
5
|
+
class TestStartAndStop < Test::Unit::TestCase
|
6
|
+
context "run app" do
|
7
|
+
|
8
|
+
setup do
|
9
|
+
@port = 8585
|
10
|
+
@pid = fork do
|
11
|
+
Starter.start(@port, false)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
should "start server on default port 8585" do
|
16
|
+
sleep 3
|
17
|
+
result = Curl::Easy.perform("http://localhost:#{@port}/index.html")
|
18
|
+
assert_equal 200, result.response_code
|
19
|
+
end
|
20
|
+
|
21
|
+
teardown do
|
22
|
+
Process.kill 'TERM', @pid
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/test/unit/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module AjaxCat
|
4
|
+
|
5
|
+
class TestLogger < Test::Unit::TestCase
|
6
|
+
context "run app" do
|
7
|
+
|
8
|
+
setup do
|
9
|
+
@logger = Logger.new("prefix")
|
10
|
+
end
|
11
|
+
|
12
|
+
should "log message" do
|
13
|
+
res = @logger.compose_message("message")
|
14
|
+
assert (res =~ /prefix/), "not match prefix"
|
15
|
+
assert (res =~ /message/), "not match message"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module AjaxCat
|
4
|
+
|
5
|
+
class TestMosesPair < Test::Unit::TestCase
|
6
|
+
def test_moses_pair
|
7
|
+
|
8
|
+
Logger.print_log(false)
|
9
|
+
|
10
|
+
moses_ini_path = File.dirname(__FILE__) + "/../fixtures/moses.ini"
|
11
|
+
@pair = MosesPair.new('cs-en',"moses",moses_ini_path)
|
12
|
+
assert_equal(@pair.class, MosesPair, "right class")
|
13
|
+
request = Request::Raw.new("das ist")
|
14
|
+
result = @pair.process_request(request)
|
15
|
+
assert_equal(616, result.size)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
module AjaxCat
|
5
|
+
|
6
|
+
module Request
|
7
|
+
|
8
|
+
class TestRawRequest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
def test_can_read_fixture
|
11
|
+
text = File.readlines(File.dirname(__FILE__) + "/../fixtures/translation_table")[0].chop
|
12
|
+
assert_equal(text,
|
13
|
+
"10 ||| myslím , že tento dům je malá ||| d: 0 lm: -33.2059 w: -7 tm: -3.67773 -6.51247 -6.97174 -12.6506 3.99959 ||| -4.63843 ||| 0-1=0 2=1-2 3-5=3-5 6=6",
|
14
|
+
"fixture string is same"
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_parse_position
|
19
|
+
text = File.readlines(File.dirname(__FILE__) + "/../fixtures/translation_table")[0].chop
|
20
|
+
position = Raw.parse_position(text)
|
21
|
+
assert_equal(10, position, "parsing position")
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_process_line_and_get_result
|
25
|
+
|
26
|
+
request = Raw.new("");
|
27
|
+
File.new(File.dirname(__FILE__) + "/../fixtures/translation_table").each do |line|
|
28
|
+
request.process_line(line)
|
29
|
+
end
|
30
|
+
|
31
|
+
assert_equal(File.read(File.dirname(__FILE__) + "/../fixtures/translation_table"), request.result)
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
module AjaxCat
|
5
|
+
|
6
|
+
module Request
|
7
|
+
|
8
|
+
class TestSimpleRequest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
def test_process_line_and_get_result
|
11
|
+
|
12
|
+
request = Simple.new("");
|
13
|
+
File.new(File.dirname(__FILE__) + "/../fixtures/translation_table").each do |line|
|
14
|
+
request.process_line(line)
|
15
|
+
end
|
16
|
+
result = "myslím , že tento dům je malá "
|
17
|
+
assert_equal(result, request.result)
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ajax-cat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,55 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-16 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sinatra
|
16
|
+
requirement: &2177543000 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.3.2
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2177543000
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: colorize
|
27
|
+
requirement: &2177542520 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.5.8
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2177542520
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: thin
|
38
|
+
requirement: &2177542040 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.3.1
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2177542040
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: thor
|
49
|
+
requirement: &2177541540 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.15.2
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2177541540
|
14
58
|
- !ruby/object:Gem::Dependency
|
15
59
|
name: rdoc
|
16
|
-
requirement: &
|
60
|
+
requirement: &2177540920 !ruby/object:Gem::Requirement
|
17
61
|
none: false
|
18
62
|
requirements:
|
19
63
|
- - ~>
|
@@ -21,10 +65,10 @@ dependencies:
|
|
21
65
|
version: '3.12'
|
22
66
|
type: :development
|
23
67
|
prerelease: false
|
24
|
-
version_requirements: *
|
68
|
+
version_requirements: *2177540920
|
25
69
|
- !ruby/object:Gem::Dependency
|
26
70
|
name: bundler
|
27
|
-
requirement: &
|
71
|
+
requirement: &2177540320 !ruby/object:Gem::Requirement
|
28
72
|
none: false
|
29
73
|
requirements:
|
30
74
|
- - ~>
|
@@ -32,10 +76,10 @@ dependencies:
|
|
32
76
|
version: 1.0.0
|
33
77
|
type: :development
|
34
78
|
prerelease: false
|
35
|
-
version_requirements: *
|
79
|
+
version_requirements: *2177540320
|
36
80
|
- !ruby/object:Gem::Dependency
|
37
81
|
name: jeweler
|
38
|
-
requirement: &
|
82
|
+
requirement: &2177539360 !ruby/object:Gem::Requirement
|
39
83
|
none: false
|
40
84
|
requirements:
|
41
85
|
- - ~>
|
@@ -43,10 +87,33 @@ dependencies:
|
|
43
87
|
version: 1.8.3
|
44
88
|
type: :development
|
45
89
|
prerelease: false
|
46
|
-
version_requirements: *
|
90
|
+
version_requirements: *2177539360
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: shoulda
|
93
|
+
requirement: &2177538680 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ~>
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 3.0.1
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *2177538680
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: curb
|
104
|
+
requirement: &2177538200 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.8.0
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: *2177538200
|
47
113
|
description: computer-aided translation backed by machine translation
|
48
114
|
email: odchazel@gmail.com
|
49
|
-
executables:
|
115
|
+
executables:
|
116
|
+
- ajax-cat
|
50
117
|
extensions: []
|
51
118
|
extra_rdoc_files:
|
52
119
|
- LICENSE.txt
|
@@ -60,25 +127,40 @@ files:
|
|
60
127
|
- Rakefile
|
61
128
|
- VERSION
|
62
129
|
- ajax-cat.gemspec
|
130
|
+
- bin/ajax-cat
|
63
131
|
- lib/.DS_Store
|
64
132
|
- lib/ajax-cat.rb
|
65
|
-
- lib/
|
66
|
-
- lib/
|
67
|
-
- lib/
|
68
|
-
- lib/public/
|
69
|
-
- lib/public/
|
70
|
-
- lib/
|
71
|
-
- lib/
|
72
|
-
- lib/public/
|
73
|
-
- lib/public/
|
74
|
-
- lib/public/
|
75
|
-
- lib/public/
|
76
|
-
- lib/public/
|
77
|
-
- lib/public/
|
78
|
-
- lib/public/
|
79
|
-
- lib/public/
|
133
|
+
- lib/ajax-cat/ajax_cat_server.rb
|
134
|
+
- lib/ajax-cat/logger.rb
|
135
|
+
- lib/ajax-cat/moses_pair.rb
|
136
|
+
- lib/ajax-cat/public/AjaxCatList.coffee
|
137
|
+
- lib/ajax-cat/public/AjaxCatTranslation.coffee
|
138
|
+
- lib/ajax-cat/public/Suggestions.coffee
|
139
|
+
- lib/ajax-cat/public/TranslationTable.coffee
|
140
|
+
- lib/ajax-cat/public/Utils.coffee
|
141
|
+
- lib/ajax-cat/public/ajax-cat.coffee
|
142
|
+
- lib/ajax-cat/public/ajax-cat.js
|
143
|
+
- lib/ajax-cat/public/bootstrap.css
|
144
|
+
- lib/ajax-cat/public/bootstrap.js
|
145
|
+
- lib/ajax-cat/public/index.html
|
146
|
+
- lib/ajax-cat/public/index.js
|
147
|
+
- lib/ajax-cat/public/jquery.js
|
148
|
+
- lib/ajax-cat/public/style.css
|
149
|
+
- lib/ajax-cat/public/translation.html
|
150
|
+
- lib/ajax-cat/public/translation.js
|
151
|
+
- lib/ajax-cat/request/raw.rb
|
152
|
+
- lib/ajax-cat/request/simple.rb
|
153
|
+
- test/fixtures/europarl.srilm.gz
|
154
|
+
- test/fixtures/moses.ini
|
155
|
+
- test/fixtures/phrase-table
|
156
|
+
- test/fixtures/translation_table
|
80
157
|
- test/helper.rb
|
81
|
-
- test/
|
158
|
+
- test/integration/test_start_and_stop.rb
|
159
|
+
- test/unit/.DS_Store
|
160
|
+
- test/unit/test_logger.rb
|
161
|
+
- test/unit/test_moses_pair.rb
|
162
|
+
- test/unit/test_raw_request.rb
|
163
|
+
- test/unit/test_simple_request.rb
|
82
164
|
homepage: http://github.com/hypertornado/ajax-cat
|
83
165
|
licenses:
|
84
166
|
- MIT
|
@@ -94,7 +176,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
94
176
|
version: '0'
|
95
177
|
segments:
|
96
178
|
- 0
|
97
|
-
hash:
|
179
|
+
hash: -1104195367549568479
|
98
180
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
181
|
none: false
|
100
182
|
requirements:
|