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,147 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'langue/japanese/parser'
|
3
|
+
|
4
|
+
describe Langue::Japanese::Parser, '#initialize' do
|
5
|
+
it 'sets an empty hash to mecab_options attribute' do
|
6
|
+
parser = described_class.new
|
7
|
+
mecab_options = parser.mecab_options
|
8
|
+
mecab_options.should be_a(Hash)
|
9
|
+
mecab_options.should be_empty
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'sets an instance of Langue::Japanese::Logging::NullLogger to @logger' do
|
13
|
+
parser = described_class.new
|
14
|
+
logger = parser.instance_eval { @logger }
|
15
|
+
logger.should be_a(Langue::Japanese::Logging::NullLogger)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'sets an empty hash to @taggers' do
|
19
|
+
parser = described_class.new
|
20
|
+
taggers = parser.instance_eval { @taggers }
|
21
|
+
taggers.should be_a(Hash)
|
22
|
+
taggers.should be_empty
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with mecab_options option' do
|
26
|
+
it 'sets the value of mecab_options option to mecab_options attribute' do
|
27
|
+
parser = described_class.new(:mecab_options => {:key => 'value'})
|
28
|
+
parser.mecab_options.should == {:key => 'value'}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'with logger option' do
|
33
|
+
it 'sets the value of logger option to @logger' do
|
34
|
+
parser = described_class.new(:logger => 'logger')
|
35
|
+
logger = parser.instance_eval { @logger }
|
36
|
+
logger.should == 'logger'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe Langue::Japanese::Parser, '#parse' do
|
42
|
+
before do
|
43
|
+
tagger_stub(3)
|
44
|
+
@morphemes = described_class.new.parse('text')
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'returns an instance of Langue::Morphemes' do
|
48
|
+
@morphemes.should be_a(Langue::Morphemes)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'returns an array with the number of morpheme' do
|
52
|
+
@morphemes.should have(3).items
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'returns an array containing the contents of the morpheme' do
|
56
|
+
@morphemes[0].text.should == '1'
|
57
|
+
@morphemes[1].text.should == '2'
|
58
|
+
@morphemes[2].text.should == '3'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe Langue::Japanese::Parser, '#tagger' do
|
63
|
+
before do
|
64
|
+
@parser = described_class.new
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'calls MeCab::Tagger.new with mecab_options attribute' do
|
68
|
+
MeCab::Tagger.should_receive(:new).with('mecab_options')
|
69
|
+
@parser.stub!(:mecab_options_as_string).and_return('mecab_options')
|
70
|
+
@parser.send(:tagger)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'returns an instance of MeCab::Tagger' do
|
74
|
+
tagger = tagger_stub
|
75
|
+
@parser.send(:tagger).should == tagger
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe Langue::Japanese::Parser, '#mecab_options_as_string' do
|
80
|
+
it 'returns an empty string if it does not give options' do
|
81
|
+
parser = described_class.new
|
82
|
+
mecab_options_as_string = parser.send(:mecab_options_as_string)
|
83
|
+
mecab_options_as_string.should be_a(String)
|
84
|
+
mecab_options_as_string.should be_empty
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'with sysdic option' do
|
88
|
+
it 'returns a string included d option' do
|
89
|
+
parser = described_class.new(:mecab_options => {:sysdic => 'sysdic'})
|
90
|
+
parser.send(:mecab_options_as_string).should == '-d sysdic'
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'with userdic option' do
|
95
|
+
it 'returns a string included u option' do
|
96
|
+
parser = described_class.new(:mecab_options => {:userdic => 'userdic'})
|
97
|
+
parser.send(:mecab_options_as_string).should == '-u userdic'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'with an unsupported option' do
|
102
|
+
it 'logs that an option is unsupported' do
|
103
|
+
parser = described_class.new(:mecab_options => {:unsupported => 'value'})
|
104
|
+
|
105
|
+
parser.instance_eval { @logger }.should_receive(:post).with('langue.japanese.parser', {
|
106
|
+
:level => 'warn',
|
107
|
+
:message => "'unsupported' option is unsupported",
|
108
|
+
:key => :unsupported
|
109
|
+
})
|
110
|
+
|
111
|
+
parser.send(:mecab_options_as_string)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe Langue::Japanese::Parser, '#create_morpheme' do
|
117
|
+
before do
|
118
|
+
@parser = described_class.new
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'returns an expected morpheme' do
|
122
|
+
surface = 'surface'
|
123
|
+
feature = 'part_of_speech,category1,category2,category3,inflection,inflection_type,root_form,yomi,pronunciation'
|
124
|
+
morpheme = @parser.send(:create_morpheme, surface, feature)
|
125
|
+
morpheme.text.should == 'surface'
|
126
|
+
morpheme.part_of_speech.should == 'part_of_speech'
|
127
|
+
morpheme.categories.should == %w(category1 category2 category3)
|
128
|
+
morpheme.inflection.should == 'inflection'
|
129
|
+
morpheme.inflection_type.should == 'inflection_type'
|
130
|
+
morpheme.root_form.should == 'root_form'
|
131
|
+
morpheme.yomi.should == 'yomi'
|
132
|
+
morpheme.pronunciation.should == 'pronunciation'
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'replaces to nil from the asterisk' do
|
136
|
+
surface = 'surface'
|
137
|
+
feature = '*,*,*,*,*,*,*,*,*'
|
138
|
+
morpheme = @parser.send(:create_morpheme, surface, feature)
|
139
|
+
morpheme.part_of_speech.should be_nil
|
140
|
+
morpheme.categories.should be_empty
|
141
|
+
morpheme.inflection.should be_nil
|
142
|
+
morpheme.inflection_type.should be_nil
|
143
|
+
morpheme.root_form.should be_nil
|
144
|
+
morpheme.yomi.should be_nil
|
145
|
+
morpheme.pronunciation.should be_nil
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'langue/japanese/shaper'
|
4
|
+
|
5
|
+
describe Langue::Japanese::Shaper, '#initialize' do
|
6
|
+
it 'sets an instance of Langue::Japanese::Logging::NullLogger to @logger' do
|
7
|
+
parser = described_class.new
|
8
|
+
logger = parser.instance_eval { @logger }
|
9
|
+
logger.should be_a(Langue::Japanese::Logging::NullLogger)
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'with logger option' do
|
13
|
+
it 'sets the value of logger option to @logger' do
|
14
|
+
parser = described_class.new(:logger => 'logger')
|
15
|
+
logger = parser.instance_eval { @logger }
|
16
|
+
logger.should == 'logger'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe Langue::Japanese::Shaper, '#shape_person_name' do
|
22
|
+
it 'forms the morphemes to a person name' do
|
23
|
+
shaper = described_class.new
|
24
|
+
|
25
|
+
{
|
26
|
+
'あたしの名前は天道あかねよ' => '天道あかね',
|
27
|
+
'オレの名前は早乙女乱馬だ' => '早乙女乱馬'
|
28
|
+
}.each do |text, name|
|
29
|
+
morphemes = parser.parse(text)
|
30
|
+
morpheme = shaper.shape_person_name(morphemes, name).find { |m| m.classified?(*%w(名詞 固有名詞 人名)) }
|
31
|
+
morpheme.text.should == name
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'langue/japanese/structurer'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
describe Langue::Japanese::Structurer, '::WORD_CLASSES' do
|
6
|
+
before do
|
7
|
+
@word_classes = Langue::Japanese::Structurer::WORD_CLASSES
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'has the word classes' do
|
11
|
+
@word_classes.should == [
|
12
|
+
Langue::Japanese::Period,
|
13
|
+
Langue::Japanese::Verb,
|
14
|
+
Langue::Japanese::Adjective,
|
15
|
+
Langue::Japanese::AdjectiveNoun,
|
16
|
+
Langue::Japanese::Pronoun,
|
17
|
+
Langue::Japanese::Noun
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'has take method in all the word classes' do
|
22
|
+
@word_classes.each do |word_class|
|
23
|
+
word_class.should be_respond_to(:take)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe Langue::Japanese::Structurer, '#initialize' do
|
29
|
+
it 'sets an instance of Langue::Japanese::Logging::NullLogger to @logger' do
|
30
|
+
structurer = described_class.new
|
31
|
+
logger = structurer.instance_eval { @logger }
|
32
|
+
logger.should be_a(Langue::Japanese::Logging::NullLogger)
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'with logger option' do
|
36
|
+
it 'sets the value of logger option to @logger' do
|
37
|
+
structurer = described_class.new(:logger => 'logger')
|
38
|
+
logger = structurer.instance_eval { @logger }
|
39
|
+
logger.should == 'logger'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe Langue::Japanese::Structurer, '#structure' do
|
45
|
+
before :all do
|
46
|
+
@parser = parser
|
47
|
+
@morphemes = @parser.parse('今日は妹と一緒にお買い物してきたよ。楽しかった〜')
|
48
|
+
@word_classes = Langue::Japanese::Structurer::WORD_CLASSES
|
49
|
+
end
|
50
|
+
|
51
|
+
before do
|
52
|
+
@structurer = described_class.new
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'returns an instance of Langue::Text' do
|
56
|
+
text = @structurer.structure(@morphemes)
|
57
|
+
text.should be_a Langue::Text
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns valid text' do
|
61
|
+
text = @structurer.structure(@morphemes)
|
62
|
+
text.should be_valid
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'returns sentences in the text' do
|
66
|
+
text = @structurer.structure(@morphemes)
|
67
|
+
text.should have(2).items
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'returns words in the sentences' do
|
71
|
+
text = @structurer.structure(@morphemes)
|
72
|
+
text[0].should have(9).items
|
73
|
+
text[1].should have(2).items
|
74
|
+
end
|
75
|
+
|
76
|
+
YAML.load_file(File.join(File.dirname(__FILE__), 'data.yaml')).each do |data|
|
77
|
+
input = data['text']
|
78
|
+
sentences = data['sentences']
|
79
|
+
|
80
|
+
it "extracts expected words from #{input.size < 10 ? input : input[0..7] + '...'}" do
|
81
|
+
morphemes = @parser.parse(input)
|
82
|
+
text = @structurer.structure(morphemes)
|
83
|
+
text.should have(sentences.size).items
|
84
|
+
|
85
|
+
text.each_with_index do |sentence, index|
|
86
|
+
sentence = sentence.select { |word| !word.instance_of?(Langue::Word) }
|
87
|
+
words = sentences[index]
|
88
|
+
sentence.should have(words.size).items
|
89
|
+
|
90
|
+
words.zip(sentence).each do |pair|
|
91
|
+
pair[1].text.should == pair[0][0]
|
92
|
+
pair[1].class.name.split('::').last.should == pair[0][1]
|
93
|
+
next unless pair[0][2]
|
94
|
+
|
95
|
+
pair[0][2].each do |name, value|
|
96
|
+
if name.downcase == 'attributes'
|
97
|
+
value.each do |attribute|
|
98
|
+
pair[1].__send__("#{attribute}?").should be_true
|
99
|
+
end
|
100
|
+
else
|
101
|
+
got = pair[1].__send__(name)
|
102
|
+
|
103
|
+
if TrueClass === value
|
104
|
+
got.should be_true
|
105
|
+
elsif FalseClass === value
|
106
|
+
got.should be_false
|
107
|
+
else
|
108
|
+
got.should == value
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'langue/japanese/words/adjective_noun'
|
4
|
+
|
5
|
+
describe Langue::Japanese::AdjectiveNoun, '.take' do
|
6
|
+
after do
|
7
|
+
@pairs.each do |text, size|
|
8
|
+
morphemes = parser.parse(text)
|
9
|
+
described_class.take(morphemes, 0).should == size
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'takes an adjective noun' do
|
14
|
+
@pairs = {
|
15
|
+
'大丈夫だ' => 1,
|
16
|
+
'健康だ' => 1,
|
17
|
+
'かっこいいこと' => 0,
|
18
|
+
'会話だ' => 0,
|
19
|
+
'話すこと' => 0
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'takes an adjective noun with prefix' do
|
24
|
+
@pairs = {
|
25
|
+
'超大丈夫だ' => 2,
|
26
|
+
'反健康だ' => 2,
|
27
|
+
'超それだ' => 0,
|
28
|
+
'超若干だ' => 0,
|
29
|
+
'超可愛いこと' => 0,
|
30
|
+
'反かっこいいこと' => 0
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'takes an adjective noun with suffix' do
|
35
|
+
@pairs = {
|
36
|
+
'病気がちだ' => 2,
|
37
|
+
'犬好きだ' => 2,
|
38
|
+
'犬だ' => 0,
|
39
|
+
'それがちだ' => 0,
|
40
|
+
'若干がちだ' => 0
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'takes a successive adjective noun' do
|
45
|
+
@pairs = {
|
46
|
+
'健康大丈夫だ' => 2,
|
47
|
+
'健康大丈夫がちだ' => 2,
|
48
|
+
'健康大丈夫ラーメンだ' => 0
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'takes a complex adjective' do
|
53
|
+
@pairs = {
|
54
|
+
'超病気がちだ' => 3,
|
55
|
+
'超漆黒病気がちだ' => 4,
|
56
|
+
'反超健康大丈夫だ' => 4,
|
57
|
+
'反超健康大丈夫がちだ' => 4,
|
58
|
+
'超犬だ' => 0,
|
59
|
+
'超健康大丈夫ラーメンだ' => 0,
|
60
|
+
'精神的疾患だ' => 0
|
61
|
+
}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe Langue::Japanese::AdjectiveNoun, '#prefix' do
|
66
|
+
it 'returns the prefix' do
|
67
|
+
adjective_noun('反超病気がち').prefix.should == '反超'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe Langue::Japanese::AdjectiveNoun, '#body' do
|
72
|
+
it 'returns the text with the prefix' do
|
73
|
+
adjective_noun('反超病気がち').body.should == '病気がち'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'langue/japanese/words/adjective'
|
4
|
+
|
5
|
+
describe Langue::Japanese::Adjective, '.take' do
|
6
|
+
after do
|
7
|
+
@pairs.each do |text, size|
|
8
|
+
morphemes = parser.parse(text)
|
9
|
+
described_class.take(morphemes, 0).should == size
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'takes an adjective' do
|
14
|
+
@pairs = {
|
15
|
+
'可愛いこと' => 1,
|
16
|
+
'かっこいいこと' => 1,
|
17
|
+
'会話だ' => 0,
|
18
|
+
'話すこと' => 0
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'takes an adjective with prefix' do
|
23
|
+
@pairs = {
|
24
|
+
'くそ可愛いこと' => 2,
|
25
|
+
'くそくそかっこいいこと' => 3,
|
26
|
+
'くそ会話だ' => 0
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'takes an adjective with suffix' do
|
31
|
+
@pairs = {
|
32
|
+
'可愛いっぽいこと' => 2
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'takes a successive adjective' do
|
37
|
+
@pairs = {
|
38
|
+
'可愛がたいこと' => 2
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'takes a negative adjective' do
|
43
|
+
@pairs = {
|
44
|
+
'可愛くないこと' => 2,
|
45
|
+
'かっこよくないこと' => 2
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'takes a perfective adjective' do
|
50
|
+
@pairs = {
|
51
|
+
'可愛かったこと' => 2,
|
52
|
+
'かっこよかったこと' => 2
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'takes a complex adjective' do
|
57
|
+
@pairs = {
|
58
|
+
'くそ可愛がたくなかったこと' => 5,
|
59
|
+
'クソかっこよくないこと' => 3,
|
60
|
+
'美しくなかったこと' => 3,
|
61
|
+
'厳しいっぽくなかったこと' => 4
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'takes an adjective by other' do
|
66
|
+
@pairs = {
|
67
|
+
'可愛いでしょう' => 3
|
68
|
+
}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe Langue::Japanese::Adjective, '#key_morpheme' do
|
73
|
+
it 'returns the categorematic adjective or the noncategorematic adjective' do
|
74
|
+
{
|
75
|
+
'可愛い' => 0,
|
76
|
+
'可愛っぽい' => 0,
|
77
|
+
'可愛くない' => 0,
|
78
|
+
'可愛がたい' => 1
|
79
|
+
}.each do |text, index|
|
80
|
+
word = adjective(text)
|
81
|
+
word.key_morpheme.should == word[index]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'with an empty word' do
|
86
|
+
it 'returns nil' do
|
87
|
+
word = described_class.new
|
88
|
+
word.key_morpheme.should be_nil
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe Langue::Japanese::Adjective, '#prefix' do
|
94
|
+
it 'returns the prefix' do
|
95
|
+
adjective('くそくそ可愛っぽくない').prefix.should == 'くそくそ'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe Langue::Japanese::Adjective, '#body' do
|
100
|
+
it 'returns the text with the prefix' do
|
101
|
+
adjective('くそくそ可愛っぽくない').body.should == '可愛い'
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe Langue::Japanese::Adjective, '#negative?' do
|
106
|
+
it 'returns true if it is negative' do
|
107
|
+
adjective('可愛くない').should be_negative
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'returns false if it is not negative' do
|
111
|
+
adjective('可愛い').should_not be_negative
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe Langue::Japanese::Adjective, '#perfective?' do
|
116
|
+
it 'returns true if it is perfective' do
|
117
|
+
adjective('可愛かった').should be_perfective
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'returns false if it is not perfective' do
|
121
|
+
adjective('可愛い').should_not be_perfective
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'langue/japanese/words/noun'
|
4
|
+
|
5
|
+
describe Langue::Japanese::Noun, '.take' do
|
6
|
+
after do
|
7
|
+
@pairs.each do |text, size|
|
8
|
+
morphemes = parser.parse(text)
|
9
|
+
described_class.take(morphemes, 0).should == size
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'takes a noun' do
|
14
|
+
@pairs = {
|
15
|
+
'会話だ' => 1,
|
16
|
+
'かっこいいこと' => 0,
|
17
|
+
'話すこと' => 0,
|
18
|
+
'大丈夫だ' => 0,
|
19
|
+
'健康だ' => 0
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'takes a noun with prefix' do
|
24
|
+
@pairs = {
|
25
|
+
'超会話だ' => 2,
|
26
|
+
'超反会話だ' => 3,
|
27
|
+
'超大丈夫だ' => 0,
|
28
|
+
'反健康だ' => 0,
|
29
|
+
'超それだ' => 0,
|
30
|
+
'超若干だ' => 0,
|
31
|
+
'超可愛いこと' => 0,
|
32
|
+
'反かっこいいこと' => 0
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'takes a successive noun' do
|
37
|
+
@pairs = {
|
38
|
+
'緊急連絡網だ' => 3,
|
39
|
+
'健康大丈夫ラーメンだ' => 3,
|
40
|
+
'精神的疾患だ' => 3,
|
41
|
+
'緊急大丈夫だ' => 0
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'takes an adverbable noun' do
|
46
|
+
@pairs = {
|
47
|
+
'一挙だ' => 1,
|
48
|
+
'一挙ラーメン永年だ' => 1,
|
49
|
+
'一挙永年ラーメンだ' => 2,
|
50
|
+
'ラーメン永年だ' => 1
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'does not take noun conjunct to suru-verb' do
|
55
|
+
@pairs = {
|
56
|
+
'連絡する' => 0,
|
57
|
+
'緊急連絡する' => 0,
|
58
|
+
'緊急連絡網する' => 3
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'does not take noun if starts with special char' do
|
63
|
+
@pairs = {
|
64
|
+
'ぁ犬だ' => 0,
|
65
|
+
'ァ犬だ' => 0,
|
66
|
+
'ぃ犬だ' => 0,
|
67
|
+
'ィ犬だ' => 0,
|
68
|
+
'ぅ犬だ' => 0,
|
69
|
+
'ゥ犬だ' => 0,
|
70
|
+
'ぇ犬だ' => 0,
|
71
|
+
'ェ犬だ' => 0,
|
72
|
+
'ぉ犬だ' => 0,
|
73
|
+
'ォ犬だ' => 0,
|
74
|
+
'っ犬だ' => 0,
|
75
|
+
'ッ犬だ' => 0,
|
76
|
+
'ー犬だ' => 0
|
77
|
+
}
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'langue/japanese/words/period'
|
4
|
+
|
5
|
+
describe Langue::Japanese::Period, '.take' do
|
6
|
+
after do
|
7
|
+
@pairs.each do |text, size|
|
8
|
+
morphemes = parser.parse(text)
|
9
|
+
described_class.take(morphemes, 0).should == size
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'takes a period' do
|
14
|
+
@pairs = {
|
15
|
+
'。さて' => 1,
|
16
|
+
'…… さて' => 2,
|
17
|
+
'‥・ さて' => 2,
|
18
|
+
'、、、 さて' => 3,
|
19
|
+
'。。。 さて' => 3,
|
20
|
+
'. さて' => 1,
|
21
|
+
'... さて' => 3,
|
22
|
+
'.さて' => 1,
|
23
|
+
'..さて' => 2,
|
24
|
+
'.。.さて' => 3,
|
25
|
+
'、。さて' => 2,
|
26
|
+
'! さて' => 1,
|
27
|
+
'! さて' => 1,
|
28
|
+
'!! さて' => 2,
|
29
|
+
'!! さて' => 2,
|
30
|
+
'!! さて' => 2,
|
31
|
+
'? さて' => 1,
|
32
|
+
'? さて' => 1,
|
33
|
+
'?? さて' => 2,
|
34
|
+
'?? さて' => 2,
|
35
|
+
'!? さて' => 2,
|
36
|
+
'!? さて' => 2,
|
37
|
+
'!?! さて' => 3,
|
38
|
+
'!?!? さて' => 4,
|
39
|
+
'!??!!?! さて' => 7,
|
40
|
+
'、さて' => 0,
|
41
|
+
',さて' => 0,
|
42
|
+
', さて' => 0
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe Langue::Japanese::Period, '#exclamation?' do
|
48
|
+
it 'returns true if include exclamation mark' do
|
49
|
+
period('!').should be_exclamation
|
50
|
+
period('!').should be_exclamation
|
51
|
+
period('?!').should be_exclamation
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'returns false if do not include exclamation marks' do
|
55
|
+
period('?').should_not be_exclamation
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe Langue::Japanese::Period, '#question?' do
|
60
|
+
it 'returns true if include question mark' do
|
61
|
+
period('?').should be_question
|
62
|
+
period('?').should be_question
|
63
|
+
period('!?').should be_question
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'returns false if do not include question marks' do
|
67
|
+
period('!').should_not be_question
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'langue/japanese/words/pronoun'
|
4
|
+
|
5
|
+
describe Langue::Japanese::Pronoun, '.take' do
|
6
|
+
after do
|
7
|
+
@pairs.each do |text, size|
|
8
|
+
morphemes = parser.parse(text)
|
9
|
+
described_class.take(morphemes, 0).should == size
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'takes a pronoun' do
|
14
|
+
@pairs = {
|
15
|
+
'それだ' => 1,
|
16
|
+
'僕だ' => 1,
|
17
|
+
'それ僕だ' => 1,
|
18
|
+
'会話それだ' => 0,
|
19
|
+
'かっこいいこと' => 0,
|
20
|
+
'会話だ' => 0,
|
21
|
+
'話すこと' => 0
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|