rudachi 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -2
- data/lib/rudachi/{dependencies.rb → dependencies/jruby.rb} +25 -3
- data/lib/rudachi/dependencies/ruby.rb +37 -0
- data/lib/rudachi/file_parser.rb +1 -1
- data/lib/rudachi/lazy_load.rb +16 -0
- data/lib/rudachi/loader.rb +5 -6
- data/lib/rudachi/stream_parser.rb +3 -4
- data/lib/rudachi/text_parser.rb +1 -1
- data/lib/rudachi/version.rb +1 -1
- metadata +22 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2a7d72805e33fa5e12884193bf931d6bdf7ce16d6f9243022c7fcedad8c2f23
|
4
|
+
data.tar.gz: '0050952b57a66b96a89ed7cebf5dc51caed87a2437cf9c4dc494b62578f90f20'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1a1799c8bcda90ec099a44fedc81f2c2018cd1fec7fbbf1065b1dcde5282ff0d427702b3f5276679adac88ebcf27cd6370f987ebb5aa751d660b96392b91c86
|
7
|
+
data.tar.gz: e25716b5b9b2483bb5c3433482d0b655ddb2eee944d18d1b9fdacca409aa26a8faf20ad350d478fffcbfe0f9761e867208e81a3396749b6f189195e35e4d1f03
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Rudachi
|
2
|
-
|
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
|
-
|
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
|
data/lib/rudachi/file_parser.rb
CHANGED
data/lib/rudachi/loader.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
module Rudachi
|
2
|
-
class UnavailableError < StandardError; end;
|
3
|
-
|
4
2
|
class << self
|
5
3
|
def load!
|
6
|
-
|
7
|
-
|
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
|
-
|
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
|
data/lib/rudachi/text_parser.rb
CHANGED
data/lib/rudachi/version.rb
CHANGED
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.
|
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
|
-
dependencies:
|
13
|
-
|
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
|
70
|
+
summary: A Ruby wrapper for Sudachi
|
55
71
|
test_files: []
|