light-mecab 0.0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f71e38a8bffc439780889b8159cc4eb0edfb4ddc
4
+ data.tar.gz: c2b6da744a3da6bf59838437cf9af4d7919d3107
5
+ SHA512:
6
+ metadata.gz: 5ba527248b849472c1e4d3ea9d3070c2df322e6a605c43ea40181e14b9e7f427f994d09b00134959f8b88665002dcb1f6bb792d99c8c9386eb03991caf43a9f9
7
+ data.tar.gz: 3439477c732e5c94bfe65cc1409c75e0d81765c973bff8c809374ee2563a406ba11e36c89d44476d87121961747ef3455c45c1d33e5d85bc9d05dd11d7e6a9d5
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mecablight.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kei Tsuchiya
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,47 @@
1
+ # LightMecab
2
+
3
+ LightMecabは,mecab-rubyをラッピングすることで,より簡単に形態素解析を行うgemである.
4
+
5
+ ## Environment
6
+
7
+ MeCabおよびmecab-rubyが動作する環境が必要.
8
+
9
+ ## Installation
10
+
11
+ Gemfileに以下を記述する.
12
+
13
+ gem 'light-mecab'
14
+
15
+ その後,
16
+
17
+ $ bundle
18
+
19
+ を実行.
20
+
21
+ 以下のコマンドでもインストール可能.
22
+
23
+ $ gem install light-mecab
24
+
25
+ ## Usage
26
+ 例えば「太郎はこの本を二郎を見た女性に渡した。」という文に含まれる名詞は,
27
+
28
+ ```ruby
29
+ require 'light-mecab'
30
+ sentence = '太郎はこの本を二郎を見た女性に渡した。'
31
+ LightMecab::Morpheme.new(sentence).noun
32
+ ```
33
+ によって取得できる(返り値はString型の配列).
34
+
35
+ その他の品詞(形態素)を取得するメソッド名は,以下を参照.
36
+
37
+ lib/locale/morpheme.yml
38
+
39
+
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module LightMecab
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,63 @@
1
+ require 'light-mecab/version'
2
+ require 'MeCab'
3
+ require 'yaml'
4
+
5
+ module LightMecab
6
+ class Morpheme
7
+ @@i18n = ::YAML.load_file(File.expand_path(File.join(__FILE__, '..', 'locale', 'morpheme.yml')))
8
+
9
+ class << self
10
+ # @param text [String]
11
+ # @return [Array <MeCab::Node>]
12
+ def analyze(text)
13
+ nodes = []
14
+ node = ::MeCab::Tagger.new.parseToNode(text)
15
+ while node
16
+ nodes << node
17
+ node = node.next
18
+ end
19
+ nodes.shift
20
+ nodes.pop
21
+ nodes
22
+ end
23
+
24
+ # @param key [String or Symbol]
25
+ # @return [String]
26
+ def i18n(key)
27
+ key.is_a?(Symbol) ? @@i18n[key.to_s] : @@i18n[key]
28
+ end
29
+ end
30
+
31
+ # @param text [String]
32
+ def initialize(text)
33
+ @nodes = self.class.analyze(text)
34
+ end
35
+
36
+ # @return [Integer]
37
+ def count
38
+ @nodes.size
39
+ end
40
+
41
+ # @param method_name [Symbol]
42
+ def method_missing(method_name)
43
+ if !self.class.i18n(method_name)
44
+ raise NoMethodError
45
+ end
46
+ extract(self.class.i18n(method_name))
47
+ end
48
+
49
+ private
50
+
51
+ # @param name [String]
52
+ # @return [Array <String>]
53
+ def extract(name)
54
+ morpheme = []
55
+ @nodes.each do |node|
56
+ if name == node.feature.split(',').first.force_encoding('UTF-8')
57
+ morpheme << node.surface.force_encoding('UTF-8')
58
+ end
59
+ end
60
+ morpheme
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,9 @@
1
+ noun: '名詞'
2
+ verb: '動詞'
3
+ aux_verb: '助動詞'
4
+ adjective: '形容詞'
5
+ conjunction: '接続詞'
6
+ interjection: '感動詞'
7
+ particle: '助詞'
8
+ ad_adjective: '連体詞'
9
+ symbol: '記号'
@@ -0,0 +1,20 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'light-mecab/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'light-mecab'
8
+ spec.version = LightMecab::VERSION
9
+ spec.authors = ['Kei Tsuchiya']
10
+ spec.email = ['kei.tsuchiya86@gmail.com']
11
+ spec.description = %q{Execute morphological analysis by MeCab}
12
+ spec.summary = %q{Wrapping mecab-ruby to execute morphological analysis easlily}
13
+ spec.homepage = 'https://github.com/kei500/light-mecab'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+ end
@@ -0,0 +1,56 @@
1
+ # coding: utf-8
2
+ $: << File.expand_path(File.join(__FILE__, '..', '..', 'lib'))
3
+
4
+ require 'test-unit'
5
+ require 'light-mecab'
6
+
7
+ class TC_LightMecab_Morpheme < Test::Unit::TestCase
8
+ def setup
9
+ @sentence = 'そして太郎はこの本を二郎を見た美しい女性に渡した。'
10
+ @morpheme = LightMecab::Morpheme.new(@sentence)
11
+ end
12
+
13
+ def test_count
14
+ assert_equal(17, @morpheme.count)
15
+ end
16
+
17
+ def test_method_missing_noun
18
+ assert_equal(['太郎', '本', '二', '郎', '女性'], @morpheme.noun)
19
+ end
20
+
21
+ def test_method_missing_verb
22
+ assert_equal(['見', '渡し'], @morpheme.verb)
23
+ end
24
+
25
+ def test_method_missing_aux_verb
26
+ assert_equal(['た', 'た'], @morpheme.aux_verb)
27
+ end
28
+
29
+ def test_method_missing_adjective
30
+ assert_equal(['美しい'], @morpheme.adjective)
31
+ end
32
+
33
+ def test_method_missing_conjunction
34
+ assert_equal(['そして'], @morpheme.conjunction)
35
+ end
36
+
37
+ def test_method_missing_interjection
38
+ assert_equal([], @morpheme.interjection)
39
+ end
40
+
41
+ def test_method_missing_particle
42
+ assert_equal(['は', 'を', 'を', 'に'], @morpheme.particle)
43
+ end
44
+
45
+ def test_method_missing_ad_adjective
46
+ assert_equal(['この'], @morpheme.ad_adjective)
47
+ end
48
+
49
+ def test_method_missing_symbol
50
+ assert_equal(['。'], @morpheme.symbol)
51
+ end
52
+
53
+ def test_method_missing_hoge
54
+ assert_raise{@morpheme.hoge}
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: light-mecab
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Kei Tsuchiya
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Execute morphological analysis by MeCab
14
+ email:
15
+ - kei.tsuchiya86@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - .gitignore
21
+ - Gemfile
22
+ - LICENSE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - lib/light-mecab.rb
26
+ - lib/light-mecab/version.rb
27
+ - lib/locale/morpheme.yml
28
+ - light-mecab.gemspec
29
+ - test/test_morpheme.rb
30
+ homepage: https://github.com/kei500/light-mecab
31
+ licenses:
32
+ - MIT
33
+ metadata: {}
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 2.0.2
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: Wrapping mecab-ruby to execute morphological analysis easlily
54
+ test_files:
55
+ - test/test_morpheme.rb