rudachi 1.1.1 → 1.2.0

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: 1cd976cea8211f4f452c2cd20a3fb286828d449aa346ea54458e98ecf47819aa
4
- data.tar.gz: 7b8b886b6dc1467d33fdd44878ce1a490c13c7aacd6a40bd80e68ddcea631801
3
+ metadata.gz: 515a2588b078bce3a050c6e1c4cd115524daaf5edfb71b76024e44ca9cb1cf26
4
+ data.tar.gz: eeb369e360a30b5dc050820c0b77ce4f9e98f6f9babac3e7700009ba8d2b372f
5
5
  SHA512:
6
- metadata.gz: 6c21aaea246963a585ceee7800f13013797ae16f10386c933e01d3f1709ed96a5a7bcfd0d5f0e9e0a43ba17b9be2a7d2db0ce9a82ec446673ff2cf3b48a016fa
7
- data.tar.gz: c06e0239aa4c8bae28f9a4b60d00beb66aea07a7d85760126a2e875e539a46a6716aace54f62f3f193edee31c8e8300c34bf1b2be8908b4acc2285d366bc1b7b
6
+ metadata.gz: 989c5f7acc769e3b9304592db515f30192bdf51d1aa2ce3578b380d30a06d229cfa8f96bc818d7245adeb3b72a8fa657178796a2a08cab3addb6658236219e7d
7
+ data.tar.gz: 704c0e1053077802101e7218fae201a53a2adf44203f66ef2bf8093c3c8f4de208b06c7e905b2c54aeb3c2a009bb392f73f92181633c4417081a4675245f866f
data/README.md CHANGED
@@ -1,23 +1,29 @@
1
1
  # Rudachi
2
- [Sudachi](https://github.com/WorksApplications/Sudachi) wrapper Gem for JRuby.
2
+ JRuby wrapper for [Sudachi](https://github.com/WorksApplications/Sudachi).
3
3
 
4
- #### For Text
4
+ #### 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
- #### For File
10
+ #### File
11
11
  ```rb
12
- File.open('sample.txt', 'w') { |f| f << '東京都へ行く' }
13
- Rudachi::FileParser.parse('sample.txt')
12
+ File.open('input.txt', 'w') { |f| f << '東京都へ行く' }
13
+ Rudachi::FileParser.parse('input.txt')
14
+ => "東京都\t名詞,固有名詞,地名,一般,*,*\t東京都\nへ\t助詞,格助詞,*,*,*,*\tへ\n行く\t動詞,非自立可能,*,*,五段-カ行,終止形-一般\t行く\nEOS\n"
15
+ ```
16
+
17
+ #### IO
18
+ ```rb
19
+ Rudachi::StreamParser.parse(StringIO.new('東京都へ行く'))
14
20
  => "東京都\t名詞,固有名詞,地名,一般,*,*\t東京都\nへ\t助詞,格助詞,*,*,*,*\tへ\n行く\t動詞,非自立可能,*,*,五段-カ行,終止形-一般\t行く\nEOS\n"
15
21
  ```
16
22
 
17
23
  #### With [some options](https://github.com/WorksApplications/Sudachi#options)
18
24
  ```rb
19
- Rudachi::TextParser.new(o: 'result.txt', m: 'A').parse('東京都へ行く')
20
- File.read('result.txt')
25
+ Rudachi::TextParser.new(o: 'output.txt', m: 'A').parse('東京都へ行く')
26
+ File.read('output.txt')
21
27
  => "東京\t名詞,固有名詞,地名,一般,*,*\t東京\n都\t名詞,普通名詞,一般,*,*,*\t都\nへ\t助詞,格助詞,*,*,*,*\tへ\n行く\t動詞,非自立可能,*,*,五段-カ行,終止形-一般\t行く\nEOS\n"
22
28
  ```
23
29
 
@@ -54,7 +60,7 @@ LEGAL LICENSE-2.0.txt system_core.dic
54
60
  gem 'rudachi'
55
61
  ```
56
62
 
57
- Then run `bundle install` .
63
+ Then run `bundle install`.
58
64
 
59
65
  3. Initialize Rudachi
60
66
 
@@ -8,12 +8,13 @@ java_import 'java.nio.charset.StandardCharsets'
8
8
  require Rudachi.jar_path
9
9
  java_import 'com.worksap.nlp.sudachi.SudachiCommandLine'
10
10
 
11
- module Java
12
- String = JavaLang::String
13
- System = JavaLang::System
14
- ByteArrayInputStream = JavaIo::ByteArrayInputStream
15
- ByteArrayOutputStream = JavaIo::ByteArrayOutputStream
16
- PrintStream = JavaIo::PrintStream
17
- UTF_8 = JavaNioCharset::StandardCharsets::UTF_8
18
- SudachiCommandLine = ComWorksapNlpSudachi::SudachiCommandLine
11
+ module Rudachi
12
+ module Java
13
+ System = ::Java::JavaLang::System
14
+ ByteArrayInputStream = ::Java::JavaIo::ByteArrayInputStream
15
+ ByteArrayOutputStream = ::Java::JavaIo::ByteArrayOutputStream
16
+ PrintStream = ::Java::JavaIo::PrintStream
17
+ UTF_8 = ::Java::JavaNioCharset::StandardCharsets::UTF_8
18
+ SudachiCommandLine = ::Java::ComWorksapNlpSudachi::SudachiCommandLine
19
+ end
19
20
  end
@@ -9,30 +9,33 @@ module Rudachi
9
9
 
10
10
  def initialize(**opts)
11
11
  Rudachi.load!
12
-
13
- @output = Java::ByteArrayOutputStream.new
14
- @opts = Option.new(opts)
12
+ @opts = Option.new(opts)
15
13
  end
16
14
 
17
15
  def parse(path)
18
- take_stdout do
19
- Java::SudachiCommandLine.main(
20
- Option.cmds(@opts).push(Java::String.new(path))
21
- )
16
+ output_stream do |output|
17
+ take_stdout(output) do
18
+ Java::SudachiCommandLine.main(
19
+ Option.cmds(@opts).push(path)
20
+ )
21
+ end
22
22
  end
23
- @output.toString
24
23
  end
25
24
 
26
25
  private
27
26
 
28
- def take_stdout
27
+ def take_stdout(output)
29
28
  stdout = Java::System.out
30
- stream = Java::PrintStream.new(@output)
31
- Java::System.setOut(stream)
32
29
 
30
+ Java::System.setOut(output)
33
31
  yield
34
-
35
32
  Java::System.setOut(stdout)
36
33
  end
34
+
35
+ def output_stream
36
+ Java::ByteArrayOutputStream.new.tap do |output|
37
+ yield Java::PrintStream.new(output)
38
+ end.toString
39
+ end
37
40
  end
38
41
  end
@@ -0,0 +1,11 @@
1
+ require 'rudachi/text_parser'
2
+
3
+ module Rudachi
4
+ class StreamParser < TextParser
5
+ private
6
+
7
+ def input_stream(stream)
8
+ stream.to_inputstream
9
+ end
10
+ end
11
+ end
@@ -3,25 +3,29 @@ require 'rudachi/file_parser'
3
3
  module Rudachi
4
4
  class TextParser < FileParser
5
5
  def parse(text)
6
- @input = Java::String.new(text)
7
- take_stdin do
8
- take_stdout do
9
- Java::SudachiCommandLine.main(Option.cmds(@opts))
6
+ output_stream do |output|
7
+ take_stdin(input_stream(text)) do
8
+ take_stdout(output) do
9
+ Java::SudachiCommandLine.main(Option.cmds(@opts))
10
+ end
10
11
  end
11
12
  end
12
- @output.toString
13
13
  end
14
14
 
15
15
  private
16
16
 
17
- def take_stdin
17
+ def take_stdin(input)
18
18
  stdin = Java::System.in
19
- stream = Java::ByteArrayInputStream.new(@input.getBytes(Java::UTF_8))
20
- Java::System.setIn(stream)
21
19
 
20
+ Java::System.setIn(input)
22
21
  yield
23
-
24
22
  Java::System.setIn(stdin)
25
23
  end
24
+
25
+ def input_stream(text)
26
+ Java::ByteArrayInputStream.new(
27
+ text.to_java.getBytes(Java::UTF_8)
28
+ )
29
+ end
26
30
  end
27
31
  end
@@ -1,3 +1,3 @@
1
1
  module Rudachi
2
- VERSION = '1.1.1'
2
+ VERSION = '1.2.0'
3
3
  end
data/lib/rudachi.rb CHANGED
@@ -2,3 +2,4 @@ require 'rudachi/config'
2
2
  require 'rudachi/option/config'
3
3
  require 'rudachi/file_parser'
4
4
  require 'rudachi/text_parser'
5
+ require 'rudachi/stream_parser'
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rudachi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.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-10 00:00:00.000000000 Z
11
+ date: 2022-04-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Sudachi wrapper for JRuby.
13
+ description: A JRuby wrapper for Sudachi.
14
14
  email: "-"
15
15
  executables: []
16
16
  extensions: []
@@ -26,6 +26,7 @@ files:
26
26
  - lib/rudachi/option/boolean_option.rb
27
27
  - lib/rudachi/option/config.rb
28
28
  - lib/rudachi/option/string_option.rb
29
+ - lib/rudachi/stream_parser.rb
29
30
  - lib/rudachi/text_parser.rb
30
31
  - lib/rudachi/version.rb
31
32
  homepage: https://github.com/SongCastle/rudachi
@@ -50,5 +51,5 @@ requirements: []
50
51
  rubygems_version: 3.0.3
51
52
  signing_key:
52
53
  specification_version: 4
53
- summary: Sudachi wrapper for JRuby
54
+ summary: A JRuby wrapper for Sudachi
54
55
  test_files: []