rudachi 1.2.0 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 515a2588b078bce3a050c6e1c4cd115524daaf5edfb71b76024e44ca9cb1cf26
4
- data.tar.gz: eeb369e360a30b5dc050820c0b77ce4f9e98f6f9babac3e7700009ba8d2b372f
3
+ metadata.gz: b2a7d72805e33fa5e12884193bf931d6bdf7ce16d6f9243022c7fcedad8c2f23
4
+ data.tar.gz: '0050952b57a66b96a89ed7cebf5dc51caed87a2437cf9c4dc494b62578f90f20'
5
5
  SHA512:
6
- metadata.gz: 989c5f7acc769e3b9304592db515f30192bdf51d1aa2ce3578b380d30a06d229cfa8f96bc818d7245adeb3b72a8fa657178796a2a08cab3addb6658236219e7d
7
- data.tar.gz: 704c0e1053077802101e7218fae201a53a2adf44203f66ef2bf8093c3c8f4de208b06c7e905b2c54aeb3c2a009bb392f73f92181633c4417081a4675245f866f
6
+ metadata.gz: a1a1799c8bcda90ec099a44fedc81f2c2018cd1fec7fbbf1065b1dcde5282ff0d427702b3f5276679adac88ebcf27cd6370f987ebb5aa751d660b96392b91c86
7
+ data.tar.gz: e25716b5b9b2483bb5c3433482d0b655ddb2eee944d18d1b9fdacca409aa26a8faf20ad350d478fffcbfe0f9761e867208e81a3396749b6f189195e35e4d1f03
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Rudachi
2
- JRuby wrapper for [Sudachi](https://github.com/WorksApplications/Sudachi).
2
+ Ruby wrapper for [Sudachi](https://github.com/WorksApplications/Sudachi).
3
3
 
4
4
  #### Text
5
5
  ```rb
@@ -29,7 +29,13 @@ File.read('output.txt')
29
29
 
30
30
  ## Requirements
31
31
 
32
- - [JRuby](https://github.com/jruby/jruby) 9.1.3.0 or later
32
+ #### Ruby
33
+ - Ruby 2.3.0 or newer
34
+ - [rjb](https://github.com/arton/rjb) 1.1.1 or newer
35
+ - [Sudachi](https://github.com/WorksApplications/Sudachi)
36
+
37
+ #### JRuby
38
+ - [JRuby](https://github.com/jruby/jruby) 9.1.3.0 or newer
33
39
  - [Sudachi](https://github.com/WorksApplications/Sudachi)
34
40
 
35
41
  ## Installation
@@ -1,20 +1,42 @@
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
+ def parse(io)
31
+ output_stream do |output|
32
+ take_stdin(io.to_inputstream) do
33
+ take_stdout(output) do
34
+ Java::SudachiCommandLine.main(Option.cmds(@opts))
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ LazyLoad.run_load_hooks(:stream_processor)
41
+ end
20
42
  end
@@ -0,0 +1,37 @@
1
+ require 'rjb'
2
+ require 'rudachi/lazy_load'
3
+
4
+ Rjb::load(Rudachi.jar_path.to_s)
5
+
6
+ module Rudachi
7
+ module Java
8
+ String = Rjb::import('java.lang.String')
9
+ System = Rjb::import('java.lang.System')
10
+ PrintStream = Rjb::import('java.io.PrintStream')
11
+ ByteArrayInputStream = Rjb::import('java.io.ByteArrayInputStream')
12
+ ByteArrayOutputStream = Rjb::import('java.io.ByteArrayOutputStream')
13
+ UTF_8 = Rjb::import('java.nio.charset.StandardCharsets').UTF_8
14
+ SudachiCommandLine = Rjb::import('com.worksap.nlp.sudachi.SudachiCommandLine')
15
+ end
16
+
17
+ module StreamProcessor
18
+ class InvalidInclusion < StandardError; end
19
+
20
+ TERM = ?\n
21
+
22
+ def self.included(base)
23
+ raise InvalidInclusion unless base.ancestors.include?(TextParser)
24
+ end
25
+
26
+ def parse(io)
27
+ ret = []
28
+ while data = io.gets
29
+ ret << super(data).strip
30
+ end
31
+
32
+ ret.join(TERM)
33
+ end
34
+
35
+ LazyLoad.run_load_hooks(:stream_processor)
36
+ end
37
+ end
@@ -9,7 +9,7 @@ module Rudachi
9
9
 
10
10
  def initialize(**opts)
11
11
  Rudachi.load!
12
- @opts = Option.new(opts)
12
+ @opts = Option.new(**opts)
13
13
  end
14
14
 
15
15
  def parse(path)
@@ -0,0 +1,16 @@
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)
12
+ @@hooks[name]&.each(&:call)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,14 +1,13 @@
1
1
  module Rudachi
2
- class UnavailableError < StandardError; end;
3
-
4
2
  class << self
5
3
  def load!
6
- raise UnavailableError, 'jruby_required' unless jruby?
7
- require 'rudachi/dependencies'
4
+ if jruby?
5
+ require 'rudachi/dependencies/jruby'
6
+ else
7
+ require 'rudachi/dependencies/ruby'
8
+ end
8
9
  end
9
10
 
10
- private
11
-
12
11
  def jruby?
13
12
  RUBY_PLATFORM == 'java'
14
13
  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
7
+ include StreamProcessor
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.3.0'
3
3
  end
metadata CHANGED
@@ -1,16 +1,30 @@
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.3.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-12 00:00:00.000000000 Z
12
- dependencies: []
13
- description: A JRuby wrapper for Sudachi.
11
+ date: 2022-04-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rjb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.1
27
+ description: A Ruby wrapper for Sudachi.
14
28
  email: "-"
15
29
  executables: []
16
30
  extensions: []
@@ -20,8 +34,10 @@ files:
20
34
  - lib/rudachi.rb
21
35
  - lib/rudachi/config.rb
22
36
  - lib/rudachi/configurable.rb
23
- - lib/rudachi/dependencies.rb
37
+ - lib/rudachi/dependencies/jruby.rb
38
+ - lib/rudachi/dependencies/ruby.rb
24
39
  - lib/rudachi/file_parser.rb
40
+ - lib/rudachi/lazy_load.rb
25
41
  - lib/rudachi/loader.rb
26
42
  - lib/rudachi/option/boolean_option.rb
27
43
  - lib/rudachi/option/config.rb
@@ -51,5 +67,5 @@ requirements: []
51
67
  rubygems_version: 3.0.3
52
68
  signing_key:
53
69
  specification_version: 4
54
- summary: A JRuby wrapper for Sudachi
70
+ summary: A Ruby wrapper for Sudachi
55
71
  test_files: []