jumanpp_ruby 0.1.1 → 0.1.2
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 +4 -4
- data/lib/jumanpp_ruby.rb +28 -12
- data/lib/jumanpp_ruby/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e634bef4c9276811523e25e08bffc42752796a1
|
4
|
+
data.tar.gz: f82a6c29d6949527c48f473288dea730df12b2e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d393e7c62ba6ee976696a8bd07202e48fd775ad1ed36f95a8759b99bde1fbfab39f89f5149409e8a612ddd1759d4dce03c45e14698c6e83dc72b70225d8f2b9c
|
7
|
+
data.tar.gz: a2d56e0efa8373bd8f6ba1591a4e1e8b4e3f4f7c069f3ad7880b743c147248365194e031eb21413bf72c3bdb35da7438d4eca8168bb89f1b0655f37a1b833a88
|
data/lib/jumanpp_ruby.rb
CHANGED
@@ -6,26 +6,26 @@ module JumanppRuby
|
|
6
6
|
class Juman
|
7
7
|
require 'open3'
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
@pipe ||= IO.popen("jumanpp #{@option.join(' ')}".strip, 'r+')
|
9
|
+
def initialize(beam: nil, force_single_path: false, partial: false)
|
10
|
+
argv = ['jumanpp']
|
11
|
+
argv << '--beam' << beam if beam
|
12
|
+
argv << '--force-single-path' if force_single_path
|
13
|
+
argv << '--partial' if partial
|
14
|
+
@pipe = IO.popen(argv, 'r+')
|
17
15
|
end
|
18
16
|
|
19
17
|
def parse(sentents)
|
20
|
-
@pipe.puts(sentents)
|
18
|
+
@pipe.puts(zh_convert(sentents))
|
21
19
|
responses = []
|
22
20
|
while sentent = @pipe.gets
|
23
|
-
|
21
|
+
a = sentent.scan(/(?:\\ |[^\s"]|"[^"]*")+/)
|
22
|
+
a.each {|i| i.sub!(/\A"(.*)"\z/, '\\1') }
|
23
|
+
responses << a
|
24
24
|
break if sentent =~ /EOS\n/
|
25
25
|
end
|
26
26
|
if block_given?
|
27
|
-
responses.each { |word| yield word
|
28
|
-
else responses.map { |word| word.
|
27
|
+
responses.each { |word| yield word }
|
28
|
+
else responses.map { |word| word.first }
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -42,5 +42,21 @@ module JumanppRuby
|
|
42
42
|
o, = Open3.capture2('jumanpp -h')
|
43
43
|
o.strip
|
44
44
|
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def zh_convert str
|
49
|
+
str.tr <<~'STR1',<<~'STR2'
|
50
|
+
ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
51
|
+
abcdefghijklmnopqrstuvwxyz
|
52
|
+
0123456789
|
53
|
+
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
|
54
|
+
STR1
|
55
|
+
ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
56
|
+
abcdefghijklmnopqrstuvwxyz
|
57
|
+
0123456789
|
58
|
+
!”#$%&’()*+,−./:;<=>?@[¥]^_`{|}〜
|
59
|
+
STR2
|
60
|
+
end
|
45
61
|
end
|
46
62
|
end
|
data/lib/jumanpp_ruby/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jumanpp_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sho ishihara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,9 +94,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
96
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.5.
|
97
|
+
rubygems_version: 2.5.2
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
100
|
summary: This gem is Ruby binding for JUMAN++
|
101
101
|
test_files: []
|
102
|
-
has_rdoc:
|