elif next_word is not None:
        total2 = sum(markov[next_word].values())
        # print("total2", total2)
        rand_float2 = random.randint(1, total2)

        for key, value in markov[next_word].items():
            # print("value", value)
            fence += int(value)
            # print("fence2", fence)
            if fence >= rand_float2:
                return key


### Testing(does not use the normalized markov and just uses regular markov chain)
if __name__ == '__main__':
    content = open_file("test.txt")
    marv = generate_markov_1st_order(content)
    print(marv)
    i = 10
    markov_example = markov_sample_histogram(marv)
    sentence = ''

    while i > 0:
        markov_example2 = markov_sample_histogram(marv, markov_example)
        sentence += " " + markov_example2
        markov_example = markov_example2
        # print(i)
        i -= 1

    print(sentence)
Exemplo n.º 2
0
 def __init__(self, text_file):
     self.content = open_file(text_file)
     self.markov = self.build_markov(self.content)
Exemplo n.º 3
0
    def word_text(self, path='test.txt'):
        words = open_file(path)

        return words
    def open_text(self, path='test.txt'):
        text = open_file(path)

        return text
Exemplo n.º 5
0
 def __init__(self, text_file):
     self.content = open_file(text_file)
     self.markov = self.chain(self.content)
    def get_text(self, path='jordanpeterson.txt'):
        # Reuses open_file from histogram, grabs text

        text = open_file(path)
        return text
# from random import random
import random
from histogram import open_file, histogram, frequency, total_words

histogram = (histogram(open_file('test.txt')))

# histogram = {"one": 1, "fish": 4, "two": 1, "blue": 1, "red": 1}

# print(frequency("the", histogram(open_file())))
# print(frequency("of", histogram(open_file())))
# print(total_words(histogram(open_file())))
total_words = total_words(histogram)

print(total_words)


def stochastic(dic, total_words):
    rand_num = random.randint(1, total_words)
    # print(rand_num)
    total_value = 0
    for key, value in dic.items():
        # if rand_num <= value:
        # print("total_value", total_value)
        if rand_num - value - total_value <= 0:
            return key
        else:
            total_value += value


""" THis is the same as the abovaluee """
# def one(dic, total):
Exemplo n.º 8
0
import random
from histogram import open_file, histogram, frequency

histogram = (histogram(open_file('test.txt')))

# histogram = {"one": 1, "fish": 4, "two": 1, "blue": 1, "red": 1}


print(frequency("the", histogram(open_file())))
# print(frequency("of", histogram(open_file())))
# print(total_words(histogram(open_file())))
total_words = total_words(histogram)

print(total_words)

def stochastic(dic, total_words):
  rand_num = random.randint(1, total_words)
  # print(rand_num)
  total_value = 0
  for key,value in dic.items():
    # if rand_num <= value:
    # print("total_value", total_value)
    if rand_num - value - total_value <= 0:
      return key
    else:
      total_value += value
Exemplo n.º 9
0
from flask import Flask, render_template, request, url_for
import random
from histogram import open_file, histogram, frequency
from sample import stochastic, words_in_total
from markov_chain_order import Markov

app = Flask(__name__)

text_title = "Dr. Jekyll and Mr. Hyde, The Story of the Door"
file_content = open_file("book.txt")
markov_chain = Markov(file_content, 2)


@app.route('/')
def index():

    num = request.args.get('length')

    if num:
        sentence = markov_chain.get_sentence(int(num))
        return render_template("base.html", word=sentence, title=text_title)
    else:
        sentence = markov_chain.get_sentence(10)
        return render_template("base.html", word=sentence, title=text_title)


if __name__ == '__main__':
    app.run(debug=True)
# from random import random
import random
from histogram import open_file, histogram, frequency, total_words

# Getting the histogram
histogram = (histogram(open_file("test.txt")))

total_words = total_words(histogram)

# print(total_words)


def stochastic(dic, total_words):
    rand_num = random.randint(1, total_words)
    # print(rand_num)
    total_value = 0

    for key, value in dic.items():
        # if rand_num <= value:
        # print("total_value", total_value)
        if rand_num - value - total_value <= 0:
            return key
        else:
            total_value += value


# print(stochastic(histogram, total_words))
""" THis is the same as the abovaluee """
# def one(dic, total):
#   rand_num = random.randint(1, total)
#   total_value = 0
Exemplo n.º 11
0
 def __init__(self, text_file):
     """Initilize markov class"""
     self.content = open_file(text_file)
     self.markov = self.chain(self.content)
Exemplo n.º 12
0
import random
from histogram import open_file, histogram, frequency

histogram = (histogram(open_file('words.txt')))

histogram1 = histogram(open_file())

print(frequency("the", histogram1)    

#histogram(open_file())))
# print(frequency("of", histogram(open_file())))
# print(total_words(histogram(open_file())))
# total_words = total_words(histogram)