jumanpp_ruby 0.1.1 → 0.1.2

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
  SHA1:
3
- metadata.gz: bb26d6625204f5aa03c84140c5a4dd95e5202540
4
- data.tar.gz: 7b6506c11ff80cdc83ea936541be60e96b097309
3
+ metadata.gz: 2e634bef4c9276811523e25e08bffc42752796a1
4
+ data.tar.gz: f82a6c29d6949527c48f473288dea730df12b2e9
5
5
  SHA512:
6
- metadata.gz: 9a864cdec2eeaade2c55a100b91cbf3a44284cfd6a097fbc917b48d6276241e04b352a248d32d174f06072d66d2851b24586eb8814a7d32766a871f48912c48a
7
- data.tar.gz: f8d6484d1558c5ae47ecd36b9e737c87572b850c369aa216c8b81271c09fdf9ae2f18d457d975607ad55da0b60b2ee5fca3630b4a3f79cdd13c11d9690aed9ec
6
+ metadata.gz: d393e7c62ba6ee976696a8bd07202e48fd775ad1ed36f95a8759b99bde1fbfab39f89f5149409e8a612ddd1759d4dce03c45e14698c6e83dc72b70225d8f2b9c
7
+ data.tar.gz: a2d56e0efa8373bd8f6ba1591a4e1e8b4e3f4f7c069f3ad7880b743c147248365194e031eb21413bf72c3bdb35da7438d4eca8168bb89f1b0655f37a1b833a88
@@ -6,26 +6,26 @@ module JumanppRuby
6
6
  class Juman
7
7
  require 'open3'
8
8
 
9
- def initialize(**options)
10
- @option = []
11
- @option.tap do |opt|
12
- opt << "-B #{options[:beam]}" if options[:beam]
13
- opt << '--force-single-path' if options[:force_single_path] == :true
14
- opt << '--partial' if options[:partial] == :true
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
- responses << sentent.delete('\\').delete('\"')
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.split }
28
- else responses.map { |word| word.split.first }
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
@@ -1,3 +1,3 @@
1
1
  module JumanppRuby
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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.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-01-21 00:00:00.000000000 Z
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.1
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: