-
Notifications
You must be signed in to change notification settings - Fork 0
/
marky_test.rb
95 lines (84 loc) · 2.4 KB
/
marky_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
require 'marky_markov'
require 'pry'
require 'yaml'
require 'literate_randomizer'
class String
def titlecase
split(/([[:alpha:]]+)/).map(&:capitalize).join
end
end
def setup
@markov = MarkyMarkov::Dictionary.new("#{rand(10000)}asdf")
# @markov.parse_file 'text/iching.txt'
@markov.parse_file 'text/iching-words.txt'
@markov.parse_file 'text/tarot-words.txt'
@markov.parse_file 'text/mckenna.txt'
@markov.parse_file 'text/rilke-words.txt'
@markov.save_dictionary!
@seeds_one = YAML.load(File.open('symbols/arcana.yml', 'r+'))
@seeds_two = YAML.load(File.open('symbols/dreams.yml', 'r+'))
@seeds_three = YAML.load(File.open('symbols/qualities.yml', 'r+'))
@seeds_four = YAML.load(File.open('symbols/hexagrams.yml', 'r+'))
@random = LiterateRandomizer.create(source_material_file: "#{Dir.pwd}/text/tarot-words.txt")
@counter = 0
end
def get_seed_word
words = [@seeds_one, @seeds_two, @seeds_three, @seeds_four].sample
words.sample
end
def find_sentence_for_word
1000.times do
sentence = @markov.generate_n_sentences(rand(3))
return sentence if sentence.downcase.include?(@seed_word.downcase)
end
nil
end
def find_sentence
sentence = nil
@seed_word = get_seed_word
sentence = find_sentence_for_word
return sentence if sentence
@counter += 1
return @random.sentence if @counter > 10
find_sentence
end
def modifiers
[
'leads to',
'follows',
'perplexes',
'shifts towards',
'obstructs',
'enhances',
'brings about',
'comes first, then',
'is a possibility, but so is',
'cannot stop',
'can turn into',
'can never stop',
'seems likely, but so does',
'can only lead to hesitation. Instead go for'
]
end
setup
loop do
gets.chomp
sentence = find_sentence
sentence = sentence.sub(/\w+/) { |m| m.capitalize }
sentence = sentence.gsub(/#{Regexp.escape(@seed_word)}/i, @seed_word.titlecase)
rand = rand(1..100)
if rand <= 4
puts "TYPE 1"
puts "#{get_seed_word.titlecase} #{modifiers.sample} #{get_seed_word.downcase}."
elsif rand <= 7
puts "TYPE 2"
sentence = sentence.split('.').first
sentence = sentence.split(',').first if sentence.split(' ').length > 10
puts "#{sentence}."
elsif rand <= 10
puts "TYPE 3"
puts "(#{get_seed_word.titlecase}) #{sentence.split('.').first}."
else
puts sentence.gsub(/#{Regexp.escape(@seed_word)}/i, @seed_word.upcase)
end
end