mecab-light 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -2
- data/lib/mecab/light/binding.rb +10 -0
- data/lib/mecab/light/tagger.rb +13 -3
- data/lib/mecab/light/version.rb +1 -1
- data/lib/mecab/light.rb +2 -2
- data/mecab-light.gemspec +2 -0
- data/spec/mecab_spec.rb +31 -27
- metadata +17 -5
- data/lib/mecab/tagger.rb +0 -7
- data/spec/lib/MeCab.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a5511af0c985b3d07f4d529ca04c7138657867c
|
4
|
+
data.tar.gz: 89da28098265ec53e39c01bd3b6fedc75ff614f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1a8cbd1738fcab2d3b3d508cd45440c3755791fe8a061704ba91dad37aef5254719c42f60820ad3fdbf533de9101170e159b57c4cf7bed7529e19a4cec5d52e
|
7
|
+
data.tar.gz: 29244fa47f165c0e26ddffc1e8a733fa97945250988a82ff088eea7da13dde505c4877c7acf51fe9d89b54119d3a8b839e09f2244515f7b46330e7a7b1572040
|
data/README.md
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
-
#
|
1
|
+
# MeCab::Light [![Build Status](https://travis-ci.org/hadzimme/mecab-light.png)](https://travis-ci.org/hadzimme/mecab-light)
|
2
2
|
|
3
3
|
Use a sequence of results as an Enumerable object.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
7
|
+
This gem works without official binding.
|
8
|
+
MeCab::Light is a 'light' tool.
|
9
|
+
This supports only the 'parse' method for now,
|
10
|
+
and the method's feature is totally different from its original.
|
8
11
|
|
9
12
|
Add this line to your application's Gemfile:
|
10
13
|
|
data/lib/mecab/light/tagger.rb
CHANGED
@@ -1,12 +1,22 @@
|
|
1
1
|
module MeCab
|
2
2
|
module Light
|
3
3
|
class Tagger
|
4
|
-
def initialize
|
5
|
-
@
|
4
|
+
def initialize
|
5
|
+
@mecab = Binding.mecab_new2('')
|
6
6
|
end
|
7
7
|
|
8
8
|
def parse(string)
|
9
|
-
Result.new(
|
9
|
+
Result.new(parse_to_enum(string))
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def parse_to_enum(string)
|
14
|
+
parse_to_str(string).sub(/EOS\n$/, '').each_line
|
15
|
+
end
|
16
|
+
|
17
|
+
def parse_to_str(string)
|
18
|
+
encoding = Encoding.default_external
|
19
|
+
Binding.mecab_sparse_tostr(@mecab, string).force_encoding(encoding)
|
10
20
|
end
|
11
21
|
end
|
12
22
|
end
|
data/lib/mecab/light/version.rb
CHANGED
data/lib/mecab/light.rb
CHANGED
data/mecab-light.gemspec
CHANGED
data/spec/mecab_spec.rb
CHANGED
@@ -1,9 +1,27 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
$:.unshift(File.expand_path(File.dirname(__FILE__)) + '/lib')
|
4
|
-
|
5
3
|
require 'rspec'
|
6
|
-
|
4
|
+
begin
|
5
|
+
require 'mecab/light'
|
6
|
+
rescue LoadError
|
7
|
+
puts 'loaded mecab-light but MeCab does not exist.'
|
8
|
+
puts 'dummy binding will be loaded.'
|
9
|
+
end
|
10
|
+
|
11
|
+
module MeCab
|
12
|
+
module Light
|
13
|
+
module Binding
|
14
|
+
def self.mecab_new2(arg)
|
15
|
+
:dummy_mecab
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.mecab_sparse_tostr(mecab, string)
|
19
|
+
result = "見る\t動詞,自立,*,*,一段,基本形,見る,ミル,ミル\nEOS\n"
|
20
|
+
result.force_encoding('ASCII-8BIT')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
7
25
|
|
8
26
|
describe MeCab::Light::Morpheme do
|
9
27
|
context 'when initialized with the result line of the word "見る"' do
|
@@ -14,11 +32,11 @@ describe MeCab::Light::Morpheme do
|
|
14
32
|
subject { @morpheme }
|
15
33
|
its(:surface){ should eq '見る' }
|
16
34
|
its(:feature){ should eq '動詞,自立,*,*,一段,基本形,見る,ミル,ミル' }
|
17
|
-
describe '
|
35
|
+
describe 'surface' do
|
18
36
|
subject { @morpheme.surface }
|
19
37
|
its(:encoding){ should be Encoding::UTF_8 }
|
20
38
|
end
|
21
|
-
describe '
|
39
|
+
describe 'feature' do
|
22
40
|
subject { @morpheme.feature }
|
23
41
|
its(:encoding){ should be Encoding::UTF_8 }
|
24
42
|
end
|
@@ -34,7 +52,7 @@ describe MeCab::Light::Result do
|
|
34
52
|
it { should respond_to :each }
|
35
53
|
it { should be_an Enumerable }
|
36
54
|
its(:count){ should be 1 }
|
37
|
-
describe '
|
55
|
+
describe 'each' do
|
38
56
|
context 'with block' do
|
39
57
|
subject { @result.each{} }
|
40
58
|
it 'should return self' do
|
@@ -48,13 +66,13 @@ describe MeCab::Light::Result do
|
|
48
66
|
end
|
49
67
|
end
|
50
68
|
end
|
51
|
-
describe '
|
69
|
+
describe '[]' do
|
52
70
|
context 'when argument 0' do
|
53
71
|
subject { @result[0] }
|
54
72
|
it { should be_an_instance_of MeCab::Light::Morpheme }
|
55
73
|
end
|
56
74
|
end
|
57
|
-
describe '
|
75
|
+
describe 'at' do
|
58
76
|
context 'when argument 0' do
|
59
77
|
subject { @result.at(0) }
|
60
78
|
it { should be_an_instance_of MeCab::Light::Morpheme }
|
@@ -62,25 +80,11 @@ describe MeCab::Light::Result do
|
|
62
80
|
end
|
63
81
|
end
|
64
82
|
end
|
65
|
-
describe MeCab::Tagger do
|
66
|
-
before { @tagger = MeCab::Tagger.new }
|
67
|
-
subject { @tagger }
|
68
|
-
it { should respond_to :parse_to_enum }
|
69
|
-
describe '#parse_to_enum' do
|
70
|
-
context 'when argument "見る"' do
|
71
|
-
subject { @tagger.parse_to_enum('見る') }
|
72
|
-
it 'should return Enumerator' do
|
73
|
-
should be_an_instance_of Enumerator
|
74
|
-
end
|
75
|
-
its(:count){ should be 1 }
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
83
|
describe MeCab::Light::Tagger do
|
80
84
|
before { @tagger = MeCab::Light::Tagger.new }
|
81
85
|
subject { @tagger }
|
82
86
|
it { should respond_to :parse }
|
83
|
-
describe '
|
87
|
+
describe 'parse' do
|
84
88
|
context 'when argument "見る"' do
|
85
89
|
before { @result = @tagger.parse('見る') }
|
86
90
|
subject { @result }
|
@@ -88,15 +92,15 @@ describe MeCab::Light::Tagger do
|
|
88
92
|
should be_an_instance_of MeCab::Light::Result
|
89
93
|
end
|
90
94
|
its(:count){ should be 1 }
|
91
|
-
describe '
|
92
|
-
context '
|
95
|
+
describe 'MeCab::Light::Result (returned)' do
|
96
|
+
context '[0]' do
|
93
97
|
before { @morpheme = @result[0] }
|
94
98
|
subject { @morpheme }
|
95
99
|
it 'should return MeCab::Light::Morpheme object' do
|
96
100
|
should be_an_instance_of MeCab::Light::Morpheme
|
97
101
|
end
|
98
|
-
describe '
|
99
|
-
context '
|
102
|
+
describe 'MeCab::Light::Morpheme (returned)' do
|
103
|
+
context 'surface' do
|
100
104
|
subject { @morpheme.surface }
|
101
105
|
it { should eq '見る' }
|
102
106
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mecab-light
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hajime WAKAHARA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-03-
|
11
|
+
date: 2013-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ffi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rake
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -51,13 +65,12 @@ files:
|
|
51
65
|
- README.md
|
52
66
|
- Rakefile
|
53
67
|
- lib/mecab/light.rb
|
68
|
+
- lib/mecab/light/binding.rb
|
54
69
|
- lib/mecab/light/morpheme.rb
|
55
70
|
- lib/mecab/light/result.rb
|
56
71
|
- lib/mecab/light/tagger.rb
|
57
72
|
- lib/mecab/light/version.rb
|
58
|
-
- lib/mecab/tagger.rb
|
59
73
|
- mecab-light.gemspec
|
60
|
-
- spec/lib/MeCab.rb
|
61
74
|
- spec/mecab_spec.rb
|
62
75
|
homepage: https://github.com/hadzimme/mecab-light
|
63
76
|
licenses: []
|
@@ -83,5 +96,4 @@ signing_key:
|
|
83
96
|
specification_version: 4
|
84
97
|
summary: A Thin Wrapper for mecab-ruby
|
85
98
|
test_files:
|
86
|
-
- spec/lib/MeCab.rb
|
87
99
|
- spec/mecab_spec.rb
|
data/lib/mecab/tagger.rb
DELETED