dopeness 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +43 -0
- data/LICENSE.txt +21 -0
- data/README.md +50 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dopeness.gemspec +40 -0
- data/lib/.DS_Store +0 -0
- data/lib/dopeness.rb +46 -0
- data/lib/dopeness/parse_pronunciation.rb +27 -0
- data/lib/dopeness/parse_surfaces.rb +33 -0
- data/lib/dopeness/parse_vowels.rb +15 -0
- data/lib/dopeness/version.rb +3 -0
- data/memo.txt +63 -0
- data/sample.rb +75 -0
- metadata +164 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 296ea513f1e7bf6e7c38a80bf711d3a2b22cefbe
|
4
|
+
data.tar.gz: 7a5476d0e30799ca6dd19a63c426a25a57aea6de
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f7ff04240d60ca52ce379dc70c3be6697440c4a29fbe920dcfefba4b3fb76555953ce7a515b550364aceffcb683887532097aac91c304bf148e601428e040cf0
|
7
|
+
data.tar.gz: 87e68af78cdb617e27479e2ab696bd83d2238fa2ed34babb369b261a3dc05ec90d55fc3bcb8da3859f8464b08df965a852da3d588e8ed9d0b9e60342a60049ac
|
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 shindyu.dev@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/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
dopeness (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
cabocha (0.69.1)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
levenshtein (0.2.2)
|
12
|
+
mecab (0.996)
|
13
|
+
rake (10.4.2)
|
14
|
+
rspec (3.4.0)
|
15
|
+
rspec-core (~> 3.4.0)
|
16
|
+
rspec-expectations (~> 3.4.0)
|
17
|
+
rspec-mocks (~> 3.4.0)
|
18
|
+
rspec-core (3.4.4)
|
19
|
+
rspec-support (~> 3.4.0)
|
20
|
+
rspec-expectations (3.4.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.4.0)
|
23
|
+
rspec-mocks (3.4.1)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.4.0)
|
26
|
+
rspec-support (3.4.1)
|
27
|
+
trigram (0.0.1)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
bundler (~> 1.16)
|
34
|
+
cabocha (~> 0.69.1)
|
35
|
+
dopeness!
|
36
|
+
levenshtein (~> 0.2.2)
|
37
|
+
mecab (~> 0.996)
|
38
|
+
rake (~> 10.0)
|
39
|
+
rspec (~> 3.0)
|
40
|
+
trigram (~> 0.0.1)
|
41
|
+
|
42
|
+
BUNDLED WITH
|
43
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 shindyu
|
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/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Dopeness
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dopeness`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
***Parse a Verse, and Analayze the Rhyme.***
|
6
|
+
|
7
|
+
Analyze japanese text, rating good rhyme.
|
8
|
+
Rating is using Ngram and Lebenstein.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'dopeness'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install dopeness
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
```
|
29
|
+
require "dopeness"
|
30
|
+
|
31
|
+
Dopeness.dope("text")
|
32
|
+
```
|
33
|
+
|
34
|
+
## Development
|
35
|
+
|
36
|
+
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.
|
37
|
+
|
38
|
+
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).
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dopeness. 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.
|
43
|
+
|
44
|
+
## License
|
45
|
+
|
46
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
47
|
+
|
48
|
+
## Code of Conduct
|
49
|
+
|
50
|
+
Everyone interacting in the Dopeness project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/dopeness/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "dopeness"
|
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/dopeness.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "dopeness/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "dopeness"
|
7
|
+
spec.version = Dopeness::VERSION
|
8
|
+
spec.authors = ["shindyu"]
|
9
|
+
spec.email = ["shindyu.dev@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{parse a verse, and analayze a rhyme}
|
12
|
+
spec.description = %q{Analyze japanese text, rating good rhyme.
|
13
|
+
Rating is using Ngram and Lebenstein.}
|
14
|
+
spec.homepage = "https://github.com/shindyu/Dopeness"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
# "public gem pushes."
|
24
|
+
# end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_dependency "bundler", "~> 1.16"
|
34
|
+
spec.add_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_dependency "rspec", "~> 3.0"
|
36
|
+
spec.add_dependency "cabocha", "~> 0.69.1"
|
37
|
+
spec.add_dependency "romankana", "~> 0.2.1"
|
38
|
+
spec.add_dependency "trigram", "~> 0.0.1"
|
39
|
+
spec.add_dependency "levenshtein", "~> 0.2.2"
|
40
|
+
end
|
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/dopeness.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "romankana"
|
2
|
+
require "trigram"
|
3
|
+
require "levenshtein"
|
4
|
+
require "dopeness/version"
|
5
|
+
require_relative "dopeness/parse_surfaces"
|
6
|
+
require_relative "dopeness/parse_pronunciation"
|
7
|
+
require_relative "dopeness/parse_vowels"
|
8
|
+
|
9
|
+
module Dopeness
|
10
|
+
def self.dope(verse)
|
11
|
+
threshold = 0.0
|
12
|
+
surfaces = parse_surfaces(verse)
|
13
|
+
pronuncitaitons = parse_pronunciation(verse)
|
14
|
+
vowels = []
|
15
|
+
pronuncitaitons.each do |pronuncitaiton|
|
16
|
+
vowels.push(parse_vowels(pronuncitaiton.to_roman))
|
17
|
+
end
|
18
|
+
chunk_features = {}
|
19
|
+
(0...vowels.size).each do |i|
|
20
|
+
once_chunk_hash = {}
|
21
|
+
max = i + 10
|
22
|
+
if vowels.size < max
|
23
|
+
max = vowels.size
|
24
|
+
|
25
|
+
end
|
26
|
+
(i...max).each do |j|
|
27
|
+
# 母音の3-gram類似度
|
28
|
+
# 母音のLevenshtein距離
|
29
|
+
# 発音のLevenshtein距離
|
30
|
+
# 対象までの物理的距離 からスコアを計算する
|
31
|
+
trigram_evaluation = Trigram.compare(vowels[i], vowels[j])
|
32
|
+
if trigram_evaluation.nan?
|
33
|
+
trigram_evaluation = 0
|
34
|
+
end
|
35
|
+
vowels_distance = 1 - Levenshtein.normalized_distance(vowels[i], vowels[j])
|
36
|
+
pronuncitaitons_distance = 1 - Levenshtein.normalized_distance(pronuncitaitons[i], pronuncitaitons[j])
|
37
|
+
physical_distance = 1 - ((j - i) / 10)
|
38
|
+
matching_score = trigram_evaluation + vowels_distance + pronuncitaitons_distance + physical_distance
|
39
|
+
once_chunk_hash.store(j, matching_score)
|
40
|
+
end
|
41
|
+
sorted_score = Hash[once_chunk_hash.sort_by{ |_, v| -v }]
|
42
|
+
chunk_features.store(i, sorted_score)
|
43
|
+
end
|
44
|
+
return surfaces, chunk_features
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
require "CaboCha"
|
4
|
+
include CaboCha
|
5
|
+
|
6
|
+
# sentenceを解析してchunkの配列を返す
|
7
|
+
module Dopeness
|
8
|
+
def parse_pronunciation(sentence)
|
9
|
+
parser = Parser.new;
|
10
|
+
tree = parser.parse(sentence)
|
11
|
+
tree.set_output_layer(OUTPUT_RAW_SENTENCE)
|
12
|
+
chunks = []
|
13
|
+
(0 ... tree.chunk_size).each do |i|
|
14
|
+
chunk = tree.chunk(i)
|
15
|
+
x = (0 ... chunk.token_size).map do |j|
|
16
|
+
if tree.token(chunk.token_pos + j).feature_list(tree.token(chunk.token_pos + j).feature_list_size - 1).force_encoding("UTF-8") != "*" then
|
17
|
+
tree.token(chunk.token_pos + j).feature_list(tree.token(chunk.token_pos + j).feature_list_size - 1).force_encoding("UTF-8")
|
18
|
+
else
|
19
|
+
tree.token(chunk.token_pos).surface.force_encoding("UTF-8")
|
20
|
+
end
|
21
|
+
end.join("")
|
22
|
+
chunks.push(x)
|
23
|
+
end
|
24
|
+
return chunks
|
25
|
+
end
|
26
|
+
module_function :parse_pronunciation
|
27
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
require "CaboCha"
|
4
|
+
include CaboCha
|
5
|
+
|
6
|
+
# sentenceを解析して配列を返す
|
7
|
+
module Dopeness
|
8
|
+
def parse_surfaces(sentence)
|
9
|
+
parser = Parser.new;
|
10
|
+
tree = parser.parse(sentence)
|
11
|
+
tree.set_output_layer(OUTPUT_RAW_SENTENCE)
|
12
|
+
surfaces = []
|
13
|
+
(0 ... tree.chunk_size).each do |i|
|
14
|
+
chunk = tree.chunk(i)
|
15
|
+
x = (0 ... chunk.token_size).map do |j|
|
16
|
+
surface = tree.token(chunk.token_pos + j).normalized_surface.force_encoding("UTF-8")
|
17
|
+
if surface != "*" then
|
18
|
+
if surface != "。"
|
19
|
+
surface
|
20
|
+
end
|
21
|
+
else
|
22
|
+
surface = tree.token(chunk.token_pos).normalized_surface.force_encoding("UTF-8")
|
23
|
+
if surface != "。"
|
24
|
+
surface
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end.join("")
|
28
|
+
surfaces.push(x)
|
29
|
+
end
|
30
|
+
return surfaces
|
31
|
+
end
|
32
|
+
module_function :parse_surfaces
|
33
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
module Dopeness
|
4
|
+
def parse_vowels(str)
|
5
|
+
vowel = ["a", "i", "u", "e", "o"]
|
6
|
+
rhyme = ""
|
7
|
+
str.each_char do |ch|
|
8
|
+
if vowel.include?(ch)
|
9
|
+
rhyme += ch
|
10
|
+
end
|
11
|
+
end
|
12
|
+
return rhyme
|
13
|
+
end
|
14
|
+
module_function :parse_vowels
|
15
|
+
end
|
data/memo.txt
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
4
|
+
mecab-ipadic-neologdをRubyから使う
|
5
|
+
|
6
|
+
環境はUbuntu15.04
|
7
|
+
neologd/mecab-ipadic-neologd
|
8
|
+
buruzaemon/natto
|
9
|
+
MeCabをインストールする
|
10
|
+
#インストール
|
11
|
+
$ sudo apt-get install mecab
|
12
|
+
|
13
|
+
#インストール確認
|
14
|
+
$ mecab --version
|
15
|
+
mecab of 0.996
|
16
|
+
|
17
|
+
$ echo "おはよう" | mecab
|
18
|
+
おはよう 感動詞,*,*,*,*,*,おはよう,オハヨウ,オハヨー
|
19
|
+
EOS
|
20
|
+
nattoをインストールする
|
21
|
+
#インストール
|
22
|
+
$ gem install natto
|
23
|
+
#もしくは
|
24
|
+
$ vim Gemfile
|
25
|
+
+ gem 'natto'
|
26
|
+
$ bundle install
|
27
|
+
|
28
|
+
#インストール確認
|
29
|
+
$ irb
|
30
|
+
> require "natto"
|
31
|
+
=> true
|
32
|
+
> natto = Natto::MeCab.new
|
33
|
+
=>
|
34
|
+
#<Natto::MeCab:0x007f7d0fca10a0
|
35
|
+
@model=#<FFI::Pointer address=0x007f7d1018b6c0>,
|
36
|
+
@tagger=#<FFI::Pointer address=0x007f7d10410600>,
|
37
|
+
@lattice=#<FFI::Pointer address=0x007f7d103cb6f0>,
|
38
|
+
@libpath="/usr/lib/libmecab.so",
|
39
|
+
@options={},
|
40
|
+
@dicts=[#<Natto::DictionaryInfo:0x007f7d0fc9e440
|
41
|
+
@filepath="/usr/share/mecab/dic/neologd/sys.dic", charset=UTF8, type=0>],
|
42
|
+
@version=0.996>
|
43
|
+
> natto.parse("おはよう")
|
44
|
+
=> "おはよう\t感動詞,*,*,*,*,*,おはよう,オハヨウ,オハヨー\nEOS\n"
|
45
|
+
mecab-ipadic-neologdをインストールする
|
46
|
+
neologd/mecab-ipadic-neologd/README.ja.md の通りにやれば問題ないです。
|
47
|
+
依存パッケージが色々とあるが、インストールは省略する。
|
48
|
+
$ git clone --depth 1 https://github.com/neologd/mecab-ipadic-neologd.git
|
49
|
+
$ cd mecab-ipadic-neologd.git
|
50
|
+
$ ./bin/install-mecab-ipadic-neologd -n
|
51
|
+
#辞書ファイルを配置するディレクトリを変えたければ-pオプションで指定
|
52
|
+
$ ./bin/install-mecab-ipadic-neologd -n -p /usr/share/mecab/dic/neologd
|
53
|
+
mecabのデフォルト辞書をneologdに変える
|
54
|
+
mecabの設定を変えてしまえば、nattoはそれを利用する。
|
55
|
+
|
56
|
+
vim /usr/local/etc/mecabrc // こっちの環境だとこのパスだった
|
57
|
+
$ vim /etc/mecabrc
|
58
|
+
+ dicdir = /usr/share/mecab/dic/neologd
|
59
|
+
|
60
|
+
#設定確認
|
61
|
+
$ echo "のんのんびより りぴーと" | mecab
|
62
|
+
のんのんびより りぴーと 名詞,固有名詞,一般,*,*,*,のんのんびよりりぴーと,ノンノンビヨリリピート,ノンノンビヨリリピート
|
63
|
+
EOS
|
data/sample.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
require "dopeness"
|
4
|
+
require 'net/http'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
# utamap cralwer
|
8
|
+
def crawler(target_url)
|
9
|
+
# uri = URI.parse('http://www.utamap.com/phpflash/flashfalsephp.php?unum=k-111208-003')
|
10
|
+
uri = URI.parse(target_url)
|
11
|
+
res = Net::HTTP.get_response(uri)
|
12
|
+
return res.body.split("test2=")[1].force_encoding("UTF-8")
|
13
|
+
end
|
14
|
+
|
15
|
+
def show_features(surfaces, chunk_features)
|
16
|
+
features_index = 0
|
17
|
+
chunk_features.each do |feature|
|
18
|
+
print "\e[33m"
|
19
|
+
puts "[#{feature[0]}] #{surfaces[feature[0]]}"
|
20
|
+
print "\e[0m"
|
21
|
+
|
22
|
+
if feature[1].empty? then
|
23
|
+
# puts "\tnone"
|
24
|
+
else
|
25
|
+
loop_count = 0
|
26
|
+
feature[1].each { |pos, score|
|
27
|
+
# if loop_count > 3
|
28
|
+
# break
|
29
|
+
# end
|
30
|
+
if features_index != pos
|
31
|
+
if 0 < score && score < 4
|
32
|
+
if 2 < score then
|
33
|
+
print "\e[32m"
|
34
|
+
puts "\t[#{pos}] #{surfaces[pos]} : #{score}"
|
35
|
+
print "\e[0m"
|
36
|
+
else
|
37
|
+
puts "\t[#{pos}] #{surfaces[pos]} : #{score}"
|
38
|
+
end
|
39
|
+
loop_count += 1
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
}
|
44
|
+
end
|
45
|
+
# puts "\n"
|
46
|
+
features_index += 1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
lyric = crawler('http://www.utamap.com/phpflash/flashfalsephp.php?unum=k-160302-083')
|
52
|
+
lyric = "この氷河期じゃ 能書きじゃなく
|
53
|
+
ひねる脳がキー 要するに猛吹雪を
|
54
|
+
毛布抜きで越えてく 肉弾戦でテクニック
|
55
|
+
出せん奴は脱落だ 辛くても立つ
|
56
|
+
ラクダみたいに 前進する
|
57
|
+
飾らない 依然シースルーで
|
58
|
+
見せてくのみ内面 まるで伸びない麺
|
59
|
+
あったかさパッケージ 音と言葉が合併し
|
60
|
+
|
61
|
+
冬の街中で マジな賭けしなきゃ
|
62
|
+
始まらね~ 母ちゃん曰く
|
63
|
+
麻雀みたく あんたちゃんと
|
64
|
+
がんばらんと サンタサンも来ないよ
|
65
|
+
だから常夏まで 言葉つなげ"
|
66
|
+
|
67
|
+
# 前処理
|
68
|
+
verses = lyric.split("\n\n")
|
69
|
+
|
70
|
+
verses.each do |verse|
|
71
|
+
verse = verse.gsub(/(\s)/,"。")
|
72
|
+
puts verse
|
73
|
+
surfaces, chunk_features = Dopeness.dope(verse)
|
74
|
+
show_features(surfaces, chunk_features)
|
75
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dopeness
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- shindyu
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-09 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: :runtime
|
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: :runtime
|
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: :runtime
|
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: cabocha
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.69.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.69.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: romankana
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.2.1
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.2.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: trigram
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.0.1
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.0.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: levenshtein
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.2.2
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.2.2
|
111
|
+
description: |-
|
112
|
+
Analyze japanese text, rating good rhyme.
|
113
|
+
Rating is using Ngram and Lebenstein.
|
114
|
+
email:
|
115
|
+
- shindyu.dev@gmail.com
|
116
|
+
executables: []
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- .gitignore
|
121
|
+
- .rspec
|
122
|
+
- .travis.yml
|
123
|
+
- CODE_OF_CONDUCT.md
|
124
|
+
- Gemfile
|
125
|
+
- Gemfile.lock
|
126
|
+
- LICENSE.txt
|
127
|
+
- README.md
|
128
|
+
- Rakefile
|
129
|
+
- bin/console
|
130
|
+
- bin/setup
|
131
|
+
- dopeness.gemspec
|
132
|
+
- lib/.DS_Store
|
133
|
+
- lib/dopeness.rb
|
134
|
+
- lib/dopeness/parse_pronunciation.rb
|
135
|
+
- lib/dopeness/parse_surfaces.rb
|
136
|
+
- lib/dopeness/parse_vowels.rb
|
137
|
+
- lib/dopeness/version.rb
|
138
|
+
- memo.txt
|
139
|
+
- sample.rb
|
140
|
+
homepage: https://github.com/shindyu/Dopeness
|
141
|
+
licenses:
|
142
|
+
- MIT
|
143
|
+
metadata: {}
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubyforge_project:
|
160
|
+
rubygems_version: 2.0.14.1
|
161
|
+
signing_key:
|
162
|
+
specification_version: 4
|
163
|
+
summary: parse a verse, and analayze a rhyme
|
164
|
+
test_files: []
|