|
|
|
|
@ -9,97 +9,101 @@ os.chdir('/home/bgcarlisle/Projects/Shantybot/')
|
|
|
|
|
with open ('corpus.txt') as corpus: |
|
|
|
|
mmodel = markovify.NewlineText(corpus) |
|
|
|
|
|
|
|
|
|
first_and_third_dont_rhyme = True |
|
|
|
|
second_and_fourth_dont_rhyme = True |
|
|
|
|
shanty = "" |
|
|
|
|
|
|
|
|
|
while first_and_third_dont_rhyme or second_and_fourth_dont_rhyme: |
|
|
|
|
while len(shanty.strip().split("\n")) < 9: |
|
|
|
|
|
|
|
|
|
first_line_rhymes_n = 0 |
|
|
|
|
first_and_third_dont_rhyme = True |
|
|
|
|
second_and_fourth_dont_rhyme = True |
|
|
|
|
|
|
|
|
|
while first_line_rhymes_n < 6: |
|
|
|
|
while first_and_third_dont_rhyme or second_and_fourth_dont_rhyme: |
|
|
|
|
|
|
|
|
|
first_line = re.sub(r'[,;]$', '', mmodel.make_sentence()) |
|
|
|
|
first_line_rhymes_n = 0 |
|
|
|
|
first_line_syllables = 0 |
|
|
|
|
|
|
|
|
|
first_line_syllables = textstat.syllable_count(first_line) |
|
|
|
|
while first_line_rhymes_n < 4 and (first_line_syllables == 0 or first_line_syllables > 12): |
|
|
|
|
|
|
|
|
|
first_line_words = first_line.split(" ") |
|
|
|
|
first_line = re.sub(r'[,;]$', '', mmodel.make_sentence()) |
|
|
|
|
|
|
|
|
|
first_line_lastword = first_line_words[len(first_line_words)-1] |
|
|
|
|
first_line_syllables = textstat.syllable_count(first_line) |
|
|
|
|
|
|
|
|
|
first_line_lastword = re.sub(r'[^A-Za-z]', '', first_line_lastword) |
|
|
|
|
first_line_words = first_line.split(" ") |
|
|
|
|
|
|
|
|
|
first_line_rhymes = pronouncing.rhymes(first_line_lastword) |
|
|
|
|
first_line_lastword = first_line_words[len(first_line_words)-1] |
|
|
|
|
|
|
|
|
|
first_line_rhymes_n = len(first_line_rhymes) |
|
|
|
|
first_line_lastword = re.sub(r'[^A-Za-z]', '', first_line_lastword) |
|
|
|
|
|
|
|
|
|
second_line_rhymes_n = 0 |
|
|
|
|
first_line_rhymes = pronouncing.rhymes(first_line_lastword) |
|
|
|
|
|
|
|
|
|
while second_line_rhymes_n < 6: |
|
|
|
|
first_line_rhymes_n = len(first_line_rhymes) |
|
|
|
|
|
|
|
|
|
second_line = re.sub(r'[,;]$', '', mmodel.make_sentence()) |
|
|
|
|
second_line_rhymes_n = 0 |
|
|
|
|
second_line_syllables = 0 |
|
|
|
|
|
|
|
|
|
second_line_syllables = textstat.syllable_count(second_line) |
|
|
|
|
while second_line_rhymes_n < 4 and (second_line_syllables == 0 or second_line_syllables > 12): |
|
|
|
|
|
|
|
|
|
second_line_words = second_line.split(" ") |
|
|
|
|
second_line = re.sub(r'[,;]$', '', mmodel.make_sentence()) |
|
|
|
|
|
|
|
|
|
second_line_lastword = second_line_words[len(second_line_words)-1] |
|
|
|
|
second_line_syllables = textstat.syllable_count(second_line) |
|
|
|
|
|
|
|
|
|
second_line_lastword = re.sub(r'[^A-Za-z]', '', second_line_lastword) |
|
|
|
|
second_line_words = second_line.split(" ") |
|
|
|
|
|
|
|
|
|
second_line_rhymes = pronouncing.rhymes(second_line_lastword) |
|
|
|
|
second_line_lastword = second_line_words[len(second_line_words)-1] |
|
|
|
|
|
|
|
|
|
second_line_rhymes_n = len(second_line_rhymes) |
|
|
|
|
second_line_lastword = re.sub(r'[^A-Za-z]', '', second_line_lastword) |
|
|
|
|
|
|
|
|
|
third_line_lastword = "" |
|
|
|
|
third_line_syllables = 0 |
|
|
|
|
third_line_tries = 0 |
|
|
|
|
second_line_rhymes = pronouncing.rhymes(second_line_lastword) |
|
|
|
|
|
|
|
|
|
while (third_line_syllables != first_line_syllables or first_and_third_dont_rhyme) and third_line_tries < 1000: |
|
|
|
|
second_line_rhymes_n = len(second_line_rhymes) |
|
|
|
|
|
|
|
|
|
third_line = re.sub(r'[,;]$', '', mmodel.make_sentence(tries=10000)) |
|
|
|
|
third_line_lastword = "" |
|
|
|
|
third_line_syllables = 0 |
|
|
|
|
third_line_tries = 0 |
|
|
|
|
|
|
|
|
|
third_line_syllables = textstat.syllable_count(third_line) |
|
|
|
|
while (third_line_syllables != first_line_syllables or first_and_third_dont_rhyme) and third_line_tries < 1000: |
|
|
|
|
|
|
|
|
|
third_line_words = third_line.split(" ") |
|
|
|
|
third_line = re.sub(r'[,;]$', '', mmodel.make_sentence(tries=10000)) |
|
|
|
|
|
|
|
|
|
third_line_lastword = third_line_words[len(third_line_words)-1] |
|
|
|
|
third_line_syllables = textstat.syllable_count(third_line) |
|
|
|
|
|
|
|
|
|
## print(first_line_lastword) |
|
|
|
|
## print(third_line_lastword) |
|
|
|
|
## print() |
|
|
|
|
third_line_words = third_line.split(" ") |
|
|
|
|
|
|
|
|
|
third_line_lastword = re.sub(r'[^A-Za-z]', '', third_line_lastword) |
|
|
|
|
third_line_lastword = third_line_words[len(third_line_words)-1] |
|
|
|
|
|
|
|
|
|
first_and_third_dont_rhyme = first_line_rhymes.count(third_line_lastword) == 0 |
|
|
|
|
## print(first_line_lastword) |
|
|
|
|
## print(third_line_lastword) |
|
|
|
|
## print() |
|
|
|
|
|
|
|
|
|
third_line_tries = third_line_tries + 1 |
|
|
|
|
third_line_lastword = re.sub(r'[^A-Za-z]', '', third_line_lastword) |
|
|
|
|
|
|
|
|
|
fourth_line_lastword = "" |
|
|
|
|
fourth_line_syllables = 0 |
|
|
|
|
fourth_line_tries = 0 |
|
|
|
|
first_and_third_dont_rhyme = first_line_rhymes.count(third_line_lastword) == 0 |
|
|
|
|
|
|
|
|
|
while (fourth_line_syllables != second_line_syllables or second_and_fourth_dont_rhyme) and fourth_line_tries < 1000: |
|
|
|
|
third_line_tries = third_line_tries + 1 |
|
|
|
|
|
|
|
|
|
fourth_line = re.sub(r'[,;]$', '', mmodel.make_sentence(tries=10000)) |
|
|
|
|
fourth_line_lastword = "" |
|
|
|
|
fourth_line_syllables = 0 |
|
|
|
|
fourth_line_tries = 0 |
|
|
|
|
|
|
|
|
|
fourth_line_syllables = textstat.syllable_count(fourth_line) |
|
|
|
|
while (fourth_line_syllables != second_line_syllables or second_and_fourth_dont_rhyme) and fourth_line_tries < 1000: |
|
|
|
|
|
|
|
|
|
fourth_line_words = fourth_line.split(" ") |
|
|
|
|
fourth_line = re.sub(r'[,;]$', '', mmodel.make_sentence(tries=10000)) |
|
|
|
|
|
|
|
|
|
fourth_line_lastword = fourth_line_words[len(fourth_line_words)-1] |
|
|
|
|
fourth_line_syllables = textstat.syllable_count(fourth_line) |
|
|
|
|
|
|
|
|
|
## print(second_line_lastword) |
|
|
|
|
## print(fourth_line_lastword) |
|
|
|
|
## print() |
|
|
|
|
fourth_line_words = fourth_line.split(" ") |
|
|
|
|
|
|
|
|
|
fourth_line_lastword = re.sub(r'[^A-Za-z]', '', fourth_line_lastword) |
|
|
|
|
fourth_line_lastword = fourth_line_words[len(fourth_line_words)-1] |
|
|
|
|
|
|
|
|
|
second_and_fourth_dont_rhyme = second_line_rhymes.count(fourth_line_lastword) == 0 |
|
|
|
|
## print(second_line_lastword) |
|
|
|
|
## print(fourth_line_lastword) |
|
|
|
|
## print() |
|
|
|
|
|
|
|
|
|
fourth_line_tries = fourth_line_tries + 1 |
|
|
|
|
fourth_line_lastword = re.sub(r'[^A-Za-z]', '', fourth_line_lastword) |
|
|
|
|
|
|
|
|
|
print(first_line) |
|
|
|
|
print(second_line) |
|
|
|
|
print(third_line) |
|
|
|
|
print(fourth_line) |
|
|
|
|
print() |
|
|
|
|
second_and_fourth_dont_rhyme = second_line_rhymes.count(fourth_line_lastword) == 0 |
|
|
|
|
|
|
|
|
|
fourth_line_tries = fourth_line_tries + 1 |
|
|
|
|
|
|
|
|
|
shanty = shanty + first_line + '\n' + second_line + '\n' + third_line + '\n' + fourth_line + '\n\n' |
|
|
|
|
|
|
|
|
|
print(shanty.strip()) |
|
|
|
|
|