mojix 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 +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +73 -0
- data/Rakefile +15 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/example/mojix_cli.rb +16 -0
- data/lib/mojix.rb +9 -0
- data/lib/mojix/client.rb +29 -0
- data/lib/mojix/generated/tokenizer_pb.rb +25 -0
- data/lib/mojix/generated/tokenizer_services_pb.rb +22 -0
- data/lib/mojix/version.rb +3 -0
- data/mojix.gemspec +29 -0
- data/proto/tokenizer.proto +26 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b5ac989dccc7b27875eed445449774ab91f892a4
|
4
|
+
data.tar.gz: '09094f8c38ca1901e5fa2b8d2357b34d3ee75f07'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e4f81f564a885cb95540c6ed2fe2b4e750a47fbc135efb2caf9adb0f52445211369b8cd7e127c81dcafa5306c4d6ed8a911239ed0b688c22db8d3f4d6069e4d6
|
7
|
+
data.tar.gz: 71087ce0cf7bce4586abd8dfb2aebb4e7ed4acad9cc14e520526c2bf992fcb0aacacd7b11e7f23bc0c0ce8c6930e793564a6bc399259f341a528a24fba5b1dff
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 xmisao
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# Mojix
|
2
|
+
|
3
|
+
Mojix client for Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install yourself.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem install mojix
|
11
|
+
```
|
12
|
+
|
13
|
+
Or write your gemfile.
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'mojix'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute.
|
20
|
+
|
21
|
+
```sh
|
22
|
+
bundle install
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Premise
|
28
|
+
|
29
|
+
Mojix-server is running.
|
30
|
+
See [mojix-server](https://github.com/mojix-server) repo.
|
31
|
+
|
32
|
+
```sh
|
33
|
+
docker run -it --rm -p 9661:9661 xmisao/mojix
|
34
|
+
```
|
35
|
+
|
36
|
+
### Tokenize by mojix-server example
|
37
|
+
|
38
|
+
```
|
39
|
+
require 'mojix'
|
40
|
+
|
41
|
+
mojix = Mojix::Client.new(host: 'localhost', port: 9661, mode: :normal)
|
42
|
+
|
43
|
+
mojix.tokenize_simply('もう何も恐くない') #=> ["もう", "何", "も", "恐く", "ない"]
|
44
|
+
```
|
45
|
+
|
46
|
+
`Mojix::Client.new` arguments are optional.
|
47
|
+
You can omit `host`, `mode`, `mode` arguments.
|
48
|
+
|
49
|
+
```
|
50
|
+
require 'mojix'
|
51
|
+
|
52
|
+
# Client initialize by default settings.
|
53
|
+
# host: 'localhost'
|
54
|
+
# port: 9661
|
55
|
+
# mode: :normal
|
56
|
+
mojix = Mojix::Client.new
|
57
|
+
|
58
|
+
mojix.tokenize_simply('もう何も恐くない') #=> ["もう", "何", "も", "恐く", "ない"]
|
59
|
+
```
|
60
|
+
|
61
|
+
Valid `mode` arugments.
|
62
|
+
|
63
|
+
* `:normal`
|
64
|
+
* `:search`
|
65
|
+
* `:extended`
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/xmisao/mojix.
|
70
|
+
|
71
|
+
## License
|
72
|
+
|
73
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.libs << "test"
|
6
|
+
t.libs << "lib"
|
7
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Generate gRPC code'
|
11
|
+
task(:grpc) do |t|
|
12
|
+
sh 'grpc_tools_ruby_protoc -I proto --ruby_out=lib/mojix/generated --grpc_out=lib/mojix/generated proto/tokenizer.proto'
|
13
|
+
end
|
14
|
+
|
15
|
+
task :default => :test
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mojix"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'mojix'
|
2
|
+
|
3
|
+
client_normal = Mojix::Client.new(mode: :normal)
|
4
|
+
client_search = Mojix::Client.new(mode: :search)
|
5
|
+
client_extended = Mojix::Client.new(mode: :extended)
|
6
|
+
|
7
|
+
if ARGV.count == 0
|
8
|
+
STDOUT.puts 'Usage: ruby mojix_cli.rb "もう何も恐くない"'
|
9
|
+
exit
|
10
|
+
end
|
11
|
+
|
12
|
+
ARGV.each{|text|
|
13
|
+
puts ":normal => #{client_normal.tokenize_simply(text).inspect}"
|
14
|
+
puts ":search => #{client_search.tokenize_simply(text).inspect}"
|
15
|
+
puts ":extended => #{client_extended.tokenize_simply(text).inspect}"
|
16
|
+
}
|
data/lib/mojix.rb
ADDED
data/lib/mojix/client.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Mojix
|
2
|
+
class Client
|
3
|
+
def initialize(host: 'localhost', port: 9661, mode: :normal)
|
4
|
+
host_port = "#{host}:#{port}"
|
5
|
+
@stub = Tokenizer::Stub.new(host_port, :this_channel_is_insecure)
|
6
|
+
@mode = sym_to_mode(mode)
|
7
|
+
end
|
8
|
+
|
9
|
+
def tokenize_simply(text)
|
10
|
+
req = SimpleRequest.new(text: text, mode: @mode)
|
11
|
+
@stub.tokenize_simply(req).tokens
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def sym_to_mode(sym)
|
17
|
+
case sym
|
18
|
+
when :normal
|
19
|
+
SimpleRequest::Mode::NORMAL
|
20
|
+
when :search
|
21
|
+
SimpleRequest::Mode::SEARCH
|
22
|
+
when :extended
|
23
|
+
SimpleRequest::Mode::EXTENDED
|
24
|
+
else
|
25
|
+
raise ArgumentError
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# source: tokenizer.proto
|
3
|
+
|
4
|
+
require 'google/protobuf'
|
5
|
+
|
6
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
7
|
+
add_message "mojix.SimpleRequest" do
|
8
|
+
optional :text, :string, 1
|
9
|
+
optional :mode, :enum, 2, "mojix.SimpleRequest.Mode"
|
10
|
+
end
|
11
|
+
add_enum "mojix.SimpleRequest.Mode" do
|
12
|
+
value :NORMAL, 0
|
13
|
+
value :SEARCH, 1
|
14
|
+
value :EXTENDED, 2
|
15
|
+
end
|
16
|
+
add_message "mojix.SimpleResponse" do
|
17
|
+
repeated :tokens, :string, 1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module Mojix
|
22
|
+
SimpleRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("mojix.SimpleRequest").msgclass
|
23
|
+
SimpleRequest::Mode = Google::Protobuf::DescriptorPool.generated_pool.lookup("mojix.SimpleRequest.Mode").enummodule
|
24
|
+
SimpleResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("mojix.SimpleResponse").msgclass
|
25
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# Source: tokenizer.proto for package 'mojix'
|
3
|
+
|
4
|
+
require 'grpc'
|
5
|
+
require 'tokenizer_pb'
|
6
|
+
|
7
|
+
module Mojix
|
8
|
+
module Tokenizer
|
9
|
+
class Service
|
10
|
+
|
11
|
+
include GRPC::GenericService
|
12
|
+
|
13
|
+
self.marshal_class_method = :encode
|
14
|
+
self.unmarshal_class_method = :decode
|
15
|
+
self.service_name = 'mojix.Tokenizer'
|
16
|
+
|
17
|
+
rpc :tokenizeSimply, SimpleRequest, SimpleResponse
|
18
|
+
end
|
19
|
+
|
20
|
+
Stub = Service.rpc_stub_class
|
21
|
+
end
|
22
|
+
end
|
data/mojix.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "mojix/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mojix"
|
8
|
+
spec.version = Mojix::VERSION
|
9
|
+
spec.authors = ["xmisao"]
|
10
|
+
spec.email = ["mail@xmisao.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Mojix client for Ruby.}
|
13
|
+
spec.description = %q{Mojix gRPC client for Ruby. Mojix is micro-service oriented kuromoji gRPC server.}
|
14
|
+
spec.homepage = "https://github.com/xmisao/mojix-client-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
27
|
+
spec.add_development_dependency "grpc-tools", "~> 1.4.5"
|
28
|
+
spec.add_dependency "grpc", "~> 1.4.5"
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
syntax = "proto3";
|
2
|
+
|
3
|
+
option java_multiple_files = true;
|
4
|
+
option java_package = "com.xmisao.mojix.tokenizer";
|
5
|
+
option java_outer_classname = "IpadicTokenizer";
|
6
|
+
option objc_class_prefix = "IT";
|
7
|
+
|
8
|
+
package mojix;
|
9
|
+
|
10
|
+
service Tokenizer {
|
11
|
+
rpc tokenizeSimply (SimpleRequest) returns (SimpleResponse) {}
|
12
|
+
}
|
13
|
+
|
14
|
+
message SimpleRequest {
|
15
|
+
string text = 1;
|
16
|
+
enum Mode {
|
17
|
+
NORMAL = 0;
|
18
|
+
SEARCH = 1;
|
19
|
+
EXTENDED = 2;
|
20
|
+
}
|
21
|
+
Mode mode = 2;
|
22
|
+
}
|
23
|
+
|
24
|
+
message SimpleResponse {
|
25
|
+
repeated string tokens = 1;
|
26
|
+
}
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mojix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- xmisao
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: grpc-tools
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.4.5
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.4.5
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: grpc
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.4.5
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.4.5
|
83
|
+
description: Mojix gRPC client for Ruby. Mojix is micro-service oriented kuromoji
|
84
|
+
gRPC server.
|
85
|
+
email:
|
86
|
+
- mail@xmisao.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/setup
|
98
|
+
- example/mojix_cli.rb
|
99
|
+
- lib/mojix.rb
|
100
|
+
- lib/mojix/client.rb
|
101
|
+
- lib/mojix/generated/tokenizer_pb.rb
|
102
|
+
- lib/mojix/generated/tokenizer_services_pb.rb
|
103
|
+
- lib/mojix/version.rb
|
104
|
+
- mojix.gemspec
|
105
|
+
- proto/tokenizer.proto
|
106
|
+
homepage: https://github.com/xmisao/mojix-client-ruby
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.5.2
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: Mojix client for Ruby.
|
130
|
+
test_files: []
|