rudachi 1.2.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 515a2588b078bce3a050c6e1c4cd115524daaf5edfb71b76024e44ca9cb1cf26
4
- data.tar.gz: eeb369e360a30b5dc050820c0b77ce4f9e98f6f9babac3e7700009ba8d2b372f
3
+ metadata.gz: 8665dde657a8011fe19b9232db227e1394500c39247fcb831ba1f4909a9f1993
4
+ data.tar.gz: a98385a7e9dd44fab7902314df579774b590c77a23964098ad1ec7dc1c9fa085
5
5
  SHA512:
6
- metadata.gz: 989c5f7acc769e3b9304592db515f30192bdf51d1aa2ce3578b380d30a06d229cfa8f96bc818d7245adeb3b72a8fa657178796a2a08cab3addb6658236219e7d
7
- data.tar.gz: 704c0e1053077802101e7218fae201a53a2adf44203f66ef2bf8093c3c8f4de208b06c7e905b2c54aeb3c2a009bb392f73f92181633c4417081a4675245f866f
6
+ metadata.gz: 59418d27a0ee99486685b934d3844e4d9bff691d7b745a2d81d9d50a3dcef721e1a683a3544ad54e8e3800fe8d10942a57244b7ae6d63ea25c0731caab4a33ee
7
+ data.tar.gz: 03b93983ef097c1ec2c96b26ebd802947d2dd0d3a6a4f5615f58f8dcd604147bd7b5f3bf227eff523e71c8b7c1ebe8ba1fa3ef52b6a2981068614b1d072f6aa4
data/README.md CHANGED
@@ -32,6 +32,8 @@ File.read('output.txt')
32
32
  - [JRuby](https://github.com/jruby/jruby) 9.1.3.0 or later
33
33
  - [Sudachi](https://github.com/WorksApplications/Sudachi)
34
34
 
35
+ For Ruby, please check [rudachi-rb](https://github.com/SongCastle/rudachi-rb).
36
+
35
37
  ## Installation
36
38
 
37
39
  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))
@@ -11,7 +11,7 @@ module Rudachi
11
11
  def self.#{name}; @@#{name}; end
12
12
  def self.#{name}=(val); @@#{name} = #{klass}.new(val); end
13
13
  EOS
14
- public_send("#{name}=", default)
14
+ send("#{name}=", default)
15
15
  end
16
16
  end
17
17
  end
@@ -1,20 +1,38 @@
1
1
  require 'java'
2
+ require 'rudachi/lazy_load'
3
+ require Rudachi.jar_path
4
+
2
5
  java_import 'java.lang.System'
3
6
  java_import 'java.io.PrintStream'
4
7
  java_import 'java.io.ByteArrayInputStream'
5
8
  java_import 'java.io.ByteArrayOutputStream'
6
9
  java_import 'java.nio.charset.StandardCharsets'
7
-
8
- require Rudachi.jar_path
9
10
  java_import 'com.worksap.nlp.sudachi.SudachiCommandLine'
10
11
 
11
12
  module Rudachi
12
13
  module Java
14
+ String = ::Java::JavaLang::String
13
15
  System = ::Java::JavaLang::System
16
+ PrintStream = ::Java::JavaIo::PrintStream
14
17
  ByteArrayInputStream = ::Java::JavaIo::ByteArrayInputStream
15
18
  ByteArrayOutputStream = ::Java::JavaIo::ByteArrayOutputStream
16
- PrintStream = ::Java::JavaIo::PrintStream
17
19
  UTF_8 = ::Java::JavaNioCharset::StandardCharsets::UTF_8
18
20
  SudachiCommandLine = ::Java::ComWorksapNlpSudachi::SudachiCommandLine
19
21
  end
22
+
23
+ module StreamProcessor
24
+ class InvalidInclusion < StandardError; end
25
+
26
+ def self.included(base)
27
+ raise InvalidInclusion unless base.ancestors.include?(TextParser)
28
+ end
29
+
30
+ private
31
+
32
+ def input_stream(io)
33
+ io.to_inputstream
34
+ end
35
+
36
+ LazyLoad.run_load_hooks(:stream_processor, self)
37
+ end
20
38
  end
@@ -8,8 +8,8 @@ module Rudachi
8
8
  end
9
9
 
10
10
  def initialize(**opts)
11
- Rudachi.load!
12
- @opts = Option.new(opts)
11
+ Rudachi::Loader.load!
12
+ @opts = Option.new(**opts)
13
13
  end
14
14
 
15
15
  def parse(path)
@@ -0,0 +1,18 @@
1
+ module Rudachi
2
+ module LazyLoad
3
+ @@hooks = {}
4
+
5
+ class << self
6
+ def on_load(name, &block)
7
+ @@hooks[name] ||= []
8
+ @@hooks[name] << block
9
+ end
10
+
11
+ def run_load_hooks(name, mod)
12
+ @@hooks[name]&.each do |hook|
13
+ hook.call(mod)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,16 +1,18 @@
1
1
  module Rudachi
2
- class UnavailableError < StandardError; end;
2
+ module Loader
3
+ class UnavailableError < StandardError; end;
3
4
 
4
- class << self
5
- def load!
6
- raise UnavailableError, 'jruby_required' unless jruby?
7
- require 'rudachi/dependencies'
8
- end
5
+ class << self
6
+ def load!
7
+ raise UnavailableError, 'jruby_required' unless jruby?
8
+ require 'rudachi/dependencies'
9
+ end
9
10
 
10
- private
11
+ private
11
12
 
12
- def jruby?
13
- RUBY_PLATFORM == 'java'
13
+ def jruby?
14
+ RUBY_PLATFORM == 'java'
15
+ end
14
16
  end
15
17
  end
16
18
  end
@@ -1,3 +1,5 @@
1
+ require 'delegate'
2
+
1
3
  module Rudachi
2
4
  class Option
3
5
  class BooleanOption < Delegator
@@ -7,8 +9,8 @@ module Rudachi
7
9
  end
8
10
 
9
11
  def __getobj__; @value; end
10
- def enable?; @value; end
11
- def with_arg?; false; end
12
+ def enable? ; @value; end
13
+ def with_arg? ; false ; end
12
14
  end
13
15
  end
14
16
  end
@@ -1,3 +1,5 @@
1
+ require 'delegate'
2
+
1
3
  module Rudachi
2
4
  class Option
3
5
  class StringOption < Delegator
@@ -6,9 +8,9 @@ module Rudachi
6
8
  @value = str
7
9
  end
8
10
 
9
- def __getobj__; @value; end
10
- def enable?; !!@value; end
11
- def with_arg?; true; end
11
+ def __getobj__; @value ; end
12
+ def enable? ; !!@value; end
13
+ def with_arg? ; true ; end
12
14
  end
13
15
  end
14
16
  end
@@ -1,11 +1,10 @@
1
+ require 'rudachi/lazy_load'
1
2
  require 'rudachi/text_parser'
2
3
 
3
4
  module Rudachi
4
5
  class StreamParser < TextParser
5
- private
6
-
7
- def input_stream(stream)
8
- stream.to_inputstream
6
+ LazyLoad.on_load(:stream_processor) do |mod|
7
+ include mod
9
8
  end
10
9
  end
11
10
  end
@@ -24,7 +24,7 @@ module Rudachi
24
24
 
25
25
  def input_stream(text)
26
26
  Java::ByteArrayInputStream.new(
27
- text.to_java.getBytes(Java::UTF_8)
27
+ Java::String.new(text).getBytes(Java::UTF_8)
28
28
  )
29
29
  end
30
30
  end
@@ -1,3 +1,3 @@
1
1
  module Rudachi
2
- VERSION = '1.2.0'
2
+ VERSION = '1.4.1'
3
3
  end
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.2.0
4
+ version: 1.4.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-12 00:00:00.000000000 Z
11
+ date: 2022-05-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A JRuby wrapper for Sudachi.
14
14
  email: "-"
@@ -22,6 +22,7 @@ files:
22
22
  - lib/rudachi/configurable.rb
23
23
  - lib/rudachi/dependencies.rb
24
24
  - lib/rudachi/file_parser.rb
25
+ - lib/rudachi/lazy_load.rb
25
26
  - lib/rudachi/loader.rb
26
27
  - lib/rudachi/option/boolean_option.rb
27
28
  - lib/rudachi/option/config.rb