wordsoup 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/.byebug_history +7 -0
- data/.gitignore +10 -0
- data/Gemfile +4 -0
- data/README.md +36 -0
- data/Rakefile +2 -0
- data/author.rb +110 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/bible.txt +30382 -0
- data/lib/hamlet.txt +5588 -0
- data/lib/omats.txt +2830 -0
- data/lib/wordsoup/version.rb +3 -0
- data/lib/wordsoup.rb +108 -0
- data/wordsoup.gemspec +34 -0
- metadata +86 -0
data/lib/wordsoup.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
require "wordsoup/version"
|
2
|
+
|
3
|
+
module Wordsoup
|
4
|
+
class Author
|
5
|
+
|
6
|
+
attr_accessor :sentences, :word_hash, :first_words, :last_words
|
7
|
+
|
8
|
+
def initialize(file)
|
9
|
+
@sentences = make_sentence_array(file)
|
10
|
+
@word_hash = Hash.new { |h, k| h[k] = [] }
|
11
|
+
@first_words = []
|
12
|
+
@last_words = []
|
13
|
+
make_word_hash
|
14
|
+
end
|
15
|
+
|
16
|
+
def make_sentence_array(file)
|
17
|
+
text = ""
|
18
|
+
File.open(file).each do |line|
|
19
|
+
text << line
|
20
|
+
end
|
21
|
+
text = text.gsub(/\n/, " ")
|
22
|
+
text = text.gsub(/"/, "")
|
23
|
+
sentences = text.split(" ")
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def make_word_hash()
|
28
|
+
@sentences.each do |sentence|
|
29
|
+
sentence_array = sentence.split(" ")
|
30
|
+
sentence_array.each_with_index do |word, i|
|
31
|
+
@first_words << word if i == 0
|
32
|
+
@last_words << word if i == sentence_array.length - 1
|
33
|
+
unless i == sentence_array.length - 1
|
34
|
+
@word_hash[word] << sentence_array[i+1]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def sentence
|
41
|
+
sentence = [@first_words.sample.capitalize]
|
42
|
+
word = ""
|
43
|
+
until (sentence.length == 30)
|
44
|
+
word = @word_hash[sentence.last].sample
|
45
|
+
break if word.nil?
|
46
|
+
word = fix_word(word)
|
47
|
+
sentence << word
|
48
|
+
break if ["!","?","."].include?(word[word.length-1])
|
49
|
+
end
|
50
|
+
sentence = sentence.join(" ")
|
51
|
+
sentence[sentence.length-1] = "" if [",", ":", ";"].include?(sentence[sentence.length-1])
|
52
|
+
unless ["!","?","."].include?(sentence[sentence.length-1])
|
53
|
+
sentence << "?"
|
54
|
+
end
|
55
|
+
sentence
|
56
|
+
end
|
57
|
+
|
58
|
+
def paragraph
|
59
|
+
paragraph = ""
|
60
|
+
until paragraph.length > 250
|
61
|
+
paragraph << " "
|
62
|
+
paragraph << self.sentence
|
63
|
+
end
|
64
|
+
paragraph
|
65
|
+
end
|
66
|
+
|
67
|
+
def fix_word(word)
|
68
|
+
word = word.downcase
|
69
|
+
capitalized_words = ["i'll", "i", "god", "i."]
|
70
|
+
if capitalized_words.include?(word)
|
71
|
+
word = word.capitalize
|
72
|
+
end
|
73
|
+
word
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
class Shakespeare < Author
|
79
|
+
|
80
|
+
def initialize(file = "hamlet.txt")
|
81
|
+
super(file)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
class Hemingway < Author
|
87
|
+
|
88
|
+
def initialize(file = "omats.txt")
|
89
|
+
super(file)
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
class Hemingway < Author
|
95
|
+
|
96
|
+
def initialize(file = "omats.txt")
|
97
|
+
super(file)
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
class Bible < Author
|
102
|
+
|
103
|
+
def initialize(file = "bible.txt")
|
104
|
+
super(file)
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
data/wordsoup.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wordsoup/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "wordsoup"
|
8
|
+
spec.version = Wordsoup::VERSION
|
9
|
+
spec.authors = ["DouglasTGordon"]
|
10
|
+
spec.email = ["douglastgordon@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A jibberish generator in the style of popular authors.}
|
13
|
+
spec.description = %q{Generates sentences and paragraphs in the style of popular authors that have the syntax of English, but are totally jibberish. A better Lorem Ipsum! }
|
14
|
+
spec.homepage = "https://github.com/douglastgordon/WordSoup"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
# if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
# else
|
21
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
# "public gem pushes."
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wordsoup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- DouglasTGordon
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-26 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.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
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: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: 'Generates sentences and paragraphs in the style of popular authors that
|
42
|
+
have the syntax of English, but are totally jibberish. A better Lorem Ipsum! '
|
43
|
+
email:
|
44
|
+
- douglastgordon@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".byebug_history"
|
50
|
+
- ".gitignore"
|
51
|
+
- Gemfile
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- author.rb
|
55
|
+
- bin/console
|
56
|
+
- bin/setup
|
57
|
+
- lib/bible.txt
|
58
|
+
- lib/hamlet.txt
|
59
|
+
- lib/omats.txt
|
60
|
+
- lib/wordsoup.rb
|
61
|
+
- lib/wordsoup/version.rb
|
62
|
+
- wordsoup.gemspec
|
63
|
+
homepage: https://github.com/douglastgordon/WordSoup
|
64
|
+
licenses: []
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.5.1
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: A jibberish generator in the style of popular authors.
|
86
|
+
test_files: []
|