This file contains 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 markov | |
from markov import Markov | |
def generate_model(filename='document1.txt'): | |
f = open(filename) | |
return Markov(f) | |
markov = generate_model() | |
print markov.generate_markov_text() |
This file contains 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 nltk | |
from nltk.tokenize import word_tokenize | |
from nltk.probability import LidstoneProbDist | |
from nltk.model import NgramModel | |
import re | |
def generate_text(model, number_words=15): | |
text_words = model.generate(number_words) | |
return ' '.join([word for word in text_words]) |
This file contains 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
var cheerio = require('cheerio'); | |
var request = require('request'); | |
var _ = require('underscore'); | |
var getNumPages = function(id){ | |
return getThreadPage(id).then(function(page){ | |
var $ = cheerio.load(page); | |
var numPages = $('.topic-actions .pagination span a').last().text(); | |
numPages = numPages ? parseInt(numPages) : 1; | |
return numPages; |
This file contains 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
//Style Guide: | |
//https://github.com/makersquare/student-wiki/wiki/Style-Guide | |
//Keep things consistent. Makes reading your code a lot easier. | |
//1. Quotes. Decide on single or double. | |
//2. Functions. Space after parens. | |
//Choose one. | |
function() {...} |
This file contains 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
var filter = function(collection, predicate){ | |
var results = []; | |
each(collection, function(val){ | |
if (predicate(val)) results.push(val); | |
}); | |
return results; | |
}; |