hiwai-kaeuta 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 30b144111d55205118b2c8240070a7e5e8d95dc1
4
+ data.tar.gz: cf1aef1decab43bce43767219be1700f88609221
5
+ SHA512:
6
+ metadata.gz: e8034fd3816e5ab7fcffa3e9bf989cfdf219dba5fecc519d5d533a7392725d5fe94ac9c2480142095efaec8b2a89b83fe74fb0368dd2a4f367726b2ab8a24498
7
+ data.tar.gz: 32819814485968be4e897e0d9fad54a3659ba98d1992bb30b4f4f60951af08c6d55193be81e228e4d417f9d388093b65cc75bd54eed388c1817fd70943975b03
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ #HiwaiKaeuta
2
+
3
+ ***
4
+
5
+ #概要
6
+
7
+ 日本語の任意の歌詞を卑猥な歌詞に変更します。
8
+
9
+ ***
10
+
11
+ #インストール
12
+
13
+ ##STEP 1.
14
+
15
+ mecab-rubyをインストールして下さい。
16
+
17
+ ##STEP 2.
18
+
19
+ ###Gemfile
20
+
21
+ ```ruby
22
+ gem 'hiwai-kaeuta'
23
+ ```
24
+
25
+ ###Script
26
+
27
+ ```bash
28
+ $ gem install 'hiwai-kaeuta'
29
+ ```
30
+
31
+ ***
32
+
33
+ #使い方
34
+
35
+ ```zsh
36
+ $ ruby -e "require 'hiwai-kaeuta';
37
+ puts HiwaiKaeuta.convert('あなたのキーは机の引き出しの中です')"
38
+ アナルのキーは机のマンコの中です
39
+ ```
data/bin/hiwaikaeuta ADDED
@@ -0,0 +1,5 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require File.expand_path('../../lib/hiwai-kaeuta', __FILE__)
4
+
5
+ puts HiwaiKaeuta.convert(File.open(ARGV[0]).read)
Binary file
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'hiwai-kaeuta'
3
+ s.version = '0.0.0'
4
+ s.date = '2014-02-08'
5
+ s.summary = '卑猥な替え歌を作るgem'
6
+ s.description = '日本語の任意の歌詞を卑猥な歌詞に変えます'
7
+ s.authors = ['pandora2000']
8
+ s.email = 'tetsuri.moriya@gmail.com'
9
+ s.homepage = 'https://bitbucket.org/pandora2000/kaeuta'
10
+ s.license = 'MIT'
11
+ s.files = `git ls-files`.split($/)
12
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
13
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
14
+ s.require_paths = ['lib']
15
+ end
@@ -0,0 +1,2 @@
1
+ require 'active_support/core_ext'
2
+ ActiveSupport::Dependencies.autoload_paths << File.expand_path('../../lib', __FILE__)
@@ -0,0 +1,33 @@
1
+ class HiwaiKaeuta
2
+ def self.convert(text)
3
+ nodes = Mecab::Nodes.new(text)
4
+ strs = converted_strings(nodes)
5
+ ''.tap do |res|
6
+ location = 0
7
+ nodes.each_with_index do |node, node_index|
8
+ str_index = text.index(node.surface, location)
9
+ res << text[location...str_index]
10
+ res << strs[node_index]
11
+ location = str_index + node.surface.length
12
+ end
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def self.converted_strings(nodes)
19
+ nodes.map { |x| x.surface }.tap do |res|
20
+ [].tap do |substs|
21
+ PriorityQueue.new.tap do |subst_queue|
22
+ Inference.execute(nodes).each { |x| subst_queue.push(x, x.priority) }
23
+ until subst_queue.empty?
24
+ subst = subst_queue.pop
25
+ next if substs.any? { |x| SubstSet.are_overlapping?(x, subst) }
26
+ substs << subst
27
+ end
28
+ end
29
+ substs.each { |x| x.execute(res) }
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ class HiwaiKaeuta
2
+ class Inference
3
+ HIWAI_WORDS = [['マンコ', 'マンコ'],
4
+ ['チンコ', 'チンコ'],
5
+ ['アナル', 'アナル'],
6
+ ['マラ', 'マラ'],
7
+ ['チツ', '膣']]
8
+
9
+ def self.execute(nodes)
10
+ %w(Node No).map { |x|
11
+ Pattern.const_get(x).get_all(nodes).map(&:subst).reject(&:nil?)
12
+ }.flatten
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ class HiwaiKaeuta::Inference::Pattern::Base
2
+ def self.get_all(nodes)
3
+ end
4
+
5
+ def subst
6
+ end
7
+ end
@@ -0,0 +1,46 @@
1
+ module HiwaiKaeuta::Inference::Pattern
2
+ class No < Base
3
+ PAIRS = [[[/.*/, 'マンコ'], /^ナカ$/],
4
+ [[/.*/, 'マンコ'], /^ニオイ$/]]
5
+
6
+ def self.get_all(nodes)
7
+ nodes.select { |node|
8
+ node.reading == 'ノ' && node.index > 0 && node.index < nodes.length - 1
9
+ }.map { |node|
10
+ new(node, nodes[node.index - 1], nodes[node.index + 1])
11
+ }
12
+ end
13
+
14
+ attr_reader :no_node, :pre_node, :post_node
15
+
16
+ def initialize(no_node, pre_node, post_node)
17
+ @no_node = no_node
18
+ @pre_node = pre_node
19
+ @post_node = post_node
20
+ end
21
+
22
+ def subst
23
+ return nil unless pre_node.is_noun? && post_node.is_noun?
24
+ can = PAIRS.map { |pre, post|
25
+ [match(pre, pre_node), match(post, post_node)]
26
+ }.reject { |pre, post| pre.nil? || post.nil? }.first
27
+ return nil if can.nil?
28
+ HiwaiKaeuta::SubstSet.new(2).tap do |subst|
29
+ subst.push(HiwaiKaeuta::Subst.new(pre_node.index, can[0]))
30
+ subst.push(HiwaiKaeuta::Subst.new(post_node.index, can[1]))
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def match(matcher, node)
37
+ if matcher.nil?
38
+ HiwaiKaeuta::Inference::HIWAI_WORDS.select { |x| x[0] == node.reading }.first.try(:[], 1)
39
+ elsif matcher.is_a?(Array)
40
+ matcher[1] if matcher[0].match(node.reading)
41
+ else
42
+ node.surface if matcher.match(node.reading)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,30 @@
1
+ module HiwaiKaeuta::Inference::Pattern
2
+ class Node < Base
3
+ HIWAI_WORDS = HiwaiKaeuta::Inference::HIWAI_WORDS
4
+
5
+ def self.get_all(nodes)
6
+ nodes.map { |x| new(x) }
7
+ end
8
+
9
+ attr_reader :node
10
+
11
+ def initialize(node)
12
+ @node = node
13
+ end
14
+
15
+ def subst
16
+ return nil unless node.is_noun?
17
+ read = node.reading
18
+ can = HIWAI_WORDS.reject { |wr, ww| wr.length != read.length }
19
+ .group_by { |wr, ww|
20
+ score = 0
21
+ wr.split('').each_with_index { |c, index| score += (c == read[index] ? 1 : 0) }
22
+ score
23
+ }.max_by { |k, v| k }
24
+ return nil if can.nil? || can[0] == 0
25
+ HiwaiKaeuta::SubstSet.new(1).tap do |subst|
26
+ subst.push(HiwaiKaeuta::Subst.new(node.index, can[1][0][1]))
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,38 @@
1
+ require 'MeCab'
2
+ require 'active_support/core_ext'
3
+
4
+ module HiwaiKaeuta::Mecab
5
+ class Node
6
+ attr_reader :features, :surface, :pos
7
+ attr_accessor :location, :index
8
+
9
+ def initialize(node)
10
+ @features = node.feature.split(',').map { |x| correct_encoding(x) }
11
+ @surface = correct_encoding(node.surface)
12
+ @pos = @features[0]
13
+ end
14
+
15
+ def is_bos_or_eos?
16
+ @pos == 'BOS/EOS'
17
+ end
18
+
19
+ def is_noun?
20
+ @pos == '名詞'
21
+ end
22
+
23
+ def reading
24
+ x = @features[7]
25
+ if x == '*' || x.nil?
26
+ @surface
27
+ else
28
+ x
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def correct_encoding(str)
35
+ str.force_encoding(__ENCODING__)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,32 @@
1
+ require 'MeCab'
2
+
3
+ module HiwaiKaeuta::Mecab
4
+ class Nodes
5
+ include Enumerable
6
+
7
+ delegate :each, :length, :[], to: :data
8
+
9
+ def initialize(text)
10
+ raw_node = MeCab::Tagger.new.parseToNode(text)
11
+ @nodes = [].tap do |nodes|
12
+ location = 0
13
+ while raw_node
14
+ node = Node.new(raw_node)
15
+ unless node.surface.empty?
16
+ location = text.index(node.surface, location)
17
+ end
18
+ node.location = location
19
+ nodes << node
20
+ raw_node = raw_node.next
21
+ end
22
+ end
23
+ @nodes.each_with_index { |node, index| node.index = index }
24
+ end
25
+
26
+ private
27
+
28
+ def data
29
+ @nodes
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ class HiwaiKaeuta::PriorityQueue
2
+ def initialize
3
+ @list = []
4
+ end
5
+
6
+ def push(elem, priority)
7
+ i = 0
8
+ @list.each do |x|
9
+ break if priority > x[:priority]
10
+ i += 1
11
+ end
12
+ @list.insert(i, { priority: priority, elem: elem })
13
+ end
14
+
15
+ def pop
16
+ r = @list.shift
17
+ r[:elem]
18
+ end
19
+
20
+ def empty?
21
+ @list.empty?
22
+ end
23
+
24
+ def delete(elem)
25
+ i = 0
26
+ @list.each do |x|
27
+ break if x[:elem].equal?(elem)
28
+ i += 1
29
+ end
30
+ @list.delete_at(i)
31
+ end
32
+
33
+ def to_a
34
+ @list
35
+ end
36
+ end
@@ -0,0 +1,14 @@
1
+ class HiwaiKaeuta
2
+ class Subst
3
+ attr_accessor :index, :str
4
+
5
+ def initialize(index, str)
6
+ @index = index
7
+ @str = str
8
+ end
9
+
10
+ def execute(target)
11
+ target[index] = str
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ class HiwaiKaeuta
2
+ class SubstSet
3
+ def self.are_overlapping?(substs1, substs2)
4
+ substs1.any? { |s1| substs2.any? { |s2| s1.index == s2.index } }
5
+ end
6
+
7
+ attr_accessor :priority
8
+
9
+ delegate :push, :any?, to: :data
10
+
11
+ def initialize(priority)
12
+ @priority = priority
13
+ @data = []
14
+ end
15
+
16
+ def execute(target)
17
+ @data.each { |x| x.execute(target) }
18
+ end
19
+
20
+ private
21
+
22
+ def data
23
+ @data
24
+ end
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hiwai-kaeuta
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - pandora2000
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 日本語の任意の歌詞を卑猥な歌詞に変えます
14
+ email: tetsuri.moriya@gmail.com
15
+ executables:
16
+ - hiwaikaeuta
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - README.md
21
+ - bin/hiwaikaeuta
22
+ - hiwai-kaeuta-0.0.0.gem
23
+ - hiwai-kaeuta.gemspec
24
+ - lib/hiwai-kaeuta.rb
25
+ - lib/hiwai_kaeuta.rb
26
+ - lib/hiwai_kaeuta/inference.rb
27
+ - lib/hiwai_kaeuta/inference/pattern/base.rb
28
+ - lib/hiwai_kaeuta/inference/pattern/no.rb
29
+ - lib/hiwai_kaeuta/inference/pattern/node.rb
30
+ - lib/hiwai_kaeuta/mecab/node.rb
31
+ - lib/hiwai_kaeuta/mecab/nodes.rb
32
+ - lib/hiwai_kaeuta/priority_queue.rb
33
+ - lib/hiwai_kaeuta/subst.rb
34
+ - lib/hiwai_kaeuta/subst_set.rb
35
+ homepage: https://bitbucket.org/pandora2000/kaeuta
36
+ licenses:
37
+ - MIT
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 2.0.14
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: 卑猥な替え歌を作るgem
59
+ test_files: []
60
+ has_rdoc: