mecab-light 0.0.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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +11 -0
- data/lib/mecab-light/morpheme.rb +8 -0
- data/lib/mecab-light/result.rb +23 -0
- data/lib/mecab-light/tagger.rb +11 -0
- data/lib/mecab-light/version.rb +3 -0
- data/lib/mecab-light.rb +15 -0
- data/mecab-light.gemspec +22 -0
- data/spec/lib/MeCab.rb +9 -0
- data/spec/mecab_spec.rb +108 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 203c20a8c5d25180dc33640456ac56a975689fa3
|
4
|
+
data.tar.gz: 0f3605e2ed97c113dc3f01cc9b495936da30dc7c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 44d1f604138c01311fef9c8a2fabbf649850a7fb557dcc0d6449cb662ce7b5e8739aa506d9059614cea1c5c7b2c9261f2e4abdd24008d63c63a0460f2172f9d5
|
7
|
+
data.tar.gz: 1388fa676d029f704cf7aa61e8c0b4671fa0e47042005818c93504840f7ba10cb0b0566a540feac431efa468c3ce71bf39ca6947fac0006cddcfdf58ab59d41e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Hajime WAKAHARA
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# mecab-light [](https://travis-ci.org/hadzimme/mecab-light)
|
2
|
+
|
3
|
+
Use a sequence of results as an Enumerable object.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'mecab-light'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install mecab-light
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'mecab-light'
|
23
|
+
|
24
|
+
mecab = Mecab.new
|
25
|
+
text = 'この文を形態素解析してください。'
|
26
|
+
result = mecab.parse(text)
|
27
|
+
result[0].surface #=> "この"
|
28
|
+
result.map{|morpheme| morpheme.surface }
|
29
|
+
#=> ["この", "文", "を", "形態素", "解析", "し", "て", "ください", "。"]
|
30
|
+
```
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
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.rb
ADDED
@@ -0,0 +1,15 @@
|
|
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/mecab-light.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mecab-light/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "mecab-light"
|
8
|
+
gem.version = Mecab::VERSION
|
9
|
+
gem.authors = ["Hajime WAKAHARA"]
|
10
|
+
gem.email = ["hajime.wakahara@gmail.com"]
|
11
|
+
gem.description = %q{Use a sequence of results as an Enumerable object.}
|
12
|
+
gem.summary = %q{A Thin Wrapper for mecab-ruby}
|
13
|
+
gem.homepage = "https://github.com/hadzimme/mecab-light"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rake'
|
21
|
+
gem.add_development_dependency 'rspec'
|
22
|
+
end
|
data/spec/lib/MeCab.rb
ADDED
data/spec/mecab_spec.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
$:.unshift(File.expand_path(File.dirname(__FILE__)) + '/lib')
|
4
|
+
|
5
|
+
require 'rspec'
|
6
|
+
require 'mecab-light'
|
7
|
+
|
8
|
+
describe Mecab::Morpheme do
|
9
|
+
context 'when initialized with the result line of the word "見る"' do
|
10
|
+
before do
|
11
|
+
@morpheme = Mecab::Morpheme.new(
|
12
|
+
"見る\t動詞,自立,*,*,一段,基本形,見る,ミル,ミル\n")
|
13
|
+
end
|
14
|
+
subject { @morpheme }
|
15
|
+
its(:surface){ should eq '見る' }
|
16
|
+
its(:feature){ should eq '動詞,自立,*,*,一段,基本形,見る,ミル,ミル' }
|
17
|
+
describe '#surface' do
|
18
|
+
subject { @morpheme.surface }
|
19
|
+
its(:encoding){ should be Encoding::UTF_8 }
|
20
|
+
end
|
21
|
+
describe '#feature' do
|
22
|
+
subject { @morpheme.feature }
|
23
|
+
its(:encoding){ should be Encoding::UTF_8 }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
describe Mecab::Result do
|
28
|
+
context 'when initialized with the result Enumerator of the word "見る"' do
|
29
|
+
before do
|
30
|
+
@result = Mecab::Result.new(
|
31
|
+
["見る\t動詞,自立,*,*,一段,基本形,見る,ミル,ミル\n"].to_enum)
|
32
|
+
end
|
33
|
+
subject { @result }
|
34
|
+
it { should respond_to :each }
|
35
|
+
it { should be_an Enumerable }
|
36
|
+
its(:count){ should be 1 }
|
37
|
+
describe '#each' do
|
38
|
+
context 'with block' do
|
39
|
+
subject { @result.each{} }
|
40
|
+
it 'should return self' do
|
41
|
+
should be @result
|
42
|
+
end
|
43
|
+
end
|
44
|
+
context 'without block' do
|
45
|
+
subject { @result.each }
|
46
|
+
it 'should return Enumerator' do
|
47
|
+
should be_an_instance_of Enumerator
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
describe '#[]' do
|
52
|
+
context 'when argument 0' do
|
53
|
+
subject { @result[0] }
|
54
|
+
it { should be_an_instance_of Mecab::Morpheme }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
describe '#at' do
|
58
|
+
context 'when argument 0' do
|
59
|
+
subject { @result.at(0) }
|
60
|
+
it { should be_an_instance_of Mecab::Morpheme }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
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
|
+
describe Mecab do
|
80
|
+
before { @mecab = Mecab.new }
|
81
|
+
subject { @mecab }
|
82
|
+
it { should respond_to :parse }
|
83
|
+
describe '#parse' do
|
84
|
+
context 'when argument "見る"' do
|
85
|
+
before { @result = @mecab.parse('見る') }
|
86
|
+
subject { @result }
|
87
|
+
it 'should return Mecab::Result object' do
|
88
|
+
should be_an_instance_of Mecab::Result
|
89
|
+
end
|
90
|
+
its(:count){ should be 1 }
|
91
|
+
describe 'returned Mecab::Result object' do
|
92
|
+
context '#[0]' do
|
93
|
+
before { @morpheme = @result[0] }
|
94
|
+
subject { @morpheme }
|
95
|
+
it 'should return Mecab::Morpheme object' do
|
96
|
+
should be_an_instance_of Mecab::Morpheme
|
97
|
+
end
|
98
|
+
describe 'returned Mecab::Morpheme object' do
|
99
|
+
context '#surface' do
|
100
|
+
subject { @morpheme.surface }
|
101
|
+
it { should eq '見る' }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mecab-light
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hajime WAKAHARA
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-03-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Use a sequence of results as an Enumerable object.
|
42
|
+
email:
|
43
|
+
- hajime.wakahara@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
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
|
+
- mecab-light.gemspec
|
59
|
+
- spec/lib/MeCab.rb
|
60
|
+
- spec/mecab_spec.rb
|
61
|
+
homepage: https://github.com/hadzimme/mecab-light
|
62
|
+
licenses: []
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.0.3
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: A Thin Wrapper for mecab-ruby
|
84
|
+
test_files:
|
85
|
+
- spec/lib/MeCab.rb
|
86
|
+
- spec/mecab_spec.rb
|