exports.has = function () { var to = setTimeout(function () { assert.fail('never finished'); }, 5000); var m = markov(1); var these = 'constructor __proto__ toLocaleString valueOf __defineGetter__'; m.seed(these, function () { clearTimeout(to); var counts = {}; for (var i = 0; i < 100; i++) { var res = m.respond('the', 100); assert.ok(res.length < 100); res.forEach(function (r) { assert.ok(these.split(' ').indexOf(r) >= 0); counts[r] = (counts[r] || 0) + 1; }); } assert.eql( Object.keys(counts).sort(), these.split(' ').sort() ); }); };
log.all('SELECT message FROM log ORDER BY RANDOM() LIMIT 1000',(e,r) => { var words = r.map(d => d.message).join(' '); var seed = query || words.split(' ').pop(); var m = markov(1); var qty = ((Math.random()*20)|0); m.seed(words, () => { var resp = m.respond(seed); resp.splice(qty); client.say(to, resp.join(' ')) }) })
exports.init = function (config, events) { events.emit('debug', 'markov', 'initializing markov plugin'); if (!config.markov) { return events.emit('error', 'markov', 'Missing markov property in config' ); } if (!config.irc.nick) { return events.emit('error', 'markov', 'Missing irc.nick property in config' ); } var m = markov(1); events.emit('info', 'markov', 'reading markov seed data'); var s = fs.createReadStream(__dirname + '/../' + config.markov); m.seed(s, function (err) { if (err) { return events.emit('error', 'markov', err); } events.emit('info', 'markov', 'markov seed data loaded'); var nick = config.irc.nick; events.on('irc::message', function (from, to, message) { if (new RegExp('^\\s*' + nick + '[\\s:]').test(message)) { events.emit('debug', 'markov', 'message @ bot'); var res = m.respond(message.toString()).join(' '); events.emit('debug', 'markov', 'response: ' + res); events.emit('say', res); } else { events.emit('debug', 'markov', 'message not @ bot'); } }); }); };
twitter.verifyCredentials(function (err, user) { if (err) throw err; var m = markov(); home.tail(0, {load: true}, processChunk); function processChunk (err, chunk, next) { if (err) throw err; chunk.forEach(function (tweet) { m.seed(tweet.text); }); if (chunk.length && next) next(); } twitter.stream('user', {'with': 'followings', 'replies': 'all'}, function (stream) { stream.on('data', function (data) { if (data.text) { m.seed(data.text, function () { if (data.in_reply_to_screen_name === user.screen_name) { // respond var words = ['@' + data.user.screen_name].concat(stripMentions(m.respond(data.text, 100))); var text = createTweet(words); twitter.updateStatus(text, function (err, data) { if (err) throw err; console.log('tweeted:', data.text || data); }); } }); } }); stream.on('end', function (response) { // Handle a disconnection }); stream.on('destroy', function (response) { // Handle a 'silent' disconnection from Twitter, no end/error event fired }); }); });
#!/usr/bin/env node var cheerio = require('cheerio'); var jsdom = require('jsdom'); var request = require('request'); var pictureTube = require('picture-tube'); var mq = require('./rabbitconfix'); var exec = require('child_process').exec; var sys = require('sys'); var http = require('http'); var markov = require('markov'); var m = markov(2); var playing = 0; //var speak = "/Users/thorsten/Downloads/espeak-1.45.04-OSX/espeak-1.45.04/speak -k10 -s 150 --path=/Users/thorsten/Downloads/espeak-1.45.04-OSX/espeak-1.45.04/ "; //var speak = "/usr/local/bin/speak -k10 -s 150 -ven-us "; //var speak = "/usr/local/bin/speak -k20 -p 10 -ven-us+m2 "; //var speak = "speak -ven-pt "; var speak = "speak -ven-sbd -g10 "; if (typeof process.argv[2] == 'undefined') { console.log("OI! gimme a search term.."); process.exit(1); } var srchTerm = process.argv[2]; srchTerm = encodeURIComponent(srchTerm); var rapLyricsURL = 'http://research.blackyouthproject.com/raplyrics/'; var lyricsLinks = []; var lyricsCounter = 0;
'use strict'; /** * Dependencies */ var fs = require('fs'); var markov = require('markov'); var m = markov(); var s = fs.createReadStream(__dirname + '/dependency-invertion.txt'); m.seed(s, function () { var stdin = process.openStdin(); stdin.on('data', function (line) { var keys = line.toString(); var res = m.respond(keys, 5).join(' ').toLowerCase(); console.log(res); }); });
var util = require('util'); var fs = require('fs'); var markov = require('markov'); var m = markov(1); var s = fs.createReadStream(__dirname + '/qwantz.txt'); m.seed(s, function () { var stdin = process.openStdin(); util.print('> '); stdin.on('data', function (line) { var res = m.respond(line.toString()).join(' '); console.log(res); util.print('> '); }); });
var fs = require('fs'); var path = require('path'); var util = require('util'); var markov = require('markov'); var MeatBot = require('meatbot'); var keywords = ["weed-gif","420-gif"]; var chatter = markov(); var logs = path.join(__dirname, "qwantz.txt"); var learnFileIn = fs.createReadStream(logs); var learnFile = fs.createWriteStream(logs, {flags: 'r+'}); var avatar = fs.readFileSync(path.join(__dirname, 'avatar.txt'), 'utf8'); chatter.seed(learnFileIn); function BlazeBot() { MeatBot.call(this); this.on('message', function(msg) { if (msg.message.indexOf(this.name) !== -1) return; chatter.seed(msg.message); learnFile.write(msg.message+"\r\n"); }.bind(this)); } util.inherits(BlazeBot, MeatBot); BlazeBot.prototype.name = "uncle blazer"; BlazeBot.prototype.fingerprint = 420; BlazeBot.prototype.avatar = avatar;
function gridFromIncrMarkov(cb) { function inboundPaths(row, col, grid, n) { // starting at origin X, find inbound paths of length n: // ............. // ......o...... // .....ooo..... // ....ooooo.... // ...oooXooo... // ....ooooo.... // A move is a tuple of [row offset, column offset] var moves = [ [-1, 0], // up [ 1, 0], // down [ 0, -1], // left [ 0, 1], // right [-1, -1], // upleft [ 1, -1], // downleft [-1, 1], // upright [ 1, 1], // downright ]; // A path is a set of positions. // // Compute by starting at a [row, column] origin // and then advancing along a set of moves. // // We then drop the initial [row, column] origin and // reverse the set of positions, which gives us // the inbound path exclusive of the origin. function findInboundPath(moves) { return _.rest(_.reduce(moves, function(positionsAcc, move) { positionsAcc.push([_.last(positionsAcc)[0] + move[0], _.last(positionsAcc)[1] + move[1]]); return positionsAcc; }, [[row, col]])).reverse(); } // A position is reachable if it is inside the grid function reachable(position) { return position[0] >= 0 && grid.length > position[0] && // row is reachable position[1] >= 0 && grid[0].length > position[1]; // column is reachable } function pathReachable(path) { return _.all(path, reachable); } // Deep compare arrays using string representation function canonicalizeArray(array) { return "" + array; }; function pathNoncrossing(path) { var uniquePositions = _.unique(path, false, canonicalizeArray); return path.length === uniquePositions.length } function pathExcludesOrigin(path) { return _.all(path, function(position) { return ! (position[0] === row && position[1] === col); }); } var movelists = Combinatorics.baseN(moves, n).toArray(); var paths = _.map(movelists, findInboundPath); return _.select(paths, function(path) { return pathReachable(path) && pathNoncrossing(path) && pathExcludesOrigin(path); }); } var markovOrder = 2; var fs = require('fs'); var markov = require('markov'); var m = markov(markovOrder); var m1 = markov(1); // var s = fs.createReadStream(__dirname + '/norvig/spacey_1000.txt'); function getWords() { return fs.createReadStream('/Users/jason/dev/wordgames/gridmaker/norvig/spacey_1000.txt'); } var grid = []; var width = 40; function independentMarkovLine() { var line = []; while (line.length < width) { var more = m1.fill(m1.pick(), width); line = _.flatten([line, more]); } return _.take(line, width); } var util = require("util"); function log(x) { console.log(util.inspect(x, false, null)); } m.seed(getWords(), function() { m1.seed(getWords(), function() { // var pick = m.pick(); // console.log(pick); // console.log(m.next("e_n_v")); // throw "asdf"; // TODO for some reason this is destructive // function drawFreqs(inb, grid1) { // _.each(inb, function(path) { // _.each(path, function(position) { // grid1[position[0]][position[1]] = 0; // }); // }); // _.each(inb, function(path) { // _.each(path, function(position) { // grid1[position[0]][position[1]] = grid1[position[0]][position[1]] + 1; // }); // }); // printGrid(grid1); // } function genByInbound(row, col) { var inb = inboundPaths(row, col, grid, markovOrder); var markovKeys = _.map(inb, function(path) { return _.map(path, function(position) { return grid[position[0]][position[1]]; }).join("_"); }); var generateds = _.map(markovKeys, function(key) { var next = m.next(key); return next && next.word && next.word[0]; }); var choices = _.without(generateds, undefined); // drawFreqs(inb, _.clone(grid)); // log(_.zip(inb, markovKeys, generateds)); // log(choices); // console.log(""); return _.sample(choices) || m1.pick() || 'a'; // TODO: why default } // seed grid with one line grid.push(independentMarkovLine()); function genRowByInbound() { var row = []; for (var col = 0; col < width; col++) { row.push(genByInbound(grid.length, col)); } return row; } _.times(9, function() { grid.push(genRowByInbound()); }); cb(grid); }); }); };
import random from 'lodash/number/random'; import photos from './photos'; // names generated by chance.js const users = [ {avatar: "marc", name: "Marc Stone"}, {avatar: "ellen", name: "Ellen Clayton"}, {avatar: "ruth", name: "Ruth Maxwell"}, {avatar: "ray", name: "Ray Scott"}, {avatar: "sam", name: "Sam Munoz"}, {avatar: "craig", name: "Craig Robbins"}, {avatar: "lillie", name: "Lillie Wolfe"}, {avatar: "susan", name: "Susan Keller"} ]; const markov = markovCreator(3); export const generateReady = new Promise(resolve => { markov.seed(fs.createReadStream(__dirname + '/seed.txt'), resolve); }); export function generateMessage() { const message = {}; const user = users[Math.floor(Math.random() * users.length)]; let image; if (Math.random() < 0.2) { image = photos[Math.floor(Math.random() * photos.length)]; } message.id = Number(String(random(1, 10000)) + Date.now()).toString(36); message.avatar = '/avatars/' + user.avatar;
xhr.onreadystatechange = function() { if(xhr.readyState === 4 && xhr.status === 200) { document.querySelector('#iterate').disabled = false; var data = xhr.responseText; data = data.split('\n').map(d => d.split(' ')); data = data.map(d => ({action: d[0], note: d[1], time: d[2]})); let section = [[]]; let duration = 0; for(let i = 0; i < data.length; i++) { if(data[i].action === 'ON') { let start = parseFloat(data[i].time); //Assumes that every other note is off let stop = parseFloat(data[i+1].time); duration += Math.abs((start-stop)); if(duration <= 1) { section[section.length-1].push(new Note(data[i].note, Math.abs(start-stop))); } else { section.push([]); duration = 0; } } } //Create bars out of all notes into the section array section = new Section( section.map(s => new Bar(s.map(n => n)) ) ); //Push all notes from all bars to notes array section.bars.forEach(bar => song.push(...bar.notes)); song = song.filter(n => n.note); setGraphLanes(); //Merge all notes to sentences inputSongString = song.filter(n => n.duration > 0) .map(n => n.duration + "-" + n.note.name() + n.octave) .join(' '); merged = inputSongString.replace(/\./g, 'q'); let chain = new MarkovChain(); chain.generateChain(merged); let m = markov(2); m.seed(merged); let coupleProb = m.db(); let tempProb = {}; for(var key in coupleProb) { let formatedKey = key.match(/\dq\d*_.\d_(\dq\d*_.\d)/) ? key.match(/\dq\d*_.\d_(\dq\d*_.\d)/)[1] : ''; if(formatedKey) { for(var notes in coupleProb[key].next) { if(notes.match(/\dq\d*_.\d/g)) { notes = notes.match(/\dq\d*_.\d/g).map(note => note.replace('_', '-')); tempProb[formatedKey.replace('_', '-')] = notes } } } } coupleProb = tempProb; //Markov probabilites for all notes const probabilities = JSON.parse(chain.dump()); //Give the rules for all notes song.forEach(n => setNoteRules(probabilities, n, 1)); song.forEach(n => setNoteRules(coupleProb, n, 2)); song = song.filter(n => n.duration > 0); } }