llt 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +30 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +7 -0
- data/config.ru +3 -0
- data/lib/llt.rb +7 -0
- data/lib/llt/api.rb +55 -0
- data/lib/llt/version.rb +3 -0
- data/llt.gemspec +27 -0
- data/spec/lib/llt/api_spec.rb +66 -0
- data/spec/lib/llt_spec.rb +7 -0
- data/spec/spec_helper.rb +26 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2ccb32177fa1ff3b9fa5848091de6d25b216fbb9
|
4
|
+
data.tar.gz: 2ee96867590cbc182a24391b6d80281a84b2d534
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5c273d62ad5ec5a4f5a535625896557b8e89f77962979c8662ded57e2a50b53dfcfecf36b6e1daa607cb9655c02cc2d22f6ac02edaef5fd8d19a5b0e9b61c69a
|
7
|
+
data.tar.gz: c4ff43c1ac7fa98d12b97dec1b0e3d9af36ec6a0e3503fa6c2695d5f69f33954850844ddb5c35f62dd51eec71077d9237610658121db55b4c6ccff04c62ee188
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in llt-tokenizer.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem 'coveralls', require: false
|
7
|
+
|
8
|
+
gem 'llt-core', git: 'https://github.com/latin-language-toolkit/llt-core.git'
|
9
|
+
gem 'llt-constants', git: 'https://github.com/latin-language-toolkit/llt-constants.git'
|
10
|
+
gem 'llt-db_handler', git: 'https://github.com/latin-language-toolkit/llt-db_handler.git'
|
11
|
+
gem 'llt-helpers', git: 'https://github.com/latin-language-toolkit/llt-helpers.git'
|
12
|
+
gem 'llt-logger', git: 'https://github.com/latin-language-toolkit/llt-logger.git'
|
13
|
+
gem 'llt-segmenter', git: 'https://github.com/latin-language-toolkit/llt-segmenter.git'
|
14
|
+
gem 'llt-tokenizer', git: 'https://github.com/latin-language-toolkit/llt-tokenizer.git'
|
15
|
+
|
16
|
+
# Dependencies of db_handler
|
17
|
+
gem 'llt-core_extensions', git: 'https://github.com/latin-language-toolkit/llt-core_extensions.git'
|
18
|
+
gem 'llt-form_builder', git: 'https://github.com/latin-language-toolkit/llt-form_builder.git'
|
19
|
+
|
20
|
+
platform :ruby do
|
21
|
+
gem 'pg'
|
22
|
+
end
|
23
|
+
|
24
|
+
platform :jruby do
|
25
|
+
gem 'activerecord-jdbcpostgresql-adapter'
|
26
|
+
gem 'jruby-httpclient'
|
27
|
+
end
|
28
|
+
|
29
|
+
gem 'pry'
|
30
|
+
gem 'array_scanner'
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 LFDM
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# LLT
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'llt'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install llt
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/config.ru
ADDED
data/lib/llt.rb
ADDED
data/lib/llt/api.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'llt'
|
2
|
+
require 'llt/core/api'
|
3
|
+
require 'llt/segmenter/api'
|
4
|
+
require 'llt/tokenizer/api'
|
5
|
+
require 'sinatra/base'
|
6
|
+
require 'sinatra/respond_with'
|
7
|
+
|
8
|
+
class Api < Sinatra::Base
|
9
|
+
helpers LLT::Core::Api::Helpers
|
10
|
+
register Sinatra::RespondWith
|
11
|
+
|
12
|
+
get '/segtok' do
|
13
|
+
typecast_params!(params)
|
14
|
+
text = extract_text(params)
|
15
|
+
seg = LLT::Segmenter.new(params)
|
16
|
+
tok = LLT::Tokenizer.new(params)
|
17
|
+
sentences = seg.segment(text)
|
18
|
+
if sentences.any?
|
19
|
+
threads_count = (t = ENV['THREADS_FOR_LLT']) ? t.to_i : 4
|
20
|
+
threads = []
|
21
|
+
sentences.each_slice(slice_size(sentences, threads_count)) do |sliced|
|
22
|
+
threads << Thread.new do
|
23
|
+
forked_tok = tok.fork_instance
|
24
|
+
process_segtok(forked_tok) do
|
25
|
+
sliced.each do |sentence|
|
26
|
+
forked_tok.tokenize(sentence.to_s, add_to: sentence)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
threads.each(&:join)
|
32
|
+
end
|
33
|
+
|
34
|
+
respond_to do |f|
|
35
|
+
f.xml { to_xml(sentences, params) }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def slice_size(sentences, threads)
|
40
|
+
sent_size = sentences.size
|
41
|
+
size = sent_size / threads + 1
|
42
|
+
size <= 0 ? sent_size : size
|
43
|
+
end
|
44
|
+
|
45
|
+
def process_segtok(tokenizer)
|
46
|
+
if tokenizer.db.type == :prometheus
|
47
|
+
StemDatabase::Db.connection_pool.with_connection { yield }
|
48
|
+
# This should NOT be needed, the block above should solve that.
|
49
|
+
# I have no clue why the connections don't close by themselves...
|
50
|
+
StemDatabase::Db.connection.close
|
51
|
+
else
|
52
|
+
yield
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/llt/version.rb
ADDED
data/llt.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'llt/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "llt"
|
8
|
+
spec.version = LLT::VERSION
|
9
|
+
spec.authors = ["LFDM, christof, lichtr"]
|
10
|
+
spec.email = ["1986gh@gmail.com"]
|
11
|
+
spec.description = %q{LLT meta gem}
|
12
|
+
spec.summary = %q{LLT meta gem}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "simplecov", "~> 0.7"
|
25
|
+
spec.add_dependency "llt-segmenter"
|
26
|
+
spec.add_dependency "llt-tokenizer"
|
27
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
ENV['RACK_ENV'] = 'test'
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'llt/api'
|
5
|
+
require 'rack/test'
|
6
|
+
|
7
|
+
def app
|
8
|
+
Api
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "main api" do
|
12
|
+
include Rack::Test::Methods
|
13
|
+
|
14
|
+
describe '/segtok' do
|
15
|
+
context "with URI as input" do
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:text) {{text: "homo mittit. Marcus est."}}
|
19
|
+
|
20
|
+
context "with text as input" do
|
21
|
+
context "with accept header json" do
|
22
|
+
it "segtoks the given text" do
|
23
|
+
pending
|
24
|
+
get '/segtok', text,
|
25
|
+
{"HTTP_ACCEPT" => "application/json"}
|
26
|
+
last_response.should be_ok
|
27
|
+
response = last_response.body
|
28
|
+
parsed_response = JSON.parse(response)
|
29
|
+
parsed_response.should have(3).items
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "with accept header xml" do
|
34
|
+
it "segtoks the given text" do
|
35
|
+
pending
|
36
|
+
get '/segtok', text,
|
37
|
+
{"HTTP_ACCEPT" => "application/xml"}
|
38
|
+
last_response.should be_ok
|
39
|
+
body = last_response.body
|
40
|
+
body.should =~ /<w>homo<\/w>/
|
41
|
+
body.should =~ /<w>mittit<\/w>/
|
42
|
+
body.should =~ /<pc>\.<\/pc>/
|
43
|
+
end
|
44
|
+
|
45
|
+
it "receives params for tokenization and markup" do
|
46
|
+
params = {
|
47
|
+
indexing: true,
|
48
|
+
recursive: true,
|
49
|
+
inline: true,
|
50
|
+
}.merge(text)
|
51
|
+
|
52
|
+
get '/segtok', params,
|
53
|
+
{"HTTP_ACCEPT" => "application/xml"}
|
54
|
+
last_response.should be_ok
|
55
|
+
body = last_response.body
|
56
|
+
body.should =~ /<w s_n="1" n="1">homo<\/w>/
|
57
|
+
body.should =~ /<w s_n="1" n="2">mittit<\/w>/
|
58
|
+
body.should =~ /<pc s_n="1" n="3">\.<\/pc>/
|
59
|
+
body.should =~ /<w s_n="2" n="1">Marcus<\/w>/
|
60
|
+
body.should =~ /<w s_n="2" n="2">est<\/w>/
|
61
|
+
body.should =~ /<pc s_n="2" n="3">\.<\/pc>/
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'coveralls'
|
3
|
+
|
4
|
+
Coveralls.wear!
|
5
|
+
|
6
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
7
|
+
SimpleCov::Formatter::HTMLFormatter,
|
8
|
+
Coveralls::SimpleCov::Formatter
|
9
|
+
]
|
10
|
+
|
11
|
+
SimpleCov.start do
|
12
|
+
add_filter '/spec/'
|
13
|
+
end
|
14
|
+
|
15
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
16
|
+
require 'llt'
|
17
|
+
|
18
|
+
if defined?(LLT::Logger)
|
19
|
+
LLT::Logger.level = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
RSpec.configure do |config|
|
23
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
24
|
+
config.run_all_when_everything_filtered = true
|
25
|
+
config.filter_run :focus
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: llt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- LFDM, christof, lichtr
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '1.3'
|
25
|
+
prerelease: false
|
26
|
+
type: :development
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
prerelease: false
|
40
|
+
type: :development
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
prerelease: false
|
54
|
+
type: :development
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.7'
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0.7'
|
67
|
+
prerelease: false
|
68
|
+
type: :development
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: llt-segmenter
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
prerelease: false
|
82
|
+
type: :runtime
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: llt-tokenizer
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirement: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
prerelease: false
|
96
|
+
type: :runtime
|
97
|
+
description: LLT meta gem
|
98
|
+
email:
|
99
|
+
- 1986gh@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- .rspec
|
106
|
+
- .travis.yml
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- config.ru
|
112
|
+
- lib/llt.rb
|
113
|
+
- lib/llt/api.rb
|
114
|
+
- lib/llt/version.rb
|
115
|
+
- llt.gemspec
|
116
|
+
- spec/lib/llt/api_spec.rb
|
117
|
+
- spec/lib/llt_spec.rb
|
118
|
+
- spec/spec_helper.rb
|
119
|
+
homepage: ''
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.1.9
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: LLT meta gem
|
143
|
+
test_files:
|
144
|
+
- spec/lib/llt/api_spec.rb
|
145
|
+
- spec/lib/llt_spec.rb
|
146
|
+
- spec/spec_helper.rb
|