예제 #1
0
def main():
    # text = read_textfile("sample_text.txt")
    txt_list = convert_to_list("sample_text.txt")
    markov_chain = Markov(txt_list, 2)
    markov_chain.initiate_markov(txt_list)
    print(markov_chain.generate_sentence(15))

    return markov_chain
예제 #2
0
def main():
    '''This program reads in a histogram and returns a random word'''
    #read in text file, store as list
    txt = read_textfile("short_story.txt")
    txt_list = convert_to_list(txt)

    #create histogram based on list
    my_histogram = histogram(txt_list)

    test_randomness(my_histogram)
    test_weighted_randomness(my_histogram)
예제 #3
0
def countslopes():
    countslopesfile = open('countslopes.txt', 'w', encoding="utf-8")
    files = os.listdir('results/slopes/counts/')
    for filename in files:
        if filename != '.DS_Store' and filename != '.gitignore':
            with io.open('results/slopes/counts/' + filename, 'r') as f:
                lines = f.readlines()
                countslopes = convert_to_list(lines)

        revall = countslopes[0]
        rev60 = countslopes[1]
        rev120 = countslopes[2]
        # print(countslopes)
        dictdiff60 = dictdiff(rev60, revall)
        dictdiff120 = dictdiff(rev120, revall)
        countslopesfile.write(filename[:-4] + '\n')
        countslopesfile.write(str(dictdiff60) + '\n')
        countslopesfile.write(str(dictdiff120) + '\n')
        # print(dictdiff(rev60, revall))
        # print(dictdiff(rev120, revall))

    countslopesfile.close()
def main():
    '''Return random word from histogram'''
    txt = read_textfile("sample_text.txt")
    txt_list = convert_to_list(txt)
    histogram1 = histogram(txt_list)