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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
21
|
+
morphemes.each do |morpheme|
|
22
|
+
text = morpheme.text
|
23
|
+
index = person_name.index(text, start_index)
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
if index == start_index
|
26
|
+
person_name_morphemes << morpheme
|
27
|
+
start_index += text.size
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
@@ -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 '
|
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,
|
26
|
+
'あたしの名前は天道あかねよ' => ['天道あかね', 6],
|
27
|
+
'オレの名前は早乙女乱馬だ' => ['早乙女乱馬', 6]
|
28
|
+
}.each do |text, params|
|
29
|
+
name, size = params
|
29
30
|
morphemes = parser.parse(text)
|
30
|
-
|
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
|