ensenar 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ensenar.rb +39 -0
- metadata +45 -0
data/lib/ensenar.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
class Ensenar
|
2
|
+
def initialize
|
3
|
+
@words = []
|
4
|
+
end
|
5
|
+
|
6
|
+
def reset
|
7
|
+
@words = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def add(sentence)
|
11
|
+
@words.push sentence.split(/\W+/)
|
12
|
+
end
|
13
|
+
|
14
|
+
def generate(length)
|
15
|
+
text = []
|
16
|
+
x = rand(@words.length)
|
17
|
+
y = rand(@words[x].length)
|
18
|
+
scope = @words[x][y]
|
19
|
+
text << @words[x][y]
|
20
|
+
while(text.length < length)
|
21
|
+
l = text.length
|
22
|
+
@words.each do |sentence|
|
23
|
+
if sentence.include? text.last
|
24
|
+
pos = sentence.find_index text.last
|
25
|
+
text << sentence[pos + 1]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
if l == text.length
|
29
|
+
break
|
30
|
+
else
|
31
|
+
next
|
32
|
+
end
|
33
|
+
end
|
34
|
+
if text.length < length
|
35
|
+
text << "... ummm..."
|
36
|
+
end
|
37
|
+
return text.join(" ")
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ensenar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- ! '[ Matt Carey ]'
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-09 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A smarter way to do markov chain, sentence generation
|
15
|
+
email: matthew.b.carey@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/ensenar.rb
|
21
|
+
homepage: http://lsden.net/
|
22
|
+
licenses: []
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 1.8.11
|
42
|
+
signing_key:
|
43
|
+
specification_version: 3
|
44
|
+
summary: Markov Chaining
|
45
|
+
test_files: []
|