markov_uuid 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ It is a truth universally acknowledged, that a single man in possession
2
+ of a good fortune, must be in want of a wife.
3
+
4
+ However little known the feelings or views of such a man may be on his
5
+ first entering a neighbourhood, this truth is so well fixed in the minds
6
+ of the surrounding families, that he is considered the rightful property
@@ -0,0 +1,9 @@
1
+ module KeySelector
2
+ SEPARATOR = "#-#-"
3
+
4
+ def new_key(key, word)
5
+ return SEPARATOR if word == "\n"
6
+
7
+ word or key
8
+ end
9
+ end
@@ -0,0 +1,45 @@
1
+ module MarkovUuid
2
+ class Markov
3
+ include KeySelector
4
+ SEPARATOR = "#-#-"
5
+
6
+ def to_s i=8
7
+ @words.join("")[0..i.to_i]
8
+ end
9
+
10
+ def initialize words
11
+ @words = words
12
+ end
13
+
14
+ def add_to markov_data
15
+ key = SEPARATOR
16
+
17
+ @words.each do |word|
18
+ (markov_data[key] ||= []) << word
19
+
20
+ key = new_key(key, word)
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ class << self
27
+ def from_file( f )
28
+ new lines(f).map { |l| from_string l }.flatten
29
+ end
30
+
31
+ private
32
+
33
+ def from_string l
34
+ l.gsub(/[^a-z]/i,'').split //
35
+ end
36
+
37
+ def lines f
38
+ content = File.read f
39
+ c = content.length
40
+ r = rand c
41
+ content[r-c .. r+c].downcase.split "\n"
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,41 @@
1
+ require "YAML"
2
+ require "fileutils"
3
+ module MarkovUuid
4
+ class Storage
5
+ include KeySelector
6
+ attr_accessor :data
7
+
8
+ def initialize(data = nil )
9
+ @data = data if data.class == Hash
10
+ @data ||= Hash.new
11
+ end
12
+
13
+ def add words
14
+ words.add_to @data
15
+ end
16
+
17
+ def to_words length = 100
18
+ key = Markov::SEPARATOR
19
+ word = ""
20
+
21
+ result = length.times.map do
22
+ word = @data[key].sample rescue nil
23
+ key = new_key( key, word )
24
+ word
25
+ end.compact
26
+
27
+ Markov.new result
28
+ end
29
+
30
+ def save filename
31
+ File.open(filename, "w"){|f| YAML.dump(@data, f) }
32
+ end
33
+
34
+ def load filename
35
+ FileUtils.touch filename
36
+ File.open(filename) do |f|
37
+ @data = YAML.load f
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module MarkovUuid
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,9 @@
1
+ require_relative "./markov_uuid/version"
2
+ require_relative './markov_uuid/key_selector'
3
+ require_relative './markov_uuid/storage'
4
+ require_relative './markov_uuid/markov'
5
+
6
+
7
+ module MarkovUuid
8
+ # Your code goes here...
9
+ end
data/markov.yaml ADDED
@@ -0,0 +1,245 @@
1
+ ---
2
+ ! '#-#-':
3
+ - n
4
+ n:
5
+ - p
6
+ - o
7
+ - e
8
+ - w
9
+ - t
10
+ - o
11
+ - t
12
+ - g
13
+ - m
14
+ - h
15
+ - t
16
+ - g
17
+ - e
18
+ - t
19
+ - d
20
+ - d
21
+ - g
22
+ - s
23
+ p:
24
+ - o
25
+ - r
26
+ - e
27
+ o:
28
+ - s
29
+ - n
30
+ - f
31
+ - o
32
+ - d
33
+ - r
34
+ - f
35
+ - w
36
+ - w
37
+ - r
38
+ - f
39
+ - n
40
+ - u
41
+ - o
42
+ - d
43
+ - w
44
+ - f
45
+ - u
46
+ - n
47
+ - p
48
+ s:
49
+ - s
50
+ - e
51
+ - s
52
+ - i
53
+ - t
54
+ - o
55
+ - o
56
+ - u
57
+ - f
58
+ - t
59
+ - t
60
+ - s
61
+ - o
62
+ - o
63
+ - u
64
+ - t
65
+ - c
66
+ - i
67
+ e:
68
+ - s
69
+ - m
70
+ - i
71
+ - h
72
+ - v
73
+ - r
74
+ - k
75
+ - f
76
+ - e
77
+ - l
78
+ - w
79
+ - o
80
+ - n
81
+ - r
82
+ - i
83
+ - l
84
+ - d
85
+ - m
86
+ - s
87
+ - s
88
+ - i
89
+ - r
90
+ - d
91
+ - r
92
+ - r
93
+ i:
94
+ - o
95
+ - n
96
+ - f
97
+ - t
98
+ - n
99
+ - e
100
+ - s
101
+ - r
102
+ - n
103
+ - g
104
+ - s
105
+ - s
106
+ - x
107
+ - n
108
+ - n
109
+ - n
110
+ - l
111
+ - e
112
+ - s
113
+ - d
114
+ - g
115
+ f:
116
+ - a
117
+ - o
118
+ - a
119
+ - e
120
+ - e
121
+ - s
122
+ - i
123
+ - i
124
+ - t
125
+ - a
126
+ - u
127
+ a:
128
+ - g
129
+ - n
130
+ - w
131
+ - m
132
+ - n
133
+ - y
134
+ - n
135
+ - m
136
+ - t
137
+ g:
138
+ - o
139
+ - s
140
+ - a
141
+ - h
142
+ - f
143
+ - h
144
+ d:
145
+ - f
146
+ - t
147
+ - i
148
+ - s
149
+ - i
150
+ - e
151
+ - t
152
+ r:
153
+ - t
154
+ - l
155
+ - v
156
+ - s
157
+ - i
158
+ - h
159
+ - u
160
+ - r
161
+ - o
162
+ - e
163
+ - i
164
+ - o
165
+ - t
166
+ t:
167
+ - u
168
+ - b
169
+ - o
170
+ - t
171
+ - l
172
+ - h
173
+ - e
174
+ - e
175
+ - h
176
+ - r
177
+ - h
178
+ - h
179
+ - h
180
+ - h
181
+ - h
182
+ - h
183
+ - f
184
+ - y
185
+ u:
186
+ - n
187
+ - s
188
+ - c
189
+ - r
190
+ - t
191
+ - r
192
+ - n
193
+ - l
194
+ m:
195
+ - u
196
+ - a
197
+ - a
198
+ - i
199
+ - i
200
+ b:
201
+ - e
202
+ - e
203
+ - o
204
+ w:
205
+ - a
206
+ - i
207
+ - e
208
+ - n
209
+ - s
210
+ - e
211
+ h:
212
+ - o
213
+ - e
214
+ - a
215
+ - i
216
+ - b
217
+ - o
218
+ - i
219
+ - i
220
+ - e
221
+ - e
222
+ - a
223
+ - e
224
+ - e
225
+ - t
226
+ v:
227
+ - e
228
+ - i
229
+ l:
230
+ - i
231
+ - e
232
+ - i
233
+ - l
234
+ - f
235
+ - i
236
+ - p
237
+ k:
238
+ - n
239
+ c:
240
+ - h
241
+ - o
242
+ y:
243
+ - b
244
+ x:
245
+ - e
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'markov_uuid/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "markov_uuid"
8
+ gem.version = MarkovUuid::VERSION
9
+ gem.authors = ["Mark Burns"]
10
+ gem.email = ["markthedeveloper@gmail.com"]
11
+ gem.description = %q{People friendly readable UUIDs}
12
+ gem.summary = %q{Easily generate random English-like UUIDs (or any other language)
13
+ that are more natural to convey to other people. E.g. over the phone, etc.}
14
+ gem.homepage = "http://github.com/markburns/markov_uuid"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+ end
data/storage.rb ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+ # Markov Chain Generator
3
+ # based on the Python version by Gary Burd: http://gary.burd.info/2003/11/markov-chain-generator.html
4
+ # Released into the public domain, please keep this notice intact
5
+ # (c) InVisible GmbH
6
+ # http://www.invisible.ch
7
+ #
8
+
9
+ require "YAML"
10
+
11
+ module KeySelector
12
+ SEPARATOR = "#-#-"
13
+
14
+ def new_key(key, word)
15
+ return SEPARATOR if word == "\n"
16
+
17
+ word or key
18
+ end
19
+ end
20
+
21
+ require './words'
22
+
23
+
24
+ if __FILE__ == $0 then
25
+ storage = Storage.new
26
+ file = ARGV[0]
27
+
28
+ storage.load "markov.yaml" unless file
29
+
30
+ if file
31
+ storage.add Markov.from_file file
32
+ storage.save "markov.yaml"
33
+ end
34
+
35
+ require 'ruby-debug'
36
+
37
+ puts storage.to_words
38
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markov_uuid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mark Burns
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-13 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: People friendly readable UUIDs
15
+ email:
16
+ - markthedeveloper@gmail.com
17
+ executables:
18
+ - markov
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - bin/markov
28
+ - data/pg100.txt
29
+ - data/pride_and_prejudice_small.txt
30
+ - lib/markov_uuid.rb
31
+ - lib/markov_uuid/key_selector.rb
32
+ - lib/markov_uuid/markov.rb
33
+ - lib/markov_uuid/storage.rb
34
+ - lib/markov_uuid/version.rb
35
+ - markov.yaml
36
+ - markov_uuid.gemspec
37
+ - storage.rb
38
+ homepage: http://github.com/markburns/markov_uuid
39
+ licenses: []
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 1.8.24
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Easily generate random English-like UUIDs (or any other language) that are
62
+ more natural to convey to other people. E.g. over the phone, etc.
63
+ test_files: []