rudachi 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/rudachi/config.rb +2 -26
- data/lib/rudachi/configurable.rb +3 -3
- data/lib/rudachi/file_parser.rb +2 -2
- data/lib/rudachi/option/boolean_option.rb +14 -0
- data/lib/rudachi/option/config.rb +47 -0
- data/lib/rudachi/option/string_option.rb +14 -0
- data/lib/rudachi/version.rb +1 -1
- data/lib/rudachi.rb +1 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72d5093c7585e3ffdf4792c81489924ab73d55988f7648b0249ff4c6669e5cb0
|
4
|
+
data.tar.gz: e780dc4a15c8575fc1ddee73c46923a3ea2c5d48ec175f54f6455d8b8fabb542
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71f5f9c92949085bad0cacf1fffe6c7dfe9f3cc0974ae2ef1ce14b4888d72ba44ce9f74feba1b6937743c0c8c861a8a5cd3a1525d250ee499277a03fdf8890f8
|
7
|
+
data.tar.gz: aa843e075e6cc61aa6d275bfe2fe6caf80faa6cca22c41d5ee38da0ab444e1ade89402d0f14815dcc4d16c0558347b62cfa6a79c467f011243afa92b7a22424f
|
data/README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# Rudachi
|
2
2
|
[Sudachi](https://github.com/WorksApplications/Sudachi) wrapper Gem for JRuby.
|
3
3
|
|
4
|
-
#### Text
|
4
|
+
#### For Text
|
5
5
|
```rb
|
6
6
|
Rudachi::TextParser.parse('東京都へ行く')
|
7
7
|
=> "東京都\t名詞,固有名詞,地名,一般,*,*\t東京都\nへ\t助詞,格助詞,*,*,*,*\tへ\n行く\t動詞,非自立可能,*,*,五段-カ行,終止形-一般\t行く\nEOS\n"
|
8
8
|
```
|
9
9
|
|
10
|
-
#### File
|
10
|
+
#### For File
|
11
11
|
```rb
|
12
12
|
File.open('sample.txt', 'w') { |f| f << '東京都へ行く' }
|
13
13
|
Rudachi::FileParser.parse('sample.txt')
|
data/lib/rudachi/config.rb
CHANGED
@@ -1,32 +1,8 @@
|
|
1
1
|
require 'rudachi/configurable'
|
2
|
+
require 'rudachi/option/string_option'
|
2
3
|
|
3
4
|
module Rudachi
|
4
5
|
extend Configurable
|
5
6
|
|
6
|
-
config_accessor :jar_path,
|
7
|
-
|
8
|
-
module Option
|
9
|
-
extend Configurable
|
10
|
-
|
11
|
-
# @see https://github.com/WorksApplications/Sudachi#options
|
12
|
-
config_accessor :r, default: nil
|
13
|
-
config_accessor :s, default: nil
|
14
|
-
config_accessor :p, default: '/usr/java/lib'
|
15
|
-
config_accessor :m, default: 'C'
|
16
|
-
config_accessor :o, default: nil
|
17
|
-
config_accessor :t, default: nil
|
18
|
-
config_accessor :ts, default: nil
|
19
|
-
config_accessor :a, default: nil
|
20
|
-
config_accessor :f, default: nil
|
21
|
-
config_accessor :d, default: nil
|
22
|
-
config_accessor :h, default: nil
|
23
|
-
|
24
|
-
def self.cmds(opts)
|
25
|
-
class_variables.each_with_object([]) do |name, flags|
|
26
|
-
key = name.to_s.delete('@@')
|
27
|
-
val = opts[key] || opts[key.to_sym] || class_variable_get(name) or next
|
28
|
-
flags << "-#{key}" << val.to_s
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
7
|
+
config_accessor :jar_path, klass: Option::StringOption, default: '/usr/java/lib/sudachi.jar'
|
32
8
|
end
|
data/lib/rudachi/configurable.rb
CHANGED
@@ -6,13 +6,13 @@ module Rudachi
|
|
6
6
|
|
7
7
|
private
|
8
8
|
|
9
|
-
def config_accessor(name, default:
|
9
|
+
def config_accessor(name, klass:, default:)
|
10
10
|
attr_def = <<~EOS
|
11
11
|
def self.#{name}; @@#{name}; end
|
12
|
-
def self.#{name}=(val); @@#{name} = val; end
|
12
|
+
def self.#{name}=(val); @@#{name} = #{klass}.new(val); end
|
13
13
|
EOS
|
14
14
|
module_eval(attr_def)
|
15
|
-
|
15
|
+
public_send("#{name}=", default)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
data/lib/rudachi/file_parser.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'rudachi/config'
|
1
|
+
require 'rudachi/option/config'
|
2
2
|
require 'rudachi/loader'
|
3
3
|
|
4
4
|
module Rudachi
|
@@ -11,7 +11,7 @@ module Rudachi
|
|
11
11
|
Rudachi.load!
|
12
12
|
|
13
13
|
@output = Java::ByteArrayOutputStream.new
|
14
|
-
@opts = opts
|
14
|
+
@opts = Option.new(opts)
|
15
15
|
end
|
16
16
|
|
17
17
|
def parse(path)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Rudachi
|
2
|
+
class Option
|
3
|
+
class BooleanOption < Delegator
|
4
|
+
def initialize(bool)
|
5
|
+
raise ArgumentError, 'must be `false` or `true`' unless bool.is_a?(FalseClass) || bool.is_a?(TrueClass)
|
6
|
+
@value = bool
|
7
|
+
end
|
8
|
+
|
9
|
+
def __getobj__; @value; end
|
10
|
+
def enable?; @value; end
|
11
|
+
def with_arg?; false; end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rudachi/configurable'
|
2
|
+
require 'rudachi/option/boolean_option'
|
3
|
+
require 'rudachi/option/string_option'
|
4
|
+
|
5
|
+
module Rudachi
|
6
|
+
class Option
|
7
|
+
extend Configurable
|
8
|
+
|
9
|
+
# @see https://github.com/WorksApplications/Sudachi#options
|
10
|
+
config_accessor :r, klass: StringOption, default: nil
|
11
|
+
config_accessor :s, klass: StringOption, default: nil
|
12
|
+
config_accessor :p, klass: StringOption, default: nil
|
13
|
+
config_accessor :m, klass: StringOption, default: nil
|
14
|
+
config_accessor :o, klass: StringOption, default: nil
|
15
|
+
config_accessor :a, klass: BooleanOption, default: false
|
16
|
+
config_accessor :d, klass: BooleanOption, default: false
|
17
|
+
config_accessor :t, klass: BooleanOption, default: false
|
18
|
+
config_accessor :ts, klass: BooleanOption, default: false
|
19
|
+
config_accessor :f, klass: BooleanOption, default: false
|
20
|
+
config_accessor :h, klass: BooleanOption, default: false
|
21
|
+
|
22
|
+
def self.cmds(opts=Option.new)
|
23
|
+
class_variables.each_with_object([]) do |name, flags|
|
24
|
+
key = name[2..-1].to_sym
|
25
|
+
opt = opts.get(key) { class_variable_get(name) }
|
26
|
+
next unless opt&.enable?
|
27
|
+
flags << "-#{key}"
|
28
|
+
flags << opt.to_s if opt.with_arg?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize(**hash)
|
33
|
+
@opts = hash.each_with_object({}) do |(key, val), _hash|
|
34
|
+
raise ArgumentError, %{unknown option "#{key}"} unless self.class.class_variable_defined?("@@#{key}")
|
35
|
+
begin
|
36
|
+
_hash[key.to_sym] = self.class.class_variable_get("@@#{key}").class.new(val)
|
37
|
+
rescue ArgumentError => e
|
38
|
+
raise ArgumentError, %{"#{key}" #{e.message}}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def get(key, &block)
|
44
|
+
@opts.key?(key) ? @opts[key] : block&.call
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Rudachi
|
2
|
+
class Option
|
3
|
+
class StringOption < Delegator
|
4
|
+
def initialize(str)
|
5
|
+
raise ArgumentError, 'must be `nil` or `String`' unless str.nil? || str.is_a?(String)
|
6
|
+
@value = str
|
7
|
+
end
|
8
|
+
|
9
|
+
def __getobj__; @value; end
|
10
|
+
def enable?; !!@value; end
|
11
|
+
def with_arg?; true; end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/rudachi/version.rb
CHANGED
data/lib/rudachi.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rudachi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SongCastle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Sudachi wrapper for JRuby.
|
14
14
|
email: "-"
|
@@ -23,6 +23,9 @@ files:
|
|
23
23
|
- lib/rudachi/dependencies.rb
|
24
24
|
- lib/rudachi/file_parser.rb
|
25
25
|
- lib/rudachi/loader.rb
|
26
|
+
- lib/rudachi/option/boolean_option.rb
|
27
|
+
- lib/rudachi/option/config.rb
|
28
|
+
- lib/rudachi/option/string_option.rb
|
26
29
|
- lib/rudachi/text_parser.rb
|
27
30
|
- lib/rudachi/version.rb
|
28
31
|
homepage: https://github.com/SongCastle/rudachi
|