Пример #1
0
def write_song(doc1, doc2):
    mc = MarkovChain()
    verse = 1
    mc.add_file(doc1)
    with open(doc2, "w") as f:
        while verse < 5:
            f.write(("Verse %s" + "\n") % (verse))
            for x in range(4):
                line = mc.generate_text()
                join_line = " ".join(line)
                f.write(join_line.capitalize() + "\n")
            verse += 1
Пример #2
0
def write_song(doc1, doc2):
    mc = MarkovChain()
    verse = 1
    mc.add_file(doc1)
    with open(doc2, 'w') as f:
        while verse < 5:
            f.write(('Verse %s' + '\n') % (verse))
            for x in range(4):
                line = mc.generate_text()
                join_line = ' '.join(line)
                f.write(join_line.capitalize() + '\n')
            f.write('\n')
            verse += 1
Пример #3
0
def main():
    try:
        mc = MarkovChain()
        text = mc.add_file('ascii.txt')

        mc.generate_text(text)

    except ValueError:
        print "Oops! There's been an issue"
Пример #4
0
from markov_python.cc_markov import MarkovChain
mc = MarkovChain()

mc.add_file("story.txt")
print mc.generate_text()
import os
from markov_python.cc_markov import MarkovChain

mc = MarkovChain()
dirname = os.path.dirname(os.path.abspath(__file__))
book = os.path.join(dirname, 'Monologo_do_Vaqueiro_Gil_Vicente.txt')

mc.add_file(book)
sentence = mc.generate_text()

print(sentence)
Пример #6
0
from markov_python.cc_markov import MarkovChain

q = MarkovChain()
a = MarkovChain()
q.add_file('/users/agaro/desktop/Talk_bot/questions.txt')
a.add_file('/users/agaro/desktop/Talk_bot/answers.txt')
counter = 0
while counter <= 10:
    question = q.generate_text(13)
    question = ' '.join(question)
    print('Bot A: ')
    print question
    answer = a.generate_text(14)
    print('Bot B: ')
    answer = ' '.join(answer)
    print answer
    counter += 1
Пример #7
0
"""
Run.py includes the code that ties the flow of the application together.
It will be started from the command line.
"""

# Importing the modules needed.
from markov_python.cc_markov import MarkovChain

# Makes a new object.
mc = MarkovChain()

# Adds the text file.
mc.add_file('quotes.json')

# Generates some word in a list.
generatedWords = mc.generate_text(10)

# Prints out the word with the first letter uppercase,
# in a numbered list.
i = 0
for word in generatedWords:
    i += 1
    print("%s. %s." % (i, word.title()))
Пример #8
0
from markov_python.cc_markov import MarkovChain

mc = MarkovChain()
mc.add_file('C:/Users/dell/PycharmProjects/markov_chain/Wine Reviews.txt')

mc.add_string("red")

word_lst_1 = mc.generate_text(10)

print (word_lst_1)
word_lst_2 = []

for word in word_lst_1:
    if word.isdigit() == False:
        word_lst_2.append(word)
print(word_lst_2)

not_allowed = ["cases", "made", "has", "while"]
not_all_end = ["with", "and", "or", "on", "direct", "that", "are", "now", "through", "the", "supports", "hard", "a"]

word_lst_3 = []
for word in word_lst_2:
    if word not in not_allowed:
        word_lst_3.append(word)
print(word_lst_3)

while word_lst_3[len(word_lst_3) - 1] in not_all_end:
    del word_lst_3[len(word_lst_3) - 1]
print(word_lst_3)

str1 = ' '.join(word_lst_3)
Пример #9
0
from markov_python.cc_markov import MarkovChain

import scrapy

mc = MarkovChain()

#add filepath into mc.add_file(filepath) for files created by scrapy

mc.add_file('fetched_text')

#.generate_text() should generate a list of words
listofwords = []
listofwords = mc.generate_text(5)
listofwords = " ".join(listofwords)

print listofwords
Пример #10
0
from markov_python.cc_markov import MarkovChain as mc

mc_first = MarkovChain()

f = mc.add_file("test_text.rtf")

g = generate_text(f)

print (g)
Пример #11
0
from markov_python.cc_markov import MarkovChain
import fetch_data

hounds = MarkovChain()

hounds.add_file('D:\Projects\holmes_markov\Hounds.txt')

output = hounds.generate_text()

output = ' '.join(output)

output = output.capitalize() + "."

print output
Пример #12
0
from markov_python.cc_markov import MarkovChain

file = "pg1661.txt"

mc = MarkovChain()
mc.add_file(file)
print mc.generate_text().items
Пример #13
0
from markov_python.cc_markov import MarkovChain
#standard parser
mc = MarkovChain()

#mc.add_file('C:/Users/Chris/PycharmProjects/CodeCademy/venv/text files/carols.txt')
#mc.add_file('C:/Users/Chris/PycharmProjects/CodeCademy/venv/text files/farie tales.txt')
#mc.add_file('C:/Users/Chris/PycharmProjects/CodeCademy/venv/text files/50Shades.txt')
#mc.add_file('C:/Users/Chris/PycharmProjects/CodeCademy/venv/text files/lovecraft.txt')
#mc.add_file('C:/Users/Chris/PycharmProjects/CodeCademy/venv/text files/songdata.txt')
mc.add_file(
    'C:/Users/Chris/PycharmProjects/CodeCademy/venv/text files/bass_guitar_tabs.txt'
)
lyrics = mc.generate_text(20)


def printChain(L):
    s = "\n"
    while len(L) > 0:
        s = s + L.pop(0) + " "
    return s


print printChain(lyrics)
Пример #14
0
"""
Execute the Markov Chain of the data and produce the output
"""
import data_retrieval
from markov_python.cc_markov import MarkovChain

data_retrieval.retr()
mc = MarkovChain()
mc.add_file("gulistan-raw.txt")
sentence = mc.generate_text(10)
print "\nGENERATED SENTENCE: "
sentence[0] = sentence[0]
for i in range(0, len(sentence)):
    print sentence[i],
Пример #15
0
from markov_python.cc_markov import MarkovChain

import fetch_data

text = fetch_data

mc = MarkovChain()
mc.add_file("C:\Users\Wojtek\Desktop\Python Programming\markov_chain\Data_separate.txt")

start = True
while start == True:
    user_input = raw_input("You: ")
    if user_input == "bye":
        print "Judy: OK, byee!"
        start = False
    else:
        print "Judy: " + " ".join(mc.generate_text())
Пример #16
0
'''
Created on June 2, 2018
@author: vanessa
'''
from markov_python.cc_markov import MarkovChain

mc = MarkovChain()

mc.add_file('songtexte.txt')

lyric = mc.generate_text()
lyric = ' '.join(lyric)

Пример #17
0
from markov_python.cc_markov import MarkovChain
import random

mc = MarkovChain(3)

mc.add_file('phrase_bank.txt')

generated_song = ""


def generate_verse():
    new_verse = ""
    for lyric in mc.generate_text(random.randint(5, 16)):
        if lyric == 'i' or lyric == "i'm" or lyric == "i'ma" or lyric == "i'mma":
            lyric = lyric.capitalize()
        if new_verse == "":
            lyric = lyric.capitalize()
        new_verse += lyric + ' '
    return new_verse


def generate_song():
    generated_song = ""
    for i in range(0, random.randint(45, 55)):
        generated_song += (generate_verse() + ('\n'))
    return generated_song


print generate_song()
from markov_python.cc_markov import MarkovChain


if __name__ == '__main__':

    mc = MarkovChain()

    mc.add_file('lyrics.txt')

    lyric = mc.generate_text()
    lyric = ' '.join(lyric)

    lyric = ''.join([i for i in lyric if not i.isdigit()])
    print '---------------------------'
    print '---------------------------'
    print lyric
    print '---------------------------'
    print '---------------------------'
Пример #19
0
                    ' ').replace('</br>', ' ').replace('<b>', ' ').replace(
                        '</b>', ' ').replace('<p>', ' ').replace('</p>', ' ')

                song_string += x

#Write lyrics to files.

f.write(song_string)
f.close()

#3. Generate new song text*********************************************************************

mc = MarkovChain()  #initialise a MarkovChain class object - REMEMBER brackets!

#read a file or string:
mc.add_file('all_songs.txt')

#generate text (list of words)
output_list = mc.generate_text(200)

#add a new line after every n words (to give appearance of lyric sheet)
n = 10
i = n
while i < len(output_list):
    output_list.insert(i, '\n')
    i += (n + 1)

#join list of words and newlines into a string
output_string = " ".join(output_list)

#Print to console or save to file
Пример #20
0
from markov_python.cc_markov import MarkovChain
import fetch_data

lyrics_5 =fetch_data.lyrics_4
#blink_data= open('')

'''with open('/Users/lennykogosov/Desktop/markovproject/text.txt', 'r+') as f:
	text=f.read()'''


my_file= open('/Users/lennykogosov/Desktop/markovproject/text.txt', 'r+')
for x in lyrics_5:
	my_file.write(x) 





#my_file.close()


mc= MarkovChain()
mc.add_file('/Users/lennykogosov/Desktop/markovproject/text.txt')
first_sample= mc.generate_text(20)
print first_sample
my_file.close()
Пример #21
0
from markov_python.cc_markov import MarkovChain
mc = MarkovChain()
mc.add_file('Romeo.txt')
lines = (mc.generate_text(20))
line = " ".join(lines)
newLine = line[0].upper()
for char in line[1:]:
    newLine = newLine + char
print(newLine)
Пример #22
0
from markov_python.cc_markov import MarkovChain

mc = MarkovChain()
mc.add_file('/Users/mobpro/desktop/winereviews.txt')

mc.add_string("red")

print str(mc.generate_text(10))


Пример #23
0
from markov_python.cc_markov import MarkovChain
#import fetch_data
import os

mc = MarkovChain()

file_path = os.getcwd()
print file_path
mc.add_file("sermon_output_" + "0" + ".txt")
initial = mc.generate_text()


def convert_to_string(initial):
    sermon_string = ""
    for n in initial:
        sermon_string += (n + " ")
    print sermon_string
    return sermon_string


convert_to_string(initial)
Пример #24
0
'''
Created on 17/02/2019

@author: dinis
'''
from markov_python.cc_markov import MarkovChain

mc = MarkovChain()
mc.add_file("texto.txt")
words_list = mc.generate_text()
words_list = " ".join(words_list)
print (words_list)
Пример #25
0
from markov_python.cc_markov import MarkovChain
import fetch_data

link = 'http://www.e-reading.club/bookreader.php/1020088/Fomina_-_Pritchi._Daosskie%2C_kitayskie%2C_dzenskie.html'
#link='http://www.krotov.info/acts/01/joseph/filon_02.htm'

vocabul = fetch_data.load_web_to_text(link, 'voc.txt')
print type(vocabul)

fetch_data.show_param(str(vocabul))

out_fileS = 'out_text_string.txt'
out_file = 'out_text.txt'

text_object = MarkovChain(3)
text_object.add_file('voc.txt')
out_text = text_object.generate_text(200)

for i in out_text:
    try:
        print type(i), i.decode('utf8').encode('cp866')
    except:
        print 'Error'

out_text_j = ' '.join(out_text)
#with open(out_fileS,'w+') as ofile:
#	for i in out_text: ofile.write(i+'\n')
with open(out_file, 'w+') as ofile:
    for i in out_text:
        ofile.write(i + ' ')
Пример #26
0
#runs the project and outputs the text
from markov_python.cc_markov import MarkovChain
import fetch_data

mc = MarkovChain()

mc.add_file("sermon_output.txt")
initial = mc.generate_text()

def convert_to_file(initial):
	sermon_string = ""
	for n in initial:
		sermon_string += (n + " ")
	with open("Markov_Sermon.txt", "w") as f:
		f.write(sermon_string)

convert_to_file(initial)
Пример #27
0
'''
Created on Apr 7, 2018

@author: burust
'''
from markov_python.cc_markov import MarkovChain

mc = MarkovChain()

mc.add_file('lyrics.txt')

lyric = mc.generate_text()
lyric = ' '.join(lyric)

print '(Accompanied by soft guitar riffs, Ed Sheeran sings,)'
print ' '
print '"... ' + lyric + ' ..."'