nameko 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 +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/File: +0 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +37 -0
- data/LICENSE.txt +21 -0
- data/Name: +0 -0
- data/README.md +121 -0
- data/Rakefile +6 -0
- data/Successfully +0 -0
- data/Version: +0 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/nameko.rb +2 -0
- data/lib/nameko/nameko.rb +113 -0
- data/lib/nameko/version.rb +3 -0
- data/nameko.gemspec +28 -0
- metadata +119 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 7ea033cbecf52f5f7f98326e16ea8877b3ed5d71ba5910ac28bfc4fd74bc5a77
|
|
4
|
+
data.tar.gz: c824bc650de4469337ea3c8c12facb7c38240bbb718022a9d8444fe9ca0a8e2f
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 9048e0b1021b73e58da3a9931ab28c0853c45982d37433b1039b0d15c59743be04b4de9619291b77800d66bedd8c4246a490d088005293424d2d71f600912b47
|
|
7
|
+
data.tar.gz: 71b54f6dfa658f2e759a94401e6f97624a44619f1748e0cbf42712ed66574bb6c0be9ae829bdf52326e0d55e70119f9f8cfb53683efd9ba2a7182e7dfe8fa90d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at sa2taka@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/File:
ADDED
|
File without changes
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
nameko (0.1.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
diff-lcs (1.3)
|
|
10
|
+
ffi (1.9.23)
|
|
11
|
+
rake (10.5.0)
|
|
12
|
+
rspec (3.7.0)
|
|
13
|
+
rspec-core (~> 3.7.0)
|
|
14
|
+
rspec-expectations (~> 3.7.0)
|
|
15
|
+
rspec-mocks (~> 3.7.0)
|
|
16
|
+
rspec-core (3.7.1)
|
|
17
|
+
rspec-support (~> 3.7.0)
|
|
18
|
+
rspec-expectations (3.7.0)
|
|
19
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
20
|
+
rspec-support (~> 3.7.0)
|
|
21
|
+
rspec-mocks (3.7.0)
|
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
23
|
+
rspec-support (~> 3.7.0)
|
|
24
|
+
rspec-support (3.7.1)
|
|
25
|
+
|
|
26
|
+
PLATFORMS
|
|
27
|
+
ruby
|
|
28
|
+
|
|
29
|
+
DEPENDENCIES
|
|
30
|
+
bundler (~> 1.16)
|
|
31
|
+
ffi (~> 1.9)
|
|
32
|
+
nameko!
|
|
33
|
+
rake (~> 10.0)
|
|
34
|
+
rspec (~> 3.0)
|
|
35
|
+
|
|
36
|
+
BUNDLED WITH
|
|
37
|
+
1.16.1
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 sa2taka
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/Name:
ADDED
|
File without changes
|
data/README.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Nameko
|
|
2
|
+
|
|
3
|
+
Ruby binding for MeCab, Part-of-Speech and Morphological Analyzer.
|
|
4
|
+
|
|
5
|
+
Note:Nameko means "NAtto ya MEcab-gem yori KOkateki - NattoやMecab-gemより効果的(It is more effective than Natto or Mecab-gem)".
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'nameko'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install nameko
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
require 'nameko'
|
|
27
|
+
|
|
28
|
+
mecab = Nameko::Mecab.new
|
|
29
|
+
mecab.parse("私以外私じゃないの。")
|
|
30
|
+
# =>
|
|
31
|
+
[
|
|
32
|
+
{:surface=>'私', :pos=>'名詞', :pos1=>'代名詞', :pos2=>'一般', :pos3=>'', :conjugation_form=>'', :conjugation=>'', :base=>'私', :yomi=>'ワタシ', :pronunciation=>'ワタシ'},
|
|
33
|
+
{:surface=>'以外', :pos=>'名詞', :pos1=>'非自立', :pos2=>'副詞可能', :pos3=>'', :conjugation_form=>'', :conjugation=>'', :base=>'以外', :yomi=>'イガイ', :pronunciation=>'イガイ'},
|
|
34
|
+
{:surface=>'私', :pos=>'名詞', :pos1=>'代名詞', :pos2=>'一般', :pos3=>'', :conjugation_form=>'', :conjugation=>'', :base=>'私', :yomi=>'ワタシ', :pronunciation=>'ワタシ'},
|
|
35
|
+
{:surface=>'じゃ', :pos=>'助詞', :pos1=>'副助詞', :pos2=>'', :pos3=>'', :conjugation_form=>'', :conjugation=>'', :base=>'じゃ', :yomi=>'ジャ', :pronunciation=>'ジャ'},
|
|
36
|
+
{:surface=>'ない', :pos=>'助動詞', :pos1=>'', :pos2=>'', :pos3=>'', :conjugation_form=>'特殊・ナイ', :conjugation=>'基本形', :base=>'ない', :yomi=>'ナイ', :pronunciation=>'ナイ'},
|
|
37
|
+
{:surface=>'の', :pos=>'助詞', :pos1=>'終助詞', :pos2=>'', :pos3=>'', :conjugation_form=>'', :conjugation=>'', :base=>'の', :yomi=>'ノ', :pronunciation=>'ノ'},
|
|
38
|
+
{:surface=>'。',:pos=>'記号', :pos1=>'句点', :pos2=>'', :pos3=>'', :conjugation_form=>'', :conjugation=>'', :base=>'。', :yomi=>'。', :pronunciation=>'。'},
|
|
39
|
+
]
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Nameko::Mecab#parse returns a array of hash.
|
|
43
|
+
The hash keys meaning is as follows(The key is symbol):
|
|
44
|
+
+ `surface`: 表層系(Surface)
|
|
45
|
+
+ `pos`: 品詞(Part of speech)
|
|
46
|
+
+ `pos1`: 品詞細分類1(Part of speech subcategory1)
|
|
47
|
+
+ `pos2`: 品詞細分類2(Part of speech subcategory2)
|
|
48
|
+
+ `pos3`: 品詞細分類3(Part of speech subcategory3)
|
|
49
|
+
+ `conjugation_form`: 活用形(Conjugation form)
|
|
50
|
+
+ `conjugation`: 活用形(conjucation)
|
|
51
|
+
+ `base`: 基本形・原型(Lexical form)
|
|
52
|
+
+ `yomi`: 読み(Reading)
|
|
53
|
+
+ `pronunciation`: 発音(Pronunciation)
|
|
54
|
+
|
|
55
|
+
### With option
|
|
56
|
+
|
|
57
|
+
For example, if you use mecab-ipadic-neologd as a mecab dictionary:
|
|
58
|
+
|
|
59
|
+
```ruby
|
|
60
|
+
require 'nameko'
|
|
61
|
+
|
|
62
|
+
mecab = Nameko::Mecab.new("-d /usr/local/lib/mecab/dic/mecab-ipadic-neologd")
|
|
63
|
+
# mecab = Nameko::Mecab.new(["-d /usr/local/lib/mecab/dic/mecab-ipadic-neologd"])
|
|
64
|
+
# mecab = Nameko::Mecab.new(["-d", "/usr/local/lib/mecab/dic/mecab-ipadic-neologd"])
|
|
65
|
+
|
|
66
|
+
mecab.parse("アラレちゃん")
|
|
67
|
+
# => [{:surface=>"アラレちゃん", :pos=>"名詞", :pos1=>"固有名詞", :pos2=>"一般", :pos3=>"", :conjugation_form=>"", :conjugation=>"", :base=>"アラレちゃん", :yomi=>"アラレチャン", :pronunciation=>"アラレチャン"}]
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Nameko VS. Natto
|
|
71
|
+
|
|
72
|
+
The key difference between Natto and Nameko is the return value of parse method.
|
|
73
|
+
|
|
74
|
+
```ruby:Natto
|
|
75
|
+
require 'natto'
|
|
76
|
+
|
|
77
|
+
nm = Natto::MeCab.new
|
|
78
|
+
|
|
79
|
+
nm.enum_parse("私とあなた").each do |n|
|
|
80
|
+
puts n.feature unless n.is_eos?
|
|
81
|
+
end
|
|
82
|
+
# =>
|
|
83
|
+
名詞,代名詞,一般,*,*,*,私,ワタシ,ワタシ
|
|
84
|
+
助詞,格助詞,一般,*,*,*,と,ト,ト
|
|
85
|
+
名詞,代名詞,一般,*,*,*,あなた,アナタ,アナタ
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
```ruby:Nameko
|
|
89
|
+
require 'nameko'
|
|
90
|
+
|
|
91
|
+
mecab = Nameko::Mecab.new
|
|
92
|
+
|
|
93
|
+
mecab.parse("私とあなた")
|
|
94
|
+
# =>
|
|
95
|
+
[
|
|
96
|
+
{:surface=>"私", :pos=>"名詞", :pos1=>"代名詞", :pos2=>"一般", :pos3=>"", :conjugation_form=>"", :conjugation=>"", :base=>"私", :yomi=>"ワタシ", :pronunciation=>"ワタシ"},
|
|
97
|
+
{:surface=>"と", :pos=>"助詞", :pos1=>"格助詞", :pos2=>"一般", :pos3=>"", :conjugation_form=>"", :conjugation=>"", :base=>"と", :yomi=>"ト", :pronunciation=>"ト"},
|
|
98
|
+
{:surface=>"あなた", :pos=>"名詞", :pos1=>"代名詞", :pos2=>"一般", :pos3=>"", :conjugation_form=>"", :conjugation=>"", :base=>"あなた", :yomi=>"アナタ", :pronunciation=>"アナタ"}
|
|
99
|
+
]
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Development
|
|
103
|
+
|
|
104
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
105
|
+
|
|
106
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
107
|
+
|
|
108
|
+
## Contributing
|
|
109
|
+
|
|
110
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sa2taka/nameko. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
115
|
+
|
|
116
|
+
## Code of Conduct
|
|
117
|
+
|
|
118
|
+
Everyone interacting in the Nameko project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/nameko/blob/master/CODE_OF_CONDUCT.md).
|
|
119
|
+
|
|
120
|
+
## Author
|
|
121
|
+
[@t0p_l1ght](https://mstdn-workers.com/@t0p_l1ght)
|
data/Rakefile
ADDED
data/Successfully
ADDED
|
File without changes
|
data/Version:
ADDED
|
File without changes
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "nameko"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/nameko.rb
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
require "ffi"
|
|
2
|
+
|
|
3
|
+
module Nameko
|
|
4
|
+
# This class is providing a parse method.
|
|
5
|
+
# require 'nameko'
|
|
6
|
+
#
|
|
7
|
+
# mecab = Nameko::Mecab.new
|
|
8
|
+
# mecab.parse("私以外私じゃないの。")
|
|
9
|
+
#
|
|
10
|
+
# [
|
|
11
|
+
# {:surface=>'私', :pos=>'名詞', :pos1=>'代名詞', :pos2=>'一般', :pos3=>'', :conjugation_form=>'', :conjugation=>'', :base=>'私', :yomi=>'ワタシ', :pronunciation=>'ワタシ'},
|
|
12
|
+
# {:surface=>'以外', :pos=>'名詞', :pos1=>'非自立', :pos2=>'副詞可能', :pos3=>'', :conjugation_form=>'', :conjugation=>'', :base=>'以外', :yomi=>'イガイ', :pronunciation=>'イガイ'},
|
|
13
|
+
# {:surface=>'私', :pos=>'名詞', :pos1=>'代名詞', :pos2=>'一般', :pos3=>'', :conjugation_form=>'', :conjugation=>'', :base=>'私', :yomi=>'ワタシ', :pronunciation=>'ワタシ'},
|
|
14
|
+
# {:surface=>'じゃ', :pos=>'助詞', :pos1=>'副助詞', :pos2=>'', :pos3=>'', :conjugation_form=>'', :conjugation=>'', :base=>'じゃ', :yomi=>'ジャ', :pronunciation=>'ジャ'},
|
|
15
|
+
# {:surface=>'ない', :pos=>'助動詞', :pos1=>'', :pos2=>'', :pos3=>'', :conjugation_form=>'特殊・ナイ', :conjugation=>'基本形', :base=>'ない', :yomi=>'ナイ', :pronunciation=>'ナイ'},
|
|
16
|
+
# {:surface=>'の', :pos=>'助詞', :pos1=>'終助詞', :pos2=>'', :pos3=>'', :conjugation_form=>'', :conjugation=>'', :base=>'の', :yomi=>'ノ', :pronunciation=>'ノ'},
|
|
17
|
+
# {:surface=>'。',:pos=>'記号', :pos1=>'句点', :pos2=>'', :pos3=>'', :conjugation_form=>'', :conjugation=>'', :base=>'。', :yomi=>'。', :pronunciation=>'。'},
|
|
18
|
+
# ]
|
|
19
|
+
#
|
|
20
|
+
|
|
21
|
+
class Mecab
|
|
22
|
+
extend FFI::Library
|
|
23
|
+
ffi_lib 'mecab'
|
|
24
|
+
|
|
25
|
+
attach_function :mecab_new2, [:string], :pointer
|
|
26
|
+
attach_function :mecab_destroy, [:pointer], :void
|
|
27
|
+
attach_function :mecab_sparse_tostr, [:pointer, :string], :string
|
|
28
|
+
|
|
29
|
+
def self.destroy(mecab)
|
|
30
|
+
proc {
|
|
31
|
+
mecab_destory(mecab)
|
|
32
|
+
}
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Initialize the mecab tagger with the given option.
|
|
36
|
+
#
|
|
37
|
+
# How to specify options is as follows:
|
|
38
|
+
#
|
|
39
|
+
# @example
|
|
40
|
+
# mecab = Nameko::Mecab.new("-d /usr/local/lib/mecab/dic/mecab-ipadic-neologd")
|
|
41
|
+
# mecab = Nameko::Mecab.new(["-d /usr/local/lib/mecab/dic/mecab-ipadic-neologd"])
|
|
42
|
+
# mecab = Nameko::Mecab.new(["-d", "/usr/local/lib/mecab/dic/mecab-ipadic-neologd"])
|
|
43
|
+
#
|
|
44
|
+
#
|
|
45
|
+
def initialize(option = '')
|
|
46
|
+
option = option.join(' ') if option.is_a? Array
|
|
47
|
+
|
|
48
|
+
@mecab = mecab_new2(option)
|
|
49
|
+
ObjectSpace.define_finalizer(self, Mecab.destroy(@mecab))
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Parse the given string by MeCab.
|
|
53
|
+
# @param [String] str Parsed text
|
|
54
|
+
# @return [Array<Hash>] Result of Mecab parsing
|
|
55
|
+
#
|
|
56
|
+
# The return value is array of hash.
|
|
57
|
+
#
|
|
58
|
+
# The hash keys meaning is as follows(The key is symbol):
|
|
59
|
+
# surface: 表層系(Surface)
|
|
60
|
+
# pos: 品詞(Part of speech)
|
|
61
|
+
# pos1: 品詞細分類1(Part of speech subcategory1)
|
|
62
|
+
# pos2: 品詞細分類2(Part of speech subcategory2)
|
|
63
|
+
# pos3: 品詞細分類3(Part of speech subcategory3)
|
|
64
|
+
# conjugation_form: 活用形(Conjugation form)
|
|
65
|
+
# conjugation: 活用形(conjucation)
|
|
66
|
+
# base: 基本形・原型(Lexical form)
|
|
67
|
+
# yomi: 読み(Reading)
|
|
68
|
+
# pronunciation: 発音(Pronunciation)
|
|
69
|
+
|
|
70
|
+
def parse(str)
|
|
71
|
+
mecab_row = mecab_sparse_tostr(@mecab, str).force_encoding(Encoding.default_external)
|
|
72
|
+
analysis_result = analyze(mecab_row)
|
|
73
|
+
fill_up(analysis_result)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
def analyze(mecab_row)
|
|
79
|
+
mecab_row.split("\n").select{ |m| m != "EOS"}.map do |sentence|
|
|
80
|
+
sentence.match(/
|
|
81
|
+
^
|
|
82
|
+
(?<surface>[^\t]+)
|
|
83
|
+
\t
|
|
84
|
+
(?:
|
|
85
|
+
(?<pos>[^,]+),
|
|
86
|
+
\*?(?<pos1>[^,]*),
|
|
87
|
+
\*?(?<pos2>[^,]*),
|
|
88
|
+
\*?(?<pos3>[^,]*),
|
|
89
|
+
\*?(?<conjugation_form>[^,]*),
|
|
90
|
+
\*?(?<conjugation>[^,]*),
|
|
91
|
+
(?<base>[^,]*)
|
|
92
|
+
(?:
|
|
93
|
+
,(?<yomi>[^,]*)
|
|
94
|
+
,(?<pronunciation>[^,]*)
|
|
95
|
+
)?
|
|
96
|
+
)?
|
|
97
|
+
/x) do |md|
|
|
98
|
+
md.named_captures.map{|k,v| [k.to_sym, v] }.to_h
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def fill_up(analysis)
|
|
104
|
+
analysis.map do |parsed|
|
|
105
|
+
if !parsed[:yomi] && parsed[:surface].match(/\p{katakana}+/)
|
|
106
|
+
parsed[:yomi] = parsed[:surface]
|
|
107
|
+
parsed[:pronunciation] = parsed[:surface]
|
|
108
|
+
end
|
|
109
|
+
parsed
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
data/nameko.gemspec
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "nameko/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "nameko"
|
|
8
|
+
spec.version = Nameko::VERSION
|
|
9
|
+
spec.authors = ["sa2taka"]
|
|
10
|
+
spec.email = ["sa2taka@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Ruby binding for Mecab.}
|
|
13
|
+
spec.description = %q{Ruby binding for Mecab, Part-of-Speech and Morphological Analyzer.}
|
|
14
|
+
spec.homepage = "https://github.com/sa2taka/nameko"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
|
19
|
+
end
|
|
20
|
+
spec.bindir = "exe"
|
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
22
|
+
spec.require_paths = ["lib"]
|
|
23
|
+
|
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
27
|
+
spec.add_development_dependency "ffi", "~> 1.9"
|
|
28
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: nameko
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- sa2taka
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-03-22 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.16'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.16'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: ffi
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '1.9'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '1.9'
|
|
69
|
+
description: Ruby binding for Mecab, Part-of-Speech and Morphological Analyzer.
|
|
70
|
+
email:
|
|
71
|
+
- sa2taka@gmail.com
|
|
72
|
+
executables: []
|
|
73
|
+
extensions: []
|
|
74
|
+
extra_rdoc_files: []
|
|
75
|
+
files:
|
|
76
|
+
- ".gitignore"
|
|
77
|
+
- ".rspec"
|
|
78
|
+
- ".travis.yml"
|
|
79
|
+
- CODE_OF_CONDUCT.md
|
|
80
|
+
- 'File:'
|
|
81
|
+
- Gemfile
|
|
82
|
+
- Gemfile.lock
|
|
83
|
+
- LICENSE.txt
|
|
84
|
+
- 'Name:'
|
|
85
|
+
- README.md
|
|
86
|
+
- Rakefile
|
|
87
|
+
- Successfully
|
|
88
|
+
- 'Version:'
|
|
89
|
+
- bin/console
|
|
90
|
+
- bin/setup
|
|
91
|
+
- lib/nameko.rb
|
|
92
|
+
- lib/nameko/nameko.rb
|
|
93
|
+
- lib/nameko/version.rb
|
|
94
|
+
- nameko.gemspec
|
|
95
|
+
homepage: https://github.com/sa2taka/nameko
|
|
96
|
+
licenses:
|
|
97
|
+
- MIT
|
|
98
|
+
metadata: {}
|
|
99
|
+
post_install_message:
|
|
100
|
+
rdoc_options: []
|
|
101
|
+
require_paths:
|
|
102
|
+
- lib
|
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
|
+
requirements:
|
|
105
|
+
- - ">="
|
|
106
|
+
- !ruby/object:Gem::Version
|
|
107
|
+
version: '0'
|
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
|
+
requirements:
|
|
110
|
+
- - ">="
|
|
111
|
+
- !ruby/object:Gem::Version
|
|
112
|
+
version: '0'
|
|
113
|
+
requirements: []
|
|
114
|
+
rubyforge_project:
|
|
115
|
+
rubygems_version: 2.7.3
|
|
116
|
+
signing_key:
|
|
117
|
+
specification_version: 4
|
|
118
|
+
summary: Ruby binding for Mecab.
|
|
119
|
+
test_files: []
|