markov_rensa-ruby 0.1.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: bc4ea598171bf2a163607e75b97cec1c25f8184b
4
+ data.tar.gz: 6b6c215948c5005580bafb71c1941d40744f2ae9
5
+ SHA512:
6
+ metadata.gz: 2af549bacfc94ee467537cbb1cbe08dd031aa95f3ce78a08ddf87d884007f561552d8807f1784541fdecb81eba04e42edb68c10b744d4a29fd17494aafa8de30
7
+ data.tar.gz: 0c727e60048cf3814633d5420f552a0e1a1da8fa96bf8efa72b1acf93d54d69b88f3818e512c19514cfe222a894cee52e046b97e30144f124ba1a95d5b1d8666
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in markov_rensa.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 gin0606
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # MarkovRensa [![Build Status](https://travis-ci.org/gin0606/markov_rensa-ruby.svg)](https://travis-ci.org/gin0606/markov_rensa-ruby)
2
+
3
+ マルコフ連鎖で文章を生成する
4
+ [kyow/igo-ruby](https://github.com/kyow/igo-ruby)を使っているのでMeCabなどは不要
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'markov_rensa-ruby'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install markov_rensa-ruby
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ # IPA辞書のパスを指定する
26
+ MarkovRensa::Configuration.dictionary = '/path/to/ipadic'
27
+
28
+ generator = MarkovRensa::Generator.new
29
+ generator.add_string('メロスは激怒した。必ず、かの邪智暴虐の王を除かなければならぬと決意した。')
30
+ generator.add_string('メロスには政治がわからぬ。メロスは、村の牧人である。')
31
+ generator.add_string('笛を吹き、羊と遊んで暮して来た。けれども邪悪に対しては、人一倍に敏感であった。')
32
+
33
+ puts generator.sentence # => けれども邪悪に対しては激怒した。
34
+ ```
35
+
36
+ 文章は[太宰治 走れメロス](http://www.aozora.gr.jp/cards/000035/files/1567_14913.html)から引用
37
+
38
+ ## その他
39
+ * [Igo - a morphological analyzer](http://igo.osdn.jp/index.html#usage)
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "markov_rensa"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ module MarkovRensa
2
+ class Configuration
3
+ class << self
4
+ attr_accessor :dictionary
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,58 @@
1
+ require "mem"
2
+
3
+ module MarkovRensa
4
+ class Generator
5
+ include Mem
6
+
7
+ attr_reader :order
8
+
9
+ def initialize(order=1)
10
+ @order = order
11
+ end
12
+
13
+ def add_string(string)
14
+ sentences = string.scan(/[^。]*。/)
15
+ sentences.each do |sentence|
16
+ wakati = tagger.wakati(sentence)
17
+ start_wards << wakati[0, order]
18
+
19
+ until wakati.size < order + 1 do
20
+ (wards[wakati[0, order]] ||= []) << wakati[order]
21
+ wakati.shift
22
+ end
23
+ end
24
+ sentences
25
+ end
26
+
27
+ def sentence
28
+ sentence = (start_wards.sample || [])
29
+ while nw = (wards[sentence[-order, order]] || []).sample
30
+ sentence << nw
31
+ end
32
+ sentence.join('')
33
+ end
34
+
35
+ def sentences(n=1)
36
+ n.times.map do
37
+ sentence
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def tagger
44
+ Tagger.new
45
+ end
46
+ memoize :tagger
47
+
48
+ def start_wards
49
+ []
50
+ end
51
+ memoize :start_wards
52
+
53
+ def wards
54
+ {}
55
+ end
56
+ memoize :wards
57
+ end
58
+ end
@@ -0,0 +1,9 @@
1
+ require "igo-ruby"
2
+
3
+ module MarkovRensa
4
+ class Tagger < Igo::Tagger
5
+ def initialize
6
+ super(MarkovRensa::Configuration.dictionary)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module MarkovRensa
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,8 @@
1
+ require "markov_rensa/version"
2
+ require "markov_rensa/configuration"
3
+ require "markov_rensa/tagger"
4
+ require "markov_rensa/generator"
5
+
6
+ module MarkovRensa
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'markov_rensa/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "markov_rensa-ruby"
8
+ spec.version = MarkovRensa::VERSION
9
+ spec.authors = ["gin0606"]
10
+ spec.email = ["kkgn06@gmail.com"]
11
+
12
+ spec.summary = "マルコフ連鎖で文章を生成する"
13
+ spec.homepage = "https://github.com/gin0606/markov_rensa-ruby"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "igo-ruby", "~> 0.1.5"
21
+ spec.add_dependency "mem"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec"
26
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markov_rensa-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - gin0606
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: igo-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: mem
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - kkgn06@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/markov_rensa.rb
100
+ - lib/markov_rensa/configuration.rb
101
+ - lib/markov_rensa/generator.rb
102
+ - lib/markov_rensa/tagger.rb
103
+ - lib/markov_rensa/version.rb
104
+ - markov_rensa.gemspec
105
+ homepage: https://github.com/gin0606/markov_rensa-ruby
106
+ licenses: []
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.4.5
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: "マルコフ連鎖で文章を生成する"
128
+ test_files: []