rudachi 1.0.0 → 1.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f43021bc769b0005c5d46c3abde244756712ce1419b82ae884729508aab64780
4
- data.tar.gz: 5f3b2f74e771d2b3feb8d6de4abf7d59864da6108904437c28a498f2ae6d1e98
3
+ metadata.gz: 1cd976cea8211f4f452c2cd20a3fb286828d449aa346ea54458e98ecf47819aa
4
+ data.tar.gz: 7b8b886b6dc1467d33fdd44878ce1a490c13c7aacd6a40bd80e68ddcea631801
5
5
  SHA512:
6
- metadata.gz: 38535bc9cee7b34ee2ab3219294484d30758c82b4c2a85f53cb36519700eb52d2e44f75160ba2aee24a626a7dc95c5a02774bfd10c86da18067a7d6afcd33996
7
- data.tar.gz: 289e76174d4f7053e71c2c276635ab6b2283b48c220cb498615c88605ffec6a41f3888c89a80ad728383170c5052c3dd76be81a02bef91dc38f4049b18db1c21
6
+ metadata.gz: 6c21aaea246963a585ceee7800f13013797ae16f10386c933e01d3f1709ed96a5a7bcfd0d5f0e9e0a43ba17b9be2a7d2db0ce9a82ec446673ff2cf3b48a016fa
7
+ data.tar.gz: c06e0239aa4c8bae28f9a4b60d00beb66aea07a7d85760126a2e875e539a46a6716aace54f62f3f193edee31c8e8300c34bf1b2be8908b4acc2285d366bc1b7b
data/README.md CHANGED
@@ -1,20 +1,20 @@
1
1
  # Rudachi
2
2
  [Sudachi](https://github.com/WorksApplications/Sudachi) wrapper Gem for JRuby.
3
3
 
4
- - Text base
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 base
10
+ #### For File
11
11
  ```rb
12
12
  File.open('sample.txt', 'w') { |f| f << '東京都へ行く' }
13
13
  Rudachi::FileParser.parse('sample.txt')
14
14
  => "東京都\t名詞,固有名詞,地名,一般,*,*\t東京都\nへ\t助詞,格助詞,*,*,*,*\tへ\n行く\t動詞,非自立可能,*,*,五段-カ行,終止形-一般\t行く\nEOS\n"
15
15
  ```
16
16
 
17
- - With some options
17
+ #### With [some options](https://github.com/WorksApplications/Sudachi#options)
18
18
  ```rb
19
19
  Rudachi::TextParser.new(o: 'result.txt', m: 'A').parse('東京都へ行く')
20
20
  File.read('result.txt')
@@ -28,9 +28,9 @@ File.read('result.txt')
28
28
 
29
29
  ## Installation
30
30
 
31
- 1. Install JAR and dictionary of Sudachi ([details](https://github.com/WorksApplications/Sudachi/blob/develop/docs/tutorial.md#linux-%E3%81%AE%E5%A0%B4%E5%90%88))
31
+ 1. Install JAR and dictionary of Sudachi ([Details](https://github.com/WorksApplications/Sudachi/blob/develop/docs/tutorial.md#linux-%E3%81%AE%E5%A0%B4%E5%90%88))
32
32
 
33
- - Install the Sudachi JAR file
33
+ ##### Install the Sudachi JAR file
34
34
  ```sh
35
35
  $ wget https://github.com/WorksApplications/Sudachi/releases/download/v0.5.3/sudachi-0.5.3-executable.zip
36
36
  $ unzip sudachi-0.5.3-executable.zip
@@ -38,7 +38,7 @@ $ ls sudachi-0.5.3
38
38
  LICENSE-2.0.txt README.md javax.json-1.1.jar jdartsclone-1.2.0.jar licenses sudachi-0.5.3.jar sudachi.json sudachi_fulldict.json
39
39
  ```
40
40
 
41
- - Install the Sudachi dictionary
41
+ ##### Install the Sudachi dictionary
42
42
  ```sh
43
43
  $ wget http://sudachi.s3-website-ap-northeast-1.amazonaws.com/sudachidict/sudachi-dictionary-latest-full.zip
44
44
  $ unzip -j -d sudachi-dictionary-latest-full sudachi-dictionary-latest-full.zip
@@ -51,7 +51,7 @@ LEGAL LICENSE-2.0.txt system_core.dic
51
51
 
52
52
  ```rb
53
53
  # Gemfile
54
- gem 'rudachi', git: 'https://github.com/SongCastle/rudachi.git', tag: 'v1.0.0'
54
+ gem 'rudachi'
55
55
  ```
56
56
 
57
57
  Then run `bundle install` .
@@ -59,6 +59,8 @@ Then run `bundle install` .
59
59
  3. Initialize Rudachi
60
60
 
61
61
  ```rb
62
+ require 'rudachi'
63
+
62
64
  Rudachi.configure do |config|
63
65
  config.jar_path = 'sudachi-0.5.3/sudachi-0.5.3.jar'
64
66
  end
@@ -68,11 +70,9 @@ Rudachi::Option.configure do |config|
68
70
  end
69
71
  ```
70
72
 
71
- 4. Dit it !!
73
+ 4. Did it !!
72
74
 
73
75
  ```rb
74
- require 'rudachi'
75
-
76
76
  Rudachi::TextParser.parse('こんにちは世界')
77
77
  => "こんにちは\t感動詞,一般,*,*,*,*\t今日は\n世界\t名詞,普通名詞,一般,*,*,*\t世界\nEOS\n"
78
78
  ```
@@ -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, default: '/usr/java/lib/sudachi.jar'
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
@@ -6,13 +6,12 @@ module Rudachi
6
6
 
7
7
  private
8
8
 
9
- def config_accessor(name, default: nil)
10
- attr_def = <<~EOS
9
+ def config_accessor(name, klass:, default:)
10
+ module_eval <<~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
- module_eval(attr_def)
15
- class_variable_set("@@#{name}", default)
14
+ public_send("#{name}=", default)
16
15
  end
17
16
  end
18
17
  end
@@ -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)
@@ -1,5 +1,16 @@
1
1
  module Rudachi
2
- def self.load!
3
- require 'rudachi/dependencies'
2
+ class UnavailableError < StandardError; end;
3
+
4
+ class << self
5
+ def load!
6
+ raise UnavailableError, 'jruby_required' unless jruby?
7
+ require 'rudachi/dependencies'
8
+ end
9
+
10
+ private
11
+
12
+ def jruby?
13
+ RUBY_PLATFORM == 'java'
14
+ end
4
15
  end
5
16
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Rudachi
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.1'
3
3
  end
data/lib/rudachi.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require 'rudachi/config'
2
+ require 'rudachi/option/config'
2
3
  require 'rudachi/file_parser'
3
4
  require 'rudachi/text_parser'
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.0
4
+ version: 1.1.1
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-06 00:00:00.000000000 Z
11
+ date: 2022-04-10 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