mecab-light 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -1
- data/lib/mecab/light/morpheme.rb +10 -2
- data/lib/mecab/light/result.rb +22 -1
- data/lib/mecab/light/version.rb +1 -1
- data/spec/mecab-light-morpheme_spec.rb +68 -16
- data/spec/mecab-light-result_spec.rb +120 -35
- data/spec/mecab-light-tagger_spec.rb +54 -32
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef459849c0f6ac5aa5ec3b00f9d9cb1ccf50a571
|
4
|
+
data.tar.gz: 406118e6f6ea6c5f8e313f0738632d2d92160eb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1364dc10881cb2752311e0872d2edfffe3cd5cc5e84a9070fce6b444afd19f08d76a6ff19cc26b00266de98045758e55dc009f0fb9e774bebbda2189f6abfecf
|
7
|
+
data.tar.gz: c028bc9e01968a4861ef74128e4b6210494a8574b24ee68d5f13f51ba86b4c9f104ba04901ac2174077ca2d34ca4a77fdb841f7031ab8f5aef5408885e177c12
|
data/.travis.yml
CHANGED
data/lib/mecab/light/morpheme.rb
CHANGED
@@ -2,9 +2,17 @@ module MeCab
|
|
2
2
|
module Light
|
3
3
|
class Morpheme
|
4
4
|
def initialize(line)
|
5
|
-
@
|
5
|
+
@to_s = line.chomp
|
6
|
+
@surface, @feature = @to_s.split(/\t/)
|
7
|
+
end
|
8
|
+
|
9
|
+
alias to_s_orig to_s
|
10
|
+
private :to_s_orig
|
11
|
+
attr_reader :surface, :feature, :to_s
|
12
|
+
|
13
|
+
def inspect
|
14
|
+
to_s_orig.sub(/>$/, " #{@to_s}>")
|
6
15
|
end
|
7
|
-
attr_reader :surface, :feature
|
8
16
|
end
|
9
17
|
end
|
10
18
|
end
|
data/lib/mecab/light/result.rb
CHANGED
@@ -4,15 +4,30 @@ module MeCab
|
|
4
4
|
include Enumerable
|
5
5
|
|
6
6
|
def initialize(parsed)
|
7
|
+
@to_s = parsed
|
7
8
|
@morphemes = parsed.each_line.map { |line| Morpheme.new(line) }
|
8
9
|
end
|
9
10
|
|
11
|
+
def to_one_line
|
12
|
+
@morphemes.map do |morpheme|
|
13
|
+
morpheme.surface
|
14
|
+
end.join(' ')
|
15
|
+
end
|
16
|
+
|
17
|
+
alias to_s_orig to_s
|
18
|
+
private :to_one_line, :to_s_orig
|
19
|
+
attr_reader :to_s
|
20
|
+
|
21
|
+
def inspect
|
22
|
+
to_s_orig.sub(/>$/, " #{to_one_line}>")
|
23
|
+
end
|
24
|
+
|
10
25
|
def each(&block)
|
11
26
|
if block_given?
|
12
27
|
@morphemes.each(&block)
|
13
28
|
self
|
14
29
|
else
|
15
|
-
self.to_enum
|
30
|
+
self.to_enum { @morphemes.size }
|
16
31
|
end
|
17
32
|
end
|
18
33
|
|
@@ -21,6 +36,12 @@ module MeCab
|
|
21
36
|
end
|
22
37
|
|
23
38
|
alias at []
|
39
|
+
|
40
|
+
def size
|
41
|
+
@morphemes.size
|
42
|
+
end
|
43
|
+
|
44
|
+
alias length size
|
24
45
|
end
|
25
46
|
end
|
26
47
|
end
|
data/lib/mecab/light/version.rb
CHANGED
@@ -1,29 +1,81 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe MeCab::Light::Morpheme do
|
4
|
-
|
4
|
+
describe :new do
|
5
|
+
subject { new }
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
let :new do
|
8
|
+
MeCab::Light::Morpheme.new(line)
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
context 'with "surface\tfeature\n"' do
|
12
|
+
let :line do
|
13
|
+
"surface\tfeature\n"
|
14
|
+
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
+
specify do
|
17
|
+
expect(subject).to respond_to(:surface).with(0).arguments
|
18
|
+
end
|
16
19
|
|
17
|
-
|
18
|
-
|
20
|
+
specify do
|
21
|
+
expect(subject).to respond_to(:feature).with(0).arguments
|
22
|
+
end
|
23
|
+
|
24
|
+
describe :surface do
|
25
|
+
subject { new.surface }
|
26
|
+
|
27
|
+
specify do
|
28
|
+
expect(subject).to eq('surface')
|
29
|
+
end
|
30
|
+
|
31
|
+
describe :encoding do
|
32
|
+
subject { new.surface.encoding }
|
33
|
+
|
34
|
+
specify do
|
35
|
+
expect(subject).to eq(Encoding::UTF_8)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe :feature do
|
41
|
+
subject { new.feature }
|
42
|
+
|
43
|
+
specify do
|
44
|
+
expect(subject).to eq('feature')
|
45
|
+
end
|
46
|
+
|
47
|
+
describe :encoding do
|
48
|
+
subject { new.feature.encoding }
|
49
|
+
|
50
|
+
specify do
|
51
|
+
expect(subject).to eq(Encoding::UTF_8)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe :to_s do
|
57
|
+
subject { new.to_s }
|
58
|
+
|
59
|
+
specify do
|
60
|
+
expect(subject).to eq("surface\tfeature")
|
61
|
+
end
|
62
|
+
|
63
|
+
describe :encoding do
|
64
|
+
subject { new.to_s.encoding }
|
65
|
+
|
66
|
+
specify do
|
67
|
+
expect(subject).to eq(Encoding::UTF_8)
|
68
|
+
end
|
69
|
+
end
|
19
70
|
end
|
20
|
-
end
|
21
71
|
|
22
|
-
|
23
|
-
|
72
|
+
describe :inspect do
|
73
|
+
subject { new.inspect }
|
24
74
|
|
25
|
-
|
26
|
-
|
75
|
+
specify do
|
76
|
+
pattern = /^#<MeCab::Light::Morpheme:\w+ surface\tfeature>$/
|
77
|
+
expect(subject).to match(pattern)
|
78
|
+
end
|
27
79
|
end
|
28
80
|
end
|
29
81
|
end
|
@@ -1,61 +1,146 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe MeCab::Light::Result do
|
4
|
-
let(:morpheme) { double('MeCab::Light::Morpheme') }
|
5
|
-
let(:result) { MeCab::Light::Result.new("surface\tfeature\n") }
|
6
4
|
before do
|
7
5
|
MeCab::Light::Morpheme.stub(:new).and_return(morpheme)
|
8
6
|
end
|
9
7
|
|
10
|
-
|
11
|
-
|
8
|
+
let :morpheme do
|
9
|
+
double(MeCab::Light::Morpheme,
|
10
|
+
surface: 'surface',
|
11
|
+
feature: 'feature')
|
12
|
+
end
|
13
|
+
|
14
|
+
describe :new do
|
15
|
+
subject { new }
|
16
|
+
|
17
|
+
let :new do
|
18
|
+
MeCab::Light::Result.new(parsed)
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with "surface\tfeature\n"' do
|
22
|
+
let :parsed do
|
23
|
+
"surface\tfeature\n"
|
24
|
+
end
|
25
|
+
|
26
|
+
specify do
|
27
|
+
expect(subject).to respond_to(:each).with(0).arguments
|
28
|
+
end
|
29
|
+
|
30
|
+
specify do
|
31
|
+
expect(subject).to be_an(Enumerable)
|
32
|
+
end
|
33
|
+
|
34
|
+
describe :each do
|
35
|
+
subject { new.each(&block) }
|
12
36
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
37
|
+
context 'with block' do
|
38
|
+
let :block do
|
39
|
+
lambda { |morpheme| }
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should return self' do
|
43
|
+
expect(subject).to eq(new)
|
44
|
+
end
|
45
|
+
|
46
|
+
specify do
|
47
|
+
expect { |b| new.each(&b) }.to yield_control
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should yield with args(MeCab::Light::Morpheme)' do
|
51
|
+
expect { |b| new.each(&b) }.to yield_with_args(morpheme)
|
52
|
+
end
|
17
53
|
end
|
18
54
|
|
19
|
-
|
20
|
-
|
55
|
+
context 'without block' do
|
56
|
+
let :block do
|
57
|
+
nil
|
58
|
+
end
|
59
|
+
|
60
|
+
specify do
|
61
|
+
expect(subject).to be_an_instance_of(Enumerator)
|
62
|
+
end
|
63
|
+
|
64
|
+
describe :size do
|
65
|
+
subject { new.each.size }
|
66
|
+
|
67
|
+
specify do
|
68
|
+
expect(subject).to eq(1)
|
69
|
+
end
|
70
|
+
end
|
21
71
|
end
|
22
72
|
end
|
23
|
-
end
|
24
|
-
end
|
25
73
|
|
26
|
-
|
27
|
-
|
28
|
-
it { expect(result).to be_an(Enumerable) }
|
74
|
+
describe :count do
|
75
|
+
subject { new.count }
|
29
76
|
|
30
|
-
|
31
|
-
|
32
|
-
|
77
|
+
specify do
|
78
|
+
expect(subject).to eq(1)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe :size do
|
83
|
+
subject { new.size }
|
33
84
|
|
34
|
-
|
35
|
-
|
36
|
-
it 'should return self' do
|
37
|
-
expect(result.each{}).to eq(result)
|
85
|
+
specify do
|
86
|
+
expect(subject).to eq(1)
|
38
87
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
88
|
+
end
|
89
|
+
|
90
|
+
describe :length do
|
91
|
+
subject { new.length }
|
92
|
+
|
93
|
+
specify do
|
94
|
+
expect(subject).to eq(1)
|
42
95
|
end
|
43
96
|
end
|
44
97
|
|
45
|
-
|
46
|
-
|
98
|
+
describe :[] do
|
99
|
+
subject { new[nth] }
|
100
|
+
|
101
|
+
context 'with 0' do
|
102
|
+
let :nth do
|
103
|
+
0
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should be an instance of Morpheme' do
|
107
|
+
expect(subject).to eq(morpheme)
|
108
|
+
end
|
109
|
+
end
|
47
110
|
end
|
48
|
-
end
|
49
111
|
|
50
|
-
|
51
|
-
|
52
|
-
|
112
|
+
describe :at do
|
113
|
+
subject { new.at(nth) }
|
114
|
+
|
115
|
+
context 'with 0' do
|
116
|
+
let :nth do
|
117
|
+
0
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should be an instance of Morpheme' do
|
121
|
+
expect(subject).to eq(morpheme)
|
122
|
+
end
|
123
|
+
end
|
53
124
|
end
|
54
|
-
end
|
55
125
|
|
56
|
-
|
57
|
-
|
58
|
-
|
126
|
+
describe :inspect do
|
127
|
+
subject { new.inspect }
|
128
|
+
|
129
|
+
specify do
|
130
|
+
expect(subject).to match(/^#<MeCab::Light::Result:\w+ surface>$/)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe MeCab::Light::Morpheme do
|
135
|
+
subject { MeCab::Light::Morpheme }
|
136
|
+
|
137
|
+
before do
|
138
|
+
new
|
139
|
+
end
|
140
|
+
|
141
|
+
specify do
|
142
|
+
expect(subject).to have_received(:new).with("surface\tfeature\n")
|
143
|
+
end
|
59
144
|
end
|
60
145
|
end
|
61
146
|
end
|
@@ -1,57 +1,79 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe MeCab::Light::Tagger do
|
4
|
-
let(:binding) { double( parse_to_s: "surface\tfeature\nEOS\n" ) }
|
5
|
-
let(:result) { double('MeCab::Light::Result') }
|
6
|
-
let(:tagger) { MeCab::Light::Tagger.new }
|
7
4
|
before do
|
8
5
|
MeCab::Light::Binding.stub(:new).and_return(binding)
|
9
6
|
MeCab::Light::Result.stub(:new).and_return(result)
|
10
7
|
end
|
11
8
|
|
12
|
-
|
13
|
-
|
9
|
+
let :binding do
|
10
|
+
double(MeCab::Light::Binding,
|
11
|
+
parse_to_s: "surface\tfeature\nEOS\n")
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
MeCab::Light::Tagger.new
|
19
|
-
end
|
14
|
+
let :result do
|
15
|
+
double(MeCab::Light::Result)
|
16
|
+
end
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
describe :new do
|
19
|
+
subject { new }
|
20
|
+
|
21
|
+
let :new do
|
22
|
+
MeCab::Light::Tagger.new
|
25
23
|
end
|
26
|
-
end
|
27
24
|
|
28
|
-
|
29
|
-
|
25
|
+
specify do
|
26
|
+
expect(subject).to respond_to(:parse).with(1).argument
|
27
|
+
end
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
expect(tagger.parse('surface')).to eq(result)
|
34
|
-
end
|
29
|
+
describe :parse do
|
30
|
+
subject { new.parse(string) }
|
35
31
|
|
36
|
-
context '
|
37
|
-
|
38
|
-
|
32
|
+
context 'with "surface"' do
|
33
|
+
let :string do
|
34
|
+
'surface'
|
39
35
|
end
|
40
36
|
|
41
|
-
it 'should
|
42
|
-
expect(
|
37
|
+
it 'should be an instance of MeCab::Light::Result' do
|
38
|
+
expect(subject).to eq(result)
|
43
39
|
end
|
44
|
-
end
|
45
40
|
|
46
|
-
|
47
|
-
|
48
|
-
|
41
|
+
describe MeCab::Light::Result do
|
42
|
+
subject { MeCab::Light::Result }
|
43
|
+
|
44
|
+
before do
|
45
|
+
new.parse(string)
|
46
|
+
end
|
47
|
+
|
48
|
+
specify do
|
49
|
+
expect(subject).to have_received(:new).with("surface\tfeature\n")
|
50
|
+
end
|
49
51
|
end
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
+
describe 'an instance of', MeCab::Light::Binding do
|
54
|
+
subject { binding }
|
55
|
+
|
56
|
+
before do
|
57
|
+
new.parse(string)
|
58
|
+
end
|
59
|
+
|
60
|
+
specify do
|
61
|
+
expect(subject).to have_received(:parse_to_s).with('surface')
|
62
|
+
end
|
53
63
|
end
|
54
64
|
end
|
55
65
|
end
|
66
|
+
|
67
|
+
describe MeCab::Light::Binding do
|
68
|
+
subject { MeCab::Light::Binding }
|
69
|
+
|
70
|
+
before do
|
71
|
+
new
|
72
|
+
end
|
73
|
+
|
74
|
+
specify do
|
75
|
+
expect(subject).to have_received(:new).with('')
|
76
|
+
end
|
77
|
+
end
|
56
78
|
end
|
57
79
|
end
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mecab-light
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hajime WAKAHARA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: Use a sequence of morphemes as an Enumerable object.
|
@@ -46,8 +46,8 @@ extensions:
|
|
46
46
|
- ext/mecab/light/extconf.rb
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
|
-
- .gitignore
|
50
|
-
- .travis.yml
|
49
|
+
- ".gitignore"
|
50
|
+
- ".travis.yml"
|
51
51
|
- Gemfile
|
52
52
|
- LICENSE.txt
|
53
53
|
- README.md
|
@@ -73,17 +73,17 @@ require_paths:
|
|
73
73
|
- lib
|
74
74
|
required_ruby_version: !ruby/object:Gem::Requirement
|
75
75
|
requirements:
|
76
|
-
- -
|
76
|
+
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: '1.9'
|
79
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- -
|
81
|
+
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
requirements: []
|
85
85
|
rubyforge_project:
|
86
|
-
rubygems_version: 2.
|
86
|
+
rubygems_version: 2.2.0
|
87
87
|
signing_key:
|
88
88
|
specification_version: 4
|
89
89
|
summary: An simple interface for MeCab (UNOFFICIAL)
|