mecab-light 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -4
- data/lib/mecab/light.rb +6 -0
- data/lib/mecab/light/morpheme.rb +10 -0
- data/lib/mecab/light/result.rb +25 -0
- data/lib/mecab/light/tagger.rb +13 -0
- data/lib/mecab/light/version.rb +5 -0
- data/lib/mecab/tagger.rb +7 -0
- data/mecab-light.gemspec +3 -2
- data/spec/mecab_spec.rb +19 -19
- metadata +9 -8
- data/lib/mecab-light.rb +0 -15
- data/lib/mecab-light/morpheme.rb +0 -8
- data/lib/mecab-light/result.rb +0 -23
- data/lib/mecab-light/tagger.rb +0 -11
- data/lib/mecab-light/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bc1034d15fd3f35b2b1ad7d0ef37c2cc73cc827
|
4
|
+
data.tar.gz: cfbdc262474d9d30a56e9963e9f8b586f319dd33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1880e49178c264d6c9fb4e702d022d41742f2f6d9d0f9c46fd25367b155744b55c61518063d03e743dcd9734f10b306070c06bf6ff678f2d29ddcefc9203b614
|
7
|
+
data.tar.gz: aa31d0b6a51a66a097815dc30ca973a20fb23d468a8f1ef8cf68ff562f23cf409f4087fe2deaaeea13b23a84a2ed9acba32706ddd781bca038c9f77ed20bfdcf
|
data/README.md
CHANGED
@@ -4,6 +4,8 @@ Use a sequence of results as an Enumerable object.
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
+
At first, install the official gem "mecab-ruby" manually.
|
8
|
+
|
7
9
|
Add this line to your application's Gemfile:
|
8
10
|
|
9
11
|
gem 'mecab-light'
|
@@ -19,11 +21,11 @@ Or install it yourself as:
|
|
19
21
|
## Usage
|
20
22
|
|
21
23
|
```ruby
|
22
|
-
require 'mecab
|
24
|
+
require 'mecab/light'
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
result =
|
26
|
+
tagger = MeCab::Light::Tagger.new
|
27
|
+
string = 'この文を形態素解析してください。'
|
28
|
+
result = tagger.parse(string)
|
27
29
|
result[0].surface #=> "この"
|
28
30
|
result.map{|morpheme| morpheme.surface }
|
29
31
|
#=> ["この", "文", "を", "形態素", "解析", "し", "て", "ください", "。"]
|
data/lib/mecab/light.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module MeCab
|
2
|
+
module Light
|
3
|
+
class Result
|
4
|
+
include Enumerable
|
5
|
+
def initialize(line_enum)
|
6
|
+
@morphemes = line_enum.map{|line| Morpheme.new(line) }
|
7
|
+
end
|
8
|
+
|
9
|
+
def each(&block)
|
10
|
+
if block_given?
|
11
|
+
@morphemes.each(&block)
|
12
|
+
self
|
13
|
+
else
|
14
|
+
self.to_enum
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def [](nth)
|
19
|
+
@morphemes[nth]
|
20
|
+
end
|
21
|
+
|
22
|
+
alias at []
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/mecab/tagger.rb
ADDED
data/mecab-light.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'mecab
|
4
|
+
require 'mecab/light/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "mecab-light"
|
8
|
-
gem.version =
|
8
|
+
gem.version = MeCab::Light::VERSION
|
9
9
|
gem.authors = ["Hajime WAKAHARA"]
|
10
10
|
gem.email = ["hajime.wakahara@gmail.com"]
|
11
11
|
gem.description = %q{Use a sequence of results as an Enumerable object.}
|
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
|
+
gem.required_ruby_version = '>= 1.9'
|
19
20
|
|
20
21
|
gem.add_development_dependency 'rake'
|
21
22
|
gem.add_development_dependency 'rspec'
|
data/spec/mecab_spec.rb
CHANGED
@@ -3,12 +3,12 @@
|
|
3
3
|
$:.unshift(File.expand_path(File.dirname(__FILE__)) + '/lib')
|
4
4
|
|
5
5
|
require 'rspec'
|
6
|
-
require 'mecab
|
6
|
+
require 'mecab/light'
|
7
7
|
|
8
|
-
describe
|
8
|
+
describe MeCab::Light::Morpheme do
|
9
9
|
context 'when initialized with the result line of the word "見る"' do
|
10
10
|
before do
|
11
|
-
@morpheme =
|
11
|
+
@morpheme = MeCab::Light::Morpheme.new(
|
12
12
|
"見る\t動詞,自立,*,*,一段,基本形,見る,ミル,ミル\n")
|
13
13
|
end
|
14
14
|
subject { @morpheme }
|
@@ -24,10 +24,10 @@ describe Mecab::Morpheme do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
27
|
-
describe
|
27
|
+
describe MeCab::Light::Result do
|
28
28
|
context 'when initialized with the result Enumerator of the word "見る"' do
|
29
29
|
before do
|
30
|
-
@result =
|
30
|
+
@result = MeCab::Light::Result.new(
|
31
31
|
["見る\t動詞,自立,*,*,一段,基本形,見る,ミル,ミル\n"].to_enum)
|
32
32
|
end
|
33
33
|
subject { @result }
|
@@ -51,19 +51,19 @@ describe Mecab::Result do
|
|
51
51
|
describe '#[]' do
|
52
52
|
context 'when argument 0' do
|
53
53
|
subject { @result[0] }
|
54
|
-
it { should be_an_instance_of
|
54
|
+
it { should be_an_instance_of MeCab::Light::Morpheme }
|
55
55
|
end
|
56
56
|
end
|
57
57
|
describe '#at' do
|
58
58
|
context 'when argument 0' do
|
59
59
|
subject { @result.at(0) }
|
60
|
-
it { should be_an_instance_of
|
60
|
+
it { should be_an_instance_of MeCab::Light::Morpheme }
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
65
|
-
describe
|
66
|
-
before { @tagger =
|
65
|
+
describe MeCab::Tagger do
|
66
|
+
before { @tagger = MeCab::Tagger.new }
|
67
67
|
subject { @tagger }
|
68
68
|
it { should respond_to :parse_to_enum }
|
69
69
|
describe '#parse_to_enum' do
|
@@ -76,26 +76,26 @@ describe Mecab::Tagger do
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
79
|
-
describe
|
80
|
-
before { @
|
81
|
-
subject { @
|
79
|
+
describe MeCab::Light::Tagger do
|
80
|
+
before { @tagger = MeCab::Light::Tagger.new }
|
81
|
+
subject { @tagger }
|
82
82
|
it { should respond_to :parse }
|
83
83
|
describe '#parse' do
|
84
84
|
context 'when argument "見る"' do
|
85
|
-
before { @result = @
|
85
|
+
before { @result = @tagger.parse('見る') }
|
86
86
|
subject { @result }
|
87
|
-
it 'should return
|
88
|
-
should be_an_instance_of
|
87
|
+
it 'should return MeCab::Light::Result object' do
|
88
|
+
should be_an_instance_of MeCab::Light::Result
|
89
89
|
end
|
90
90
|
its(:count){ should be 1 }
|
91
|
-
describe 'returned
|
91
|
+
describe 'returned MeCab::Light::Result object' do
|
92
92
|
context '#[0]' do
|
93
93
|
before { @morpheme = @result[0] }
|
94
94
|
subject { @morpheme }
|
95
|
-
it 'should return
|
96
|
-
should be_an_instance_of
|
95
|
+
it 'should return MeCab::Light::Morpheme object' do
|
96
|
+
should be_an_instance_of MeCab::Light::Morpheme
|
97
97
|
end
|
98
|
-
describe 'returned
|
98
|
+
describe 'returned MeCab::Light::Morpheme object' do
|
99
99
|
context '#surface' do
|
100
100
|
subject { @morpheme.surface }
|
101
101
|
it { should eq '見る' }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mecab-light
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
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-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -50,11 +50,12 @@ files:
|
|
50
50
|
- LICENSE.txt
|
51
51
|
- README.md
|
52
52
|
- Rakefile
|
53
|
-
- lib/mecab
|
54
|
-
- lib/mecab
|
55
|
-
- lib/mecab
|
56
|
-
- lib/mecab
|
57
|
-
- lib/mecab
|
53
|
+
- lib/mecab/light.rb
|
54
|
+
- lib/mecab/light/morpheme.rb
|
55
|
+
- lib/mecab/light/result.rb
|
56
|
+
- lib/mecab/light/tagger.rb
|
57
|
+
- lib/mecab/light/version.rb
|
58
|
+
- lib/mecab/tagger.rb
|
58
59
|
- mecab-light.gemspec
|
59
60
|
- spec/lib/MeCab.rb
|
60
61
|
- spec/mecab_spec.rb
|
@@ -69,7 +70,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
70
|
requirements:
|
70
71
|
- - '>='
|
71
72
|
- !ruby/object:Gem::Version
|
72
|
-
version: '
|
73
|
+
version: '1.9'
|
73
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
75
|
requirements:
|
75
76
|
- - '>='
|
data/lib/mecab-light.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'MeCab'
|
2
|
-
require 'mecab-light/version'
|
3
|
-
require 'mecab-light/tagger'
|
4
|
-
require 'mecab-light/result'
|
5
|
-
require 'mecab-light/morpheme'
|
6
|
-
|
7
|
-
class Mecab
|
8
|
-
def initialize
|
9
|
-
@tagger = Tagger.new
|
10
|
-
end
|
11
|
-
|
12
|
-
def parse(string)
|
13
|
-
Result.new(@tagger.parse_to_enum(string))
|
14
|
-
end
|
15
|
-
end
|
data/lib/mecab-light/morpheme.rb
DELETED
data/lib/mecab-light/result.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
class Mecab
|
2
|
-
class Result
|
3
|
-
include Enumerable
|
4
|
-
def initialize(line_enum)
|
5
|
-
@morphemes = line_enum.map{|line| Morpheme.new(line) }
|
6
|
-
end
|
7
|
-
|
8
|
-
def each(&block)
|
9
|
-
if block_given?
|
10
|
-
@morphemes.each(&block)
|
11
|
-
self
|
12
|
-
else
|
13
|
-
self.to_enum
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def [](nth)
|
18
|
-
@morphemes[nth]
|
19
|
-
end
|
20
|
-
|
21
|
-
alias at []
|
22
|
-
end
|
23
|
-
end
|
data/lib/mecab-light/tagger.rb
DELETED
data/lib/mecab-light/version.rb
DELETED