rubyrubi 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubyrubi/client.rb +4 -0
- data/lib/rubyrubi/parser/base.rb +29 -22
- data/lib/rubyrubi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b005848f15f70889efb8ea6ab3fa98105e880721
|
4
|
+
data.tar.gz: 86f9fc910744efc2d59b0a9849b472add0277ee2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 033a61ebedf61ae3f2f2fe5dd762d9a8929f7bca7e25395a9ff045bb253ac20e9abdd3c9c99b1fad04a761454306ba352149970948b6a3708fc20a95f427cc45
|
7
|
+
data.tar.gz: ee1ce99f822b8de75a6d008a58ef5d6991e02139ab3c1615331957c18d6809c0c06432946b0127c53aede60826906cb02a07f765ff08d34fb8107143377d74ef
|
data/lib/rubyrubi/client.rb
CHANGED
data/lib/rubyrubi/parser/base.rb
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
module Rubyrubi
|
2
2
|
module Parser
|
3
|
-
KANJI =
|
4
|
-
OKURI = /[\p{hiragana}\p{katakana}
|
3
|
+
KANJI = /[一-龠]+/
|
4
|
+
OKURI = /[\p{hiragana}\p{katakana}ー=〜・]+/
|
5
5
|
KOMEI = /固名商品/
|
6
6
|
|
7
|
+
def self.ruby_tag(text, ruby)
|
8
|
+
"<ruby>#{text}<rp>(</rp><rt>#{ruby}</rt><rp>)</rp></ruby>"
|
9
|
+
end
|
10
|
+
|
7
11
|
class Base
|
8
12
|
def initialize(result)
|
9
13
|
result = result.with_indifferent_access
|
10
14
|
@result = result
|
11
15
|
@original = result[:ResultSet][:ma_result][:word_list][:word]
|
12
|
-
#p @original
|
13
16
|
end
|
14
17
|
|
15
18
|
def parse()
|
@@ -20,34 +23,38 @@ module Rubyrubi
|
|
20
23
|
end
|
21
24
|
|
22
25
|
def add_rubi_and_okuri(word)
|
23
|
-
#p word
|
24
26
|
if word['feature'] && word['feature'].scan(KOMEI).size > 0
|
25
27
|
return word.clone
|
26
28
|
end
|
27
29
|
|
28
|
-
kanji = word['surface'].scan(KANJI)
|
29
|
-
|
30
|
-
|
31
|
-
return word.clone
|
32
|
-
end
|
30
|
+
kanji = word['surface'].scan(KANJI)
|
31
|
+
okuri = word['surface'].scan(OKURI)
|
32
|
+
yomi = '' + word['reading']
|
33
33
|
|
34
|
-
|
35
|
-
rubi = kanji == nil && okuri == nil ? nil
|
36
|
-
: word['reading'].gsub(Regexp.new("#{okuri}$"), '')
|
34
|
+
return word.clone if !kanji || kanji.size == 0
|
37
35
|
|
38
|
-
|
39
|
-
'kanji' =>
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
36
|
+
kanji.map.with_index do |k, i|
|
37
|
+
ret = { 'kanji' => k }
|
38
|
+
oku = okuri[i]
|
39
|
+
rubi = ''
|
40
|
+
if oku
|
41
|
+
ret.merge!({ 'okuri' => oku })
|
42
|
+
rubi = yomi.slice(0, yomi.index(oku))
|
43
|
+
yomi = yomi.slice(yomi.index(oku) + oku.length, yomi.length)
|
44
|
+
else
|
45
|
+
rubi = yomi
|
46
|
+
end
|
47
|
+
ret.merge!({ 'rubi' => rubi })
|
48
|
+
end
|
44
49
|
end
|
45
50
|
|
46
51
|
def create_markup(data)
|
47
|
-
data.map do |e, i|
|
48
|
-
if e
|
49
|
-
|
50
|
-
|
52
|
+
data.map.with_index do |e, i|
|
53
|
+
if e.class == Array
|
54
|
+
e.map do |r|
|
55
|
+
Parser.ruby_tag(r['kanji'], r['rubi']) << "#{r['okuri'] ? r['okuri'] : ''}"
|
56
|
+
end.join('')
|
57
|
+
elsif e['surface']
|
51
58
|
"#{e['surface']}"
|
52
59
|
end
|
53
60
|
end
|
data/lib/rubyrubi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyrubi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 110chang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|