langue-japanese 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +6 -0
- data/LICENSE +22 -0
- data/README.md +53 -0
- data/Rakefile +2 -0
- data/langue-japanese.gemspec +22 -0
- data/lib/langue/japanese/language.rb +36 -0
- data/lib/langue/japanese/logging.rb +21 -0
- data/lib/langue/japanese/parser.rb +77 -0
- data/lib/langue/japanese/shaper.rb +70 -0
- data/lib/langue/japanese/structurer.rb +74 -0
- data/lib/langue/japanese/version.rb +5 -0
- data/lib/langue/japanese/words/adjective.rb +67 -0
- data/lib/langue/japanese/words/adjective_noun.rb +76 -0
- data/lib/langue/japanese/words/attribute.rb +100 -0
- data/lib/langue/japanese/words/classifier.rb +107 -0
- data/lib/langue/japanese/words/morpheme_filter.rb +26 -0
- data/lib/langue/japanese/words/noun.rb +61 -0
- data/lib/langue/japanese/words/period.rb +55 -0
- data/lib/langue/japanese/words/prefix.rb +19 -0
- data/lib/langue/japanese/words/pronoun.rb +16 -0
- data/lib/langue/japanese/words/verb.rb +100 -0
- data/lib/langue/japanese.rb +2 -0
- data/lib/langue-japanese.rb +1 -0
- data/spec/langue/japanese/data.yaml +169 -0
- data/spec/langue/japanese/language_spec.rb +120 -0
- data/spec/langue/japanese/parser_spec.rb +147 -0
- data/spec/langue/japanese/shaper_spec.rb +34 -0
- data/spec/langue/japanese/structurer_spec.rb +116 -0
- data/spec/langue/japanese/words/adjective_noun_spec.rb +76 -0
- data/spec/langue/japanese/words/adjective_spec.rb +123 -0
- data/spec/langue/japanese/words/noun_spec.rb +79 -0
- data/spec/langue/japanese/words/period_spec.rb +69 -0
- data/spec/langue/japanese/words/pronoun_spec.rb +24 -0
- data/spec/langue/japanese/words/verb_spec.rb +242 -0
- data/spec/langue/japanese_spec.rb +7 -0
- data/spec/spec_helper.rb +75 -0
- metadata +131 -0
@@ -0,0 +1,107 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module Langue
|
3
|
+
module Japanese
|
4
|
+
module Classifier
|
5
|
+
{
|
6
|
+
|
7
|
+
# noun
|
8
|
+
:noun => %w(名詞),
|
9
|
+
:noncategorematic_noun => %w(名詞 非自立),
|
10
|
+
:noun_conjunct_to_suru => %w(名詞 サ変接続),
|
11
|
+
:adverbable_noun => %w(名詞 副詞可能),
|
12
|
+
:adjective_stem_noun => %w(名詞 形容動詞語幹),
|
13
|
+
:pronoun => %w(名詞 代名詞),
|
14
|
+
|
15
|
+
# adjective
|
16
|
+
:categorematic_adjective => %w(形容詞 自立),
|
17
|
+
:noncategorematic_adjective => %w(形容詞 非自立),
|
18
|
+
|
19
|
+
# verb
|
20
|
+
:categorematic_verb => %w(動詞 自立),
|
21
|
+
:noncategorematic_verb => %w(動詞 非自立),
|
22
|
+
|
23
|
+
# auxiliary verb
|
24
|
+
:auxiliary_verb => %w(助動詞),
|
25
|
+
|
26
|
+
# particle
|
27
|
+
:conjunctive_particle => %w(助詞 接続助詞),
|
28
|
+
|
29
|
+
# prefix
|
30
|
+
:noun_prefix => %w(接頭詞 名詞接続),
|
31
|
+
:adjective_prefix => %w(接頭詞 形容詞接続),
|
32
|
+
:verb_prefix => %w(接頭詞 動詞接続),
|
33
|
+
|
34
|
+
# suffix
|
35
|
+
:noun_suffix => %w(名詞 接尾),
|
36
|
+
:adjective_stem_suffix => %w(名詞 接尾 形容動詞語幹),
|
37
|
+
:adjective_suffix => %w(形容詞 接尾),
|
38
|
+
:verb_suffix => %w(動詞 接尾),
|
39
|
+
|
40
|
+
# symbol
|
41
|
+
:symbol => %w(記号),
|
42
|
+
:alphabet => %w(記号 アルファベット)
|
43
|
+
|
44
|
+
}.each do |category, categories|
|
45
|
+
define_method("#{category}?") do |morphemes, index|
|
46
|
+
morphemes.at(index) { |m| m.classified?(*categories) }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def first_noun?(morphemes, index)
|
51
|
+
noun?(morphemes, index) &&
|
52
|
+
!pronoun?(morphemes, index) &&
|
53
|
+
!adverbable_noun?(morphemes, index) &&
|
54
|
+
!noun_suffix?(morphemes, index) &&
|
55
|
+
!noncategorematic_noun?(morphemes, index)
|
56
|
+
end
|
57
|
+
|
58
|
+
def first_verb?(morphemes, index)
|
59
|
+
categorematic_verb?(morphemes, index) && morphemes.at(index) do |m|
|
60
|
+
!%w(する なる 思う おもう).include?(m.root_form)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def first_adjective?(morphemes, index)
|
65
|
+
categorematic_adjective?(morphemes, index)
|
66
|
+
end
|
67
|
+
|
68
|
+
def following_noun?(morphemes, index)
|
69
|
+
noun?(morphemes, index) &&
|
70
|
+
!pronoun?(morphemes, index) &&
|
71
|
+
!adverbable_noun?(morphemes, index)
|
72
|
+
end
|
73
|
+
|
74
|
+
def following_adjective?(morphemes, index)
|
75
|
+
(noncategorematic_adjective?(morphemes, index) || adjective_suffix?(morphemes, index)) ||
|
76
|
+
auxiliary_verb?(morphemes, index)
|
77
|
+
end
|
78
|
+
|
79
|
+
def following_verb?(morphemes, index)
|
80
|
+
(noncategorematic_verb?(morphemes, index) || verb_suffix?(morphemes, index)) ||
|
81
|
+
auxiliary_verb?(morphemes, index)
|
82
|
+
end
|
83
|
+
|
84
|
+
def following_symbol?(morphemes, index)
|
85
|
+
alphabet?(morphemes, index)
|
86
|
+
end
|
87
|
+
|
88
|
+
def suru_verb?(morphemes, index)
|
89
|
+
categorematic_verb?(morphemes, index) && morphemes.at(index) { |m| m.inflected?('サ変・スル') }
|
90
|
+
end
|
91
|
+
|
92
|
+
def body_verb?(morphemes, index)
|
93
|
+
categorematic_verb?(morphemes, index) || noncategorematic_verb?(morphemes, index) && !progressive_verb?(morphemes, index)
|
94
|
+
end
|
95
|
+
|
96
|
+
def progressive_verb?(morphemes, index)
|
97
|
+
noncategorematic_verb?(morphemes, index) && morphemes.at(index) do |m|
|
98
|
+
%w(いる てる でる とる どる ちゃう じゃう).include?(m.root_form)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def body_adjective?(morphemes, index)
|
103
|
+
categorematic_adjective?(morphemes, index) || noncategorematic_adjective?(morphemes, index)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Langue
|
2
|
+
module Japanese
|
3
|
+
module MorphemeFilter
|
4
|
+
def self.included(object)
|
5
|
+
return if object.respond_to?(:filter)
|
6
|
+
|
7
|
+
object.class_eval do
|
8
|
+
def body_morphemes
|
9
|
+
@body_morphemes ||= self.class.filters.inject(self) { |morphemes, filter| filter[self, morphemes] }
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def filters
|
14
|
+
@filters ||= []
|
15
|
+
end
|
16
|
+
|
17
|
+
def filter(&filter)
|
18
|
+
remove_instance_variable(:@body_morphemes) if instance_variable_defined?(:@body_morphemes)
|
19
|
+
filters << filter
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'langue/word'
|
3
|
+
require 'langue/japanese/words/classifier'
|
4
|
+
|
5
|
+
module Langue
|
6
|
+
module Japanese
|
7
|
+
class Noun < Word
|
8
|
+
INHIBITED_FIRST_CHARS = %w(ぁ ァ ぃ ィ ぅ ゥ ぇ ェ ぉ ォ っ ッ ー)
|
9
|
+
INHIBITED_LAST_CHARS = %w()
|
10
|
+
|
11
|
+
class << self
|
12
|
+
include Classifier
|
13
|
+
|
14
|
+
def take(morphemes, index)
|
15
|
+
if first_noun?(morphemes, index)
|
16
|
+
take_noun(morphemes, index)
|
17
|
+
elsif noun_prefix?(morphemes, index)
|
18
|
+
take_noun_with_prefix(morphemes, index)
|
19
|
+
elsif adverbable_noun?(morphemes, index)
|
20
|
+
take_adverbable_noun(morphemes, index)
|
21
|
+
else
|
22
|
+
0
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def take_noun(morphemes, index)
|
27
|
+
return 0 unless first_noun?(morphemes, index)
|
28
|
+
all = adjective_stem_noun?(morphemes, index)
|
29
|
+
size = 1
|
30
|
+
|
31
|
+
while following_noun?(morphemes, index + size) || following_symbol?(morphemes, index + size)
|
32
|
+
all &&= adjective_stem_noun?(morphemes, index + size)
|
33
|
+
size += 1
|
34
|
+
end
|
35
|
+
|
36
|
+
return 0 if all
|
37
|
+
return 0 if noun_conjunct_to_suru?(morphemes, index + size - 1) && suru_verb?(morphemes, index + size)
|
38
|
+
first_char = morphemes[index].text[0]
|
39
|
+
last_char = morphemes[index + size - 1].text[-1]
|
40
|
+
return 0 if INHIBITED_FIRST_CHARS.include?(first_char)
|
41
|
+
return 0 if INHIBITED_LAST_CHARS.include?(last_char)
|
42
|
+
size
|
43
|
+
end
|
44
|
+
|
45
|
+
def take_noun_with_prefix(morphemes, index)
|
46
|
+
size = 0
|
47
|
+
size += 1 while noun_prefix?(morphemes, index + size)
|
48
|
+
return 0 unless size > 0
|
49
|
+
next_size = take_noun(morphemes, index + size)
|
50
|
+
next_size > 0 ? size + next_size : 0
|
51
|
+
end
|
52
|
+
|
53
|
+
def take_adverbable_noun(morphemes, index)
|
54
|
+
size = 0
|
55
|
+
size += 1 while adverbable_noun?(morphemes, index + size)
|
56
|
+
size
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'langue/word'
|
3
|
+
require 'langue/japanese/words/classifier'
|
4
|
+
|
5
|
+
module Langue
|
6
|
+
module Japanese
|
7
|
+
class Period < Word
|
8
|
+
COMMAS = %w(, , 、)
|
9
|
+
DOTS = COMMAS + %w(. . 。 ・ ‥ …)
|
10
|
+
MARKS = %w(! ! ? ?)
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def take(morphemes, index)
|
14
|
+
if dot?(morphemes, index)
|
15
|
+
take_dot(morphemes, index)
|
16
|
+
elsif mark?(morphemes, index)
|
17
|
+
take_mark(morphemes, index)
|
18
|
+
else
|
19
|
+
0
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def dot?(morphemes, index)
|
24
|
+
morphemes.at(index) { |m| DOTS.include?(m.text) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def mark?(morphemes, index)
|
28
|
+
morphemes.at(index) { |m| MARKS.include?(m.text) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def take_dot(morphemes, index)
|
32
|
+
size = 0
|
33
|
+
size += 1 while dot?(morphemes, index + size)
|
34
|
+
size == 1 && COMMAS.include?(morphemes[index].text) ? 0 : size
|
35
|
+
end
|
36
|
+
|
37
|
+
def take_mark(morphemes, index)
|
38
|
+
size = 0
|
39
|
+
size += 1 while mark?(morphemes, index + size)
|
40
|
+
size
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def exclamation?
|
45
|
+
@exclamation = !!(text =~ /[!!]/) unless instance_variable_defined?(:@exclamation)
|
46
|
+
@exclamation
|
47
|
+
end
|
48
|
+
|
49
|
+
def question?
|
50
|
+
@question = !!(text =~ /[??]/) unless instance_variable_defined?(:@question)
|
51
|
+
@question
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'langue/japanese/words/morpheme_filter'
|
2
|
+
|
3
|
+
module Langue
|
4
|
+
module Japanese
|
5
|
+
module Prefix
|
6
|
+
def self.included(object)
|
7
|
+
object.class_eval do
|
8
|
+
include MorphemeFilter
|
9
|
+
filter { |word, morphemes| morphemes[word.prefix_morphemes.size..-1] }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def prefix
|
14
|
+
@prefix = prefix_morphemes.map(&:text).join unless instance_variable_defined?(:@prefix)
|
15
|
+
@prefix
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'langue/japanese/words/noun'
|
2
|
+
require 'langue/japanese/words/classifier'
|
3
|
+
|
4
|
+
module Langue
|
5
|
+
module Japanese
|
6
|
+
class Pronoun < Noun
|
7
|
+
class << self
|
8
|
+
include Classifier
|
9
|
+
|
10
|
+
def take(morphemes, index)
|
11
|
+
pronoun?(morphemes, index) ? 1 : 0
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'langue/word'
|
2
|
+
require 'langue/japanese/words/prefix'
|
3
|
+
require 'langue/japanese/words/attribute'
|
4
|
+
require 'langue/japanese/words/classifier'
|
5
|
+
|
6
|
+
module Langue
|
7
|
+
module Japanese
|
8
|
+
class Verb < Word
|
9
|
+
include Prefix
|
10
|
+
include Attribute
|
11
|
+
|
12
|
+
has :progressive, :passive, :aggressive, :negative, :perfective, :imperative
|
13
|
+
|
14
|
+
class << self
|
15
|
+
include Classifier
|
16
|
+
|
17
|
+
def take(morphemes, index)
|
18
|
+
if first_verb?(morphemes, index)
|
19
|
+
take_verb(morphemes, index)
|
20
|
+
elsif verb_prefix?(morphemes, index)
|
21
|
+
take_verb_with_prefix(morphemes, index)
|
22
|
+
elsif first_noun?(morphemes, index)
|
23
|
+
take_noun_conjunct_to_suru(morphemes, index)
|
24
|
+
elsif noun_prefix?(morphemes, index)
|
25
|
+
take_noun_with_prefix_conjunct_to_suru(morphemes, index)
|
26
|
+
else
|
27
|
+
0
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def take_verb(morphemes, index)
|
32
|
+
return 0 unless first_verb?(morphemes, index)
|
33
|
+
take_following_verb(morphemes, index)
|
34
|
+
end
|
35
|
+
|
36
|
+
def take_verb_with_prefix(morphemes, index)
|
37
|
+
size = 0
|
38
|
+
size += 1 while verb_prefix?(morphemes, index + size)
|
39
|
+
return 0 unless size > 0
|
40
|
+
next_size = take_verb(morphemes, index + size)
|
41
|
+
next_size > 0 ? size + next_size : 0
|
42
|
+
end
|
43
|
+
|
44
|
+
def take_noun_conjunct_to_suru(morphemes, index)
|
45
|
+
size = 0
|
46
|
+
size += 1 while following_noun?(morphemes, index + size)
|
47
|
+
return 0 unless size > 0
|
48
|
+
return 0 unless noun_conjunct_to_suru?(morphemes, index + size - 1)
|
49
|
+
return 0 unless suru_verb?(morphemes, index + size)
|
50
|
+
size + take_following_verb(morphemes, index + size)
|
51
|
+
end
|
52
|
+
|
53
|
+
def take_noun_with_prefix_conjunct_to_suru(morphemes, index)
|
54
|
+
size = 0
|
55
|
+
size += 1 while noun_prefix?(morphemes, index + size)
|
56
|
+
return 0 unless size > 0
|
57
|
+
next_size = take_noun_conjunct_to_suru(morphemes, index + size)
|
58
|
+
next_size > 0 ? size + next_size : 0
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def take_following_verb(morphemes, index)
|
64
|
+
size = 1
|
65
|
+
size += 1 while following_verb?(morphemes, index + size) || conjunctive_particle?(morphemes, index + size) && following_verb?(morphemes, index + size + 1)
|
66
|
+
size += 1 while auxiliary_verb?(morphemes, index + size)
|
67
|
+
size
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def key_morpheme
|
72
|
+
unless instance_variable_defined?(:@key_morpheme)
|
73
|
+
@key_morpheme = if empty?
|
74
|
+
nil
|
75
|
+
else
|
76
|
+
index = size - 1
|
77
|
+
index -= 1 while !self.class.body_verb?(morphemes, index)
|
78
|
+
self[index]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
@key_morpheme
|
83
|
+
end
|
84
|
+
|
85
|
+
def prefix_morphemes
|
86
|
+
@prefix_morphemes ||= begin
|
87
|
+
size = 0
|
88
|
+
|
89
|
+
if self.class.verb_prefix?(morphemes, size)
|
90
|
+
size += 1 while self.class.verb_prefix?(morphemes, size)
|
91
|
+
elsif self.class.noun_prefix?(morphemes, size)
|
92
|
+
size += 1 while self.class.noun_prefix?(morphemes, size)
|
93
|
+
end
|
94
|
+
|
95
|
+
morphemes[0, size]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'langue/japanese'
|
@@ -0,0 +1,169 @@
|
|
1
|
+
-
|
2
|
+
text: 今日は妹と一緒にお買い物してきたよ。楽しかった〜
|
3
|
+
sentences:
|
4
|
+
-
|
5
|
+
- [今日, Noun]
|
6
|
+
- [妹, Noun]
|
7
|
+
- [一緒, Noun]
|
8
|
+
- - お買い物してきた
|
9
|
+
- Verb
|
10
|
+
- body: 買い物してくる
|
11
|
+
prefix: お
|
12
|
+
attributes: [perfective]
|
13
|
+
- [。, Period]
|
14
|
+
-
|
15
|
+
- - 楽しかった
|
16
|
+
- Adjective
|
17
|
+
- body: 楽しい
|
18
|
+
attributes: [perfective]
|
19
|
+
|
20
|
+
-
|
21
|
+
text: 例の女子会が延期になってちょっとホッとしている
|
22
|
+
sentences:
|
23
|
+
-
|
24
|
+
- [例, Noun]
|
25
|
+
- [女子会, Noun]
|
26
|
+
- [延期, Noun]
|
27
|
+
|
28
|
+
-
|
29
|
+
text: こんなに部屋が寒くてはインターネットもままならぬ
|
30
|
+
sentences:
|
31
|
+
-
|
32
|
+
- [部屋, Noun]
|
33
|
+
- - 寒く
|
34
|
+
- Adjective
|
35
|
+
- body: 寒い
|
36
|
+
- [インターネット, Noun]
|
37
|
+
|
38
|
+
-
|
39
|
+
text: 牛乳って意外と甘い?
|
40
|
+
sentences:
|
41
|
+
-
|
42
|
+
- [牛乳, Noun]
|
43
|
+
- - 甘い
|
44
|
+
- Adjective
|
45
|
+
- body: 甘い
|
46
|
+
- [?, Period]
|
47
|
+
|
48
|
+
-
|
49
|
+
text: むしろ精神的疾患とは……
|
50
|
+
sentences:
|
51
|
+
-
|
52
|
+
- [精神的疾患, Noun]
|
53
|
+
- [……, Period]
|
54
|
+
|
55
|
+
-
|
56
|
+
text: 情報系大学生なら卒業までに応用情報レベルの知識を習っていると思うのだけども.
|
57
|
+
sentences:
|
58
|
+
-
|
59
|
+
- [情報系大学生, Noun]
|
60
|
+
- [卒業, Noun]
|
61
|
+
- [応用情報レベル, Noun]
|
62
|
+
- [知識, Noun]
|
63
|
+
- - 習っている
|
64
|
+
- Verb
|
65
|
+
- body: 習う
|
66
|
+
attributes: [progressive]
|
67
|
+
- [., Period]
|
68
|
+
|
69
|
+
-
|
70
|
+
text: プログラマーの資格を持つ息子が面接に全て落ちました。理系でも旧帝じゃないとダメなのでしょうか?
|
71
|
+
sentences:
|
72
|
+
-
|
73
|
+
- [プログラマー, Noun]
|
74
|
+
- [資格, Noun]
|
75
|
+
- - 持つ
|
76
|
+
- Verb
|
77
|
+
- body: 持つ
|
78
|
+
- [息子, Noun]
|
79
|
+
- [面接, Noun]
|
80
|
+
- [全て, Noun]
|
81
|
+
- - 落ちました
|
82
|
+
- Verb
|
83
|
+
- body: 落ちる
|
84
|
+
attributes: [perfective]
|
85
|
+
- [。, Period]
|
86
|
+
-
|
87
|
+
- [理系, Noun]
|
88
|
+
- [旧帝, Noun]
|
89
|
+
- [ダメ, AdjectiveNoun]
|
90
|
+
- [?, Period]
|
91
|
+
|
92
|
+
-
|
93
|
+
text: ちゃんと病院いこうね…。はい…。
|
94
|
+
sentences:
|
95
|
+
-
|
96
|
+
- [病院, Noun]
|
97
|
+
- - いこう
|
98
|
+
- Verb
|
99
|
+
- body: いく
|
100
|
+
- […。, Period]
|
101
|
+
-
|
102
|
+
- […。, Period]
|
103
|
+
|
104
|
+
-
|
105
|
+
text: んー、お昼がスープパスタだけとか。。。あふんあふん。。。後で絶対お腹すくなー。でも今あんま食べる気しにゃい。。。
|
106
|
+
sentences:
|
107
|
+
-
|
108
|
+
- [お昼, Noun]
|
109
|
+
- [スープパスタ, Noun]
|
110
|
+
- [。。。, Period]
|
111
|
+
-
|
112
|
+
- [あふん, Verb]
|
113
|
+
- [。。。, Period]
|
114
|
+
-
|
115
|
+
- [絶対, Noun]
|
116
|
+
- [お腹, Noun]
|
117
|
+
- - すく
|
118
|
+
- Adjective
|
119
|
+
- body: すい
|
120
|
+
- [。, Period]
|
121
|
+
-
|
122
|
+
- [今あんま, Noun]
|
123
|
+
- - 食べる
|
124
|
+
- Verb
|
125
|
+
- body: 食べる
|
126
|
+
- [しにゃい, Verb]
|
127
|
+
- [。。。, Period]
|
128
|
+
|
129
|
+
-
|
130
|
+
text: iPhone 4Sにただで替えられるって聞いたけど、本当に使うかは疑問なので……
|
131
|
+
sentences:
|
132
|
+
-
|
133
|
+
- [iphone4s, Noun]
|
134
|
+
- [ただ, Noun]
|
135
|
+
- - 替えられる
|
136
|
+
- Verb
|
137
|
+
- body: 替える
|
138
|
+
attributes: [passive]
|
139
|
+
- - 聞いた
|
140
|
+
- Verb
|
141
|
+
- body: 聞く
|
142
|
+
attributes: [perfective]
|
143
|
+
- - 使う
|
144
|
+
- Verb
|
145
|
+
- body: 使う
|
146
|
+
- [疑問, Noun]
|
147
|
+
- [……, Period]
|
148
|
+
|
149
|
+
-
|
150
|
+
text: 俺のためにご奉仕しろ!
|
151
|
+
sentences:
|
152
|
+
-
|
153
|
+
- [俺, Pronoun]
|
154
|
+
- - ご奉仕しろ
|
155
|
+
- Verb
|
156
|
+
- body: 奉仕する
|
157
|
+
prefix: ご
|
158
|
+
attributes: [imperative]
|
159
|
+
- [!, Period]
|
160
|
+
|
161
|
+
-
|
162
|
+
text: 風と共に去らぬ
|
163
|
+
sentences:
|
164
|
+
-
|
165
|
+
- [風, Noun]
|
166
|
+
- - 去らぬ
|
167
|
+
- Verb
|
168
|
+
- body: 去る
|
169
|
+
attributes: [negative]
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'langue/japanese/language'
|
3
|
+
|
4
|
+
describe Langue::Japanese::Language do
|
5
|
+
it 'is an instance of Class' do
|
6
|
+
described_class.should be_an_instance_of(Class)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'extends Langue::Language' do
|
10
|
+
described_class.superclass.should == Langue::Language
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe Langue::Japanese::Language, '#parser' do
|
15
|
+
before do
|
16
|
+
@language = described_class.new(:key => 'value')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'calls Langue::Japanese::Parser.new with the options' do
|
20
|
+
parser_stub
|
21
|
+
Langue::Japanese::Parser.should_receive(:new).with(:key => 'value')
|
22
|
+
@language.parser
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'returns an instance of Langue::Japanese::Parser' do
|
26
|
+
parser = parser_stub
|
27
|
+
@language.parser.should == parser
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe Langue::Japanese::Language, '#shaper' do
|
32
|
+
before do
|
33
|
+
@language = described_class.new(:key => 'value')
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'calls Langue::Japanese::Shaper.new with the options' do
|
37
|
+
shaper_stub
|
38
|
+
Langue::Japanese::Shaper.should_receive(:new).with(:key => 'value')
|
39
|
+
@language.shaper
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns an instance of Langue::Japanese::Shaper' do
|
43
|
+
shaper = shaper_stub
|
44
|
+
@language.shaper.should == shaper
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe Langue::Japanese::Language, '#structurer' do
|
49
|
+
before do
|
50
|
+
@language = described_class.new(:key => 'value')
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'calls Langue::Japanese::Structurer.new with the options' do
|
54
|
+
structurer_stub
|
55
|
+
Langue::Japanese::Structurer.should_receive(:new).with(:key => 'value')
|
56
|
+
@language.structurer
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'returns an instance of Langue::Japanese::Structurer' do
|
60
|
+
structurer = structurer_stub
|
61
|
+
@language.structurer.should == structurer
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe Langue::Japanese::Language, '#parse' do
|
66
|
+
before do
|
67
|
+
@language = described_class.new(:key => 'value')
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'calls parse method of parser with a text' do
|
71
|
+
parser_stub do |m|
|
72
|
+
m.should_receive(:parse).with('text')
|
73
|
+
end
|
74
|
+
|
75
|
+
@language.parse('text')
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'returns the value returning from Langue::Japanese::Parser#parse' do
|
79
|
+
parser_stub
|
80
|
+
@language.parse('text').should == 'value returning from parse method'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe Langue::Japanese::Language, '#shape_person_name' do
|
85
|
+
before do
|
86
|
+
@language = described_class.new(:key => 'value')
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'calls shape_person_name method of shaper with morphemes' do
|
90
|
+
shaper_stub do |m|
|
91
|
+
m.should_receive(:shape_person_name).with('morphemes', 'Akane')
|
92
|
+
end
|
93
|
+
|
94
|
+
@language.shape_person_name('morphemes', 'Akane')
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'returns the value returning from Langue::Japanese::Shaper#shape_person_name' do
|
98
|
+
shaper_stub
|
99
|
+
@language.shape_person_name('morphemes', 'Akane').should == 'value returning from shape_person_name method'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe Langue::Japanese::Language, '#structure' do
|
104
|
+
before do
|
105
|
+
@language = described_class.new(:key => 'value')
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'calls structure method of structurer with morphemes' do
|
109
|
+
structurer_stub do |m|
|
110
|
+
m.should_receive(:structure).with('morphemes')
|
111
|
+
end
|
112
|
+
|
113
|
+
@language.structure('morphemes')
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'returns the value returning from Langue::Japanese::Structurer#structure' do
|
117
|
+
structurer_stub
|
118
|
+
@language.structure('morphemes').should == 'value returning from structure method'
|
119
|
+
end
|
120
|
+
end
|