This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from histograms import Dictogram | |
| import random | |
| from collections import deque | |
| import re | |
| def generate_random_start(model): | |
| # To just generate any starting word uncomment line: | |
| # return random.choice(model.keys()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from histograms import Dictogram | |
| def make_higher_order_markov_model(order, data): | |
| markov_model = dict() | |
| for i in range(0, len(data)-order): | |
| # Create the window | |
| window = tuple(data[i: i+order]) | |
| # Add to the dictionary |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from histograms import Dictogram | |
| def make_markov_model(data): | |
| markov_model = dict() | |
| for i in range(0, len(data)-1): | |
| if data[i] in markov_model: | |
| # We have to just append to the existing histogram | |
| markov_model[data[i]].update([data[i+1]]) | |
| else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| class Dictogram(dict): | |
| def __init__(self, iterable=None): | |
| """Initialize this histogram as a new dict; update with given items""" | |
| super(Dictogram, self).__init__() | |
| self.types = 0 # the number of distinct item types in this histogram | |
| self.tokens = 0 # the total count of all item tokens in this histogram | |
| if iterable: | |
| self.update(iterable) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // ViewController.swift | |
| // KVO_Test | |
| // | |
| // Created by Alexander Dejeu on 1/25/17. | |
| // Copyright © 2017 Do Good Technology. All rights reserved. | |
| // | |
| import UIKit | |
| import WebKit |