langue-japanese 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,32 +13,31 @@ module Langue
13
13
  end
14
14
 
15
15
  def shape_person_name(morphemes, person_name)
16
- new_morphemes = Morphemes.new
17
- name_morphemes = []
18
- start_index = 0
19
- person_name_size = person_name.size
16
+ Morphemes.new.tap do |new_morphemes|
17
+ person_name_morphemes = []
18
+ start_index = 0
19
+ person_name_size = person_name.size
20
20
 
21
- morphemes.each do |morpheme|
22
- text = morpheme.text
23
- index = person_name.index(text, start_index)
21
+ morphemes.each do |morpheme|
22
+ text = morpheme.text
23
+ index = person_name.index(text, start_index)
24
24
 
25
- if index == start_index
26
- name_morphemes << morpheme
27
- start_index += text.size
25
+ if index == start_index
26
+ person_name_morphemes << morpheme
27
+ start_index += text.size
28
28
 
29
- if start_index == person_name_size
30
- new_morphemes << join_as_person_name(name_morphemes)
31
- name_morphemes.clear
29
+ if start_index == person_name_size
30
+ new_morphemes << join_as_person_name(person_name_morphemes)
31
+ person_name_morphemes.clear
32
+ start_index = 0
33
+ end
34
+ else
35
+ new_morphemes.concat(person_name_morphemes) << morpheme
36
+ person_name_morphemes.clear
32
37
  start_index = 0
33
38
  end
34
- else
35
- new_morphemes += name_morphemes + [morpheme]
36
- name_morphemes.clear
37
- start_index = 0
38
39
  end
39
40
  end
40
-
41
- new_morphemes
42
41
  end
43
42
 
44
43
  private
@@ -1,5 +1,5 @@
1
1
  module Langue
2
2
  module Japanese
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
5
5
  end
@@ -19,15 +19,18 @@ describe Langue::Japanese::Shaper, '#initialize' do
19
19
  end
20
20
 
21
21
  describe Langue::Japanese::Shaper, '#shape_person_name' do
22
- it 'forms the morphemes to a person name' do
22
+ it 'shapes the morphemes as person name' do
23
23
  shaper = described_class.new
24
24
 
25
25
  {
26
- 'あたしの名前は天道あかねよ' => '天道あかね',
27
- 'オレの名前は早乙女乱馬だ' => '早乙女乱馬'
28
- }.each do |text, name|
26
+ 'あたしの名前は天道あかねよ' => ['天道あかね', 6],
27
+ 'オレの名前は早乙女乱馬だ' => ['早乙女乱馬', 6]
28
+ }.each do |text, params|
29
+ name, size = params
29
30
  morphemes = parser.parse(text)
30
- morpheme = shaper.shape_person_name(morphemes, name).find { |m| m.classified?(*%w(名詞 固有名詞 人名)) }
31
+ shaped_morphemes = shaper.shape_person_name(morphemes, name)
32
+ shaped_morphemes.should have(size).items
33
+ morpheme = shaped_morphemes.find { |m| m.classified?(*%w(名詞 固有名詞 人名)) }
31
34
  morpheme.text.should == name
32
35
  end
33
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: langue-japanese
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: