This commit is contained in:
nannal
2020-01-26 21:03:32 +02:00
commit 562b320154
700 changed files with 120537 additions and 0 deletions

1
node_modules/markov/.npmignore generated vendored Normal file
View File

@@ -0,0 +1 @@
node_modules

18
node_modules/markov/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,18 @@
This software is released under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

123
node_modules/markov/README.markdown generated vendored Normal file
View File

@@ -0,0 +1,123 @@
markov
======
Generate markov chains for chatbots and freestyle rap contests.
examples
========
qwantz
------
qwantz.js:
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('> ');
});
});
output:
$ node example/qwantz.js
> Hello friend.
Oh, that hurts me. How could fall apart, not unlike this tiny house. remains a danger when you? As I see him (quite often, Yes, As Thank I you? take have on! forgotten male, That oppression is is a A friend
> That is troubling news!
I've I had must to guard do against with such the a irony part of of their their fundamental fundamental injustices.
> Justice eh? SOMEBODY LIGHT UP THE BATSIGNAL
crazy I Utahraptor feel slipped alot in better! your about problems the put future! behind full You? of go My down perspective. The
methods
=======
markov(order)
-------------
Create a new markov object of order `order`, which defaults to 2.
.seed(s, cb)
------------
Seed the markov object with a string or stream `s`.
If `s` is a string, transition probabilities will be updated for every grouping
of the previously specified order with dangling links at the front and end in
the appropriate direction.
If `s`s is a stream, data events will be line-buffered and fed into `.seed()` again
line-by-line.
If `cb` is specified it will fire once the seed text is fully ingested.
.search(text)
-------------
Search for and return some key found in the text body `text`.
Return `undefined` if no matches were found.
.pick()
-------
Choose a key at random.
.next(key)
----------
Find a key likely to follow after `key`.
Returns a hash with keys `key`, the canonical next key and `word`, a raw form of
`key` as it appeared in the seed text.
.prev(key)
----------
Find a key likely to come before `key`.
Returns a hash with keys `key`, the canonical next key and `word`, a raw form of
`key` as it appeared in the seed text.
.forward(key, limit)
--------------------
Generate a markov chain forward starting at `key` and returning an array of the
raw word forms along the way.
Stop when the traversal hits a terminal entry or when limit words have been
generated if limit is specified.
.backward(key, limit)
---------------------
Generate a markov chain backward starting at `key` and returning an array of the
raw word forms along the way.
Stop when the traversal hits a terminal entry or when limit words have been
generated if limit is specified.
.fill(key, limit)
-----------------
Generate a markov chain in both directions starting at `key`. Return an array of
the raw word forms along the way including the raw word form of the supplied
`key`.
Stop when the traversal hits a terminal entry or when limit words have been
generated if limit is specified.
.respond(text, limit)
---------------------
Search for a starting key in `text` and then call `.fill(key, limit)` on it.

17
node_modules/markov/example/qwantz.js generated vendored Normal file
View File

@@ -0,0 +1,17 @@
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('> ');
});
});

50
node_modules/markov/example/qwantz.txt generated vendored Normal file
View File

@@ -0,0 +1,50 @@
Today is a beautiful day to be stomping on things! As a dinosaur, stomping is the best part of my day indeed!
*gasp*
What's that, little house? You wish you were back in your own time? THAT IS TOO BAD FOR YOU
Perhaps you too will get a stomping little girl!
WAIT!
Is stomping really the answer to your problem(s)?
Problem(s)?
My only problem(s) have to do with you interrupting my stomping!
crazy utahraptor!
With that Utahraptor out of the way I feel better! A rare pleasure indeed, to have your problems put behind you and the future full of promise!
Imagine if that Utahraptor slipped in the shower?
He'd certainly wish he'd stomped the soap out of the way (much as I now stomp this little house) as he passed on!
Perhaps in his last moments, the irony of the situation - from my perspective - would become evident.
Yes, I will freely enjoy stomping more now that he is gone!
Stop!
You?
You have retreated too far into the realm of fantasy and have forgotten that I did not in fact expire in the shower!
I must guard against such self-absorption in the future!
I GUESS THERE IS A LESSON HERE FOR US ALL!
I feel today that my actions will be charged with symbolism.
*gasp*
As a male, I take on the position of the Everyman - with the latter syllable perhaps most important from our post-feminist perspective. The house clearly represents repressed feminity, at once recalling the blissful days of the past, while reminding us of their fundamental injustices.
My action in destroying the house remains a puzzling enigma.
The emphasis on male oppression is continued as I stand poised to crush this woman beneath my man-foot.
No!
I've always seen you as representing the essential struggle between man and his darker half.
Oh, that is a part of it, to be sure.
...but the desires of my darker nature manifest themselves as misogyny!
Surely that must enter into your analysis!
I had a friend (female) who dated her roommate (also female).
Lesbians!
Of course, there's always a danger when you go down the 'date-the-person-you-live-with' road. It could fall apart, not unlike this tiny house.
They broke up a week later and still had to live together.
The sting of a failed romance!
I know it well.
I too have consummated my love for my roommate of the same gender. Now when I see him (quite often, as it turns out) there is a tension that hurts me.
Right here.
Later...
!
The realization that I've had a homosexual affair with the Utahraptor THAT I CANNOT REMEMBER AT ALL profoundly disturbs me. How could I forget such a thing?
I wonder what it was like? Maybe I was really good!
Or MAYBE he's making the whole thing up! That would explain why I don't remember it.
Extraordinary claims require extraordinary proof.
Yes! Thank you!
I feel alot better about the whole thing now.
But I have proof!
You? What manner of proof have you?
Uh
well
*gasp*

199
node_modules/markov/index.js generated vendored Normal file
View File

@@ -0,0 +1,199 @@
var EventEmitter = require('events').EventEmitter;
var deck = require('deck');
var Lazy = require('lazy');
var Hash = require('hashish');
module.exports = function (order) {
if (!order) order = 2;
var db = {};
var self = {};
self.seed = function (seed, cb) {
if (seed instanceof EventEmitter) {
Lazy(seed).lines.forEach(self.seed);
if (cb) {
seed.on('error', cb);
seed.on('end', cb);
}
}
else {
var text = (Buffer.isBuffer(seed) ? seed.toString() : seed)
var words = text.split(/\s+/);
var links = [];
for (var i = 0; i < words.length; i += order) {
var link = words.slice(i, i + order).join(' ');
links.push(link);
}
if (links.length <= 1) {
if (cb) cb(null);
return;
}
for (var i = 1; i < links.length; i++) {
var word = links[i-1];
var cword = clean(word);
var next = links[i];
var cnext = clean(next);
var node = Hash.has(db, cword)
? db[cword]
: {
count : 0,
words : {},
next : {},
prev : {},
}
;
db[cword] = node;
node.count ++;
node.words[word] = (
Hash.has(node.words, word) ? node.words[word] : 0
) + 1;
node.next[cnext] = (
Hash.has(node.next, cnext) ? node.next[cnext] : 0
) + 1
if (i > 1) {
var prev = clean(links[i-2]);
node.prev[prev] = (
Hash.has(node.prev, prev) ? node.prev[prev] : 0
) + 1;
}
else {
node.prev[''] = (node.prev[''] || 0) + 1;
}
}
if (!Hash.has(db, cnext)) db[cnext] = {
count : 1,
words : {},
next : { '' : 0 },
prev : {},
};
var n = db[cnext];
n.words[next] = (Hash.has(n.words, next) ? n.words[next] : 0) + 1;
n.prev[cword] = (Hash.has(n.prev, cword) ? n.prev[cword] : 0) + 1;
n.next[''] = (n.next[''] || 0) + 1;
if (cb) cb(null);
}
};
self.search = function (text) {
var words = text.split(/\s+/);
// find a starting point...
var start = null;
var groups = {};
for (var i = 0; i < words.length; i += order) {
var word = clean(words.slice(i, i + order).join(' '));
if (Hash.has(db, word)) groups[word] = db[word].count;
}
return deck.pick(groups);
};
self.pick = function () {
return deck.pick(Object.keys(db))
};
self.next = function (cur) {
if (!cur || !db[cur]) return undefined;
var next = deck.pick(db[cur].next);
return next && {
key : next,
word : deck.pick(db[next].words),
} || undefined;
};
self.prev = function (cur) {
if (!cur || !db[cur]) return undefined;
var prev = deck.pick(db[cur].prev);
return prev && {
key : prev,
word : deck.pick(db[prev].words),
} || undefined;
};
self.forward = function (cur, limit) {
var res = [];
while (cur && !limit || res.length < limit) {
var next = self.next(cur);
if (!next) break;
cur = next.key;
res.push(next.word);
}
return res;
};
self.backward = function (cur, limit) {
var res = [];
while (cur && !limit || res.length < limit) {
var prev = self.prev(cur);
if (!prev) break;
cur = prev.key;
res.unshift(prev.word);
}
return res;
};
self.fill = function (cur, limit) {
var res = [ deck.pick(db[cur].words) ];
if (!res[0]) return [];
if (limit && res.length >= limit) return res;;
var pcur = cur;
var ncur = cur;
while (pcur || ncur) {
if (pcur) {
var prev = self.prev(pcur);
pcur = null;
if (prev) {
pcur = prev.key;
res.unshift(prev.word);
if (limit && res.length >= limit) break;
}
}
if (ncur) {
var next = self.next(ncur);
ncur = null;
if (next) {
ncur = next.key;
res.unshift(next.word);
if (limit && res.length >= limit) break;
}
}
}
return res;
};
self.respond = function (text, limit) {
var cur = self.search(text) || self.pick();
return self.fill(cur, limit);
};
self.word = function (cur) {
return db[cur] && deck.pick(db[cur].words);
};
return self;
};
function clean (s) {
return s
.toLowerCase()
.replace(/[^a-z\d]+/g, '_')
.replace(/^_/, '')
.replace(/_$/, '')
;
}

64
node_modules/markov/package.json generated vendored Normal file
View File

@@ -0,0 +1,64 @@
{
"_from": "markov",
"_id": "markov@0.0.7",
"_inBundle": false,
"_integrity": "sha1-NazoKuJhM/cZ4WCNIfDLwhRSq+M=",
"_location": "/markov",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "markov",
"name": "markov",
"escapedName": "markov",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/markov/-/markov-0.0.7.tgz",
"_shasum": "35ace82ae26133f719e1608d21f0cbc21452abe3",
"_spec": "markov",
"_where": "/home/dabbott/dev/chainy",
"author": {
"name": "James Halliday",
"email": "mail@substack.net",
"url": "http://substack.net"
},
"bugs": {
"url": "https://github.com/substack/node-markov/issues"
},
"bundleDependencies": false,
"dependencies": {
"deck": ">=0.0.3",
"hashish": ">=0.0.2",
"lazy": ">=1.0.3"
},
"deprecated": false,
"description": "Silly markov chatbot module",
"devDependencies": {
"tape": "~1.1.1"
},
"directories": {
"lib": ".",
"example": "./example"
},
"engines": {
"node": ">=0.4.0"
},
"homepage": "https://github.com/substack/node-markov#readme",
"license": "MIT",
"main": "./index.js",
"name": "markov",
"repository": {
"type": "git",
"url": "git://github.com/substack/node-markov.git"
},
"scripts": {
"test": "tape test/*.js"
},
"version": "0.0.7"
}

34
node_modules/markov/test/cycles.js generated vendored Normal file
View File

@@ -0,0 +1,34 @@
var test = require('tape');
var markov = require('../');
var fs = require('fs');
test('cycles', function (t) {
var to = setTimeout(function () {
t.fail('never finished');
}, 5000);
var m = markov(1);
var these = 'the THE tHe ThE thE The';
m.seed(these, function () {
clearTimeout(to);
var counts = {};
for (var i = 0; i < 100; i++) {
var res = m.respond('the', 100);
t.ok(res.length < 100);
res.forEach(function (r) {
t.ok(these.split(' ').indexOf(r) >= 0);
counts[r] = (counts[r] || 0) + 1;
});
}
t.deepEqual(
Object.keys(counts).sort(),
these.split(' ').sort()
);
t.end();
});
});

34
node_modules/markov/test/has.js generated vendored Normal file
View File

@@ -0,0 +1,34 @@
var test = require('tape');
var markov = require('../');
var fs = require('fs');
test('has', function (t) {
var to = setTimeout(function () {
t.fail('never finished');
}, 5000);
var m = markov(1);
var these = 'constructor toLocaleString valueOf __defineGetter__';
m.seed(these, function () {
clearTimeout(to);
var counts = {};
for (var i = 0; i < 100; i++) {
var res = m.respond('the', 100);
t.ok(res.length < 100);
res.forEach(function (r) {
t.ok(these.split(' ').indexOf(r) >= 0);
counts[r] = (counts[r] || 0) + 1;
});
}
t.deepEqual(
Object.keys(counts).sort(),
these.split(' ').sort()
);
t.end();
});
});

30
node_modules/markov/test/limit.js generated vendored Normal file
View File

@@ -0,0 +1,30 @@
var test = require('tape');
var markov = require('../');
var fs = require('fs');
test('limit', function (t) {
var to = setTimeout(function () {
t.fail('never finished');
}, 5000);
var m = markov(1);
var these = 'the THE tHe ThE thE The the THE The tHE the the';
m.seed(these, function () {
clearTimeout(to);
var counts = {};
for (var i = 0; i < 100; i++) {
var lim = Math.ceil(Math.random() * 10);
var res = m.respond('the', lim);
t.ok(res.length <= lim);
res.forEach(function (r) {
t.ok(these.split(' ').indexOf(r) >= 0);
counts[r] = (counts[r] || 0) + 1;
});
}
t.end();
});
});

42
node_modules/markov/test/order.js generated vendored Normal file
View File

@@ -0,0 +1,42 @@
var test = require('tape');
var markov = require('../');
test('order1', function (t) {
t.plan(5);
var m = markov(1);
m.seed('This is a test.');
t.equal(
m.search('What IS your problem?'),
'is'
);
t.ok(m.search('foo bar baz zing') === undefined);
t.ok('this is a test'.split(' ').indexOf(m.pick()) >= 0);
t.deepEqual(
m.next('is'),
{ word : 'a', key : 'a' }
);
t.deepEqual(
m.prev('is'),
{ word : 'This', key : 'this' }
);
});
test('order2', function (t) {
t.plan(2);
var m = markov(2);
m.seed('This is a test.');
t.deepEqual(
m.next('this_is'),
{ word : 'a test.', key : 'a_test' }
);
t.deepEqual(
m.prev('a_test'),
{ word : 'This is', key : 'this_is' }
);
});

40
node_modules/markov/test/stream.js generated vendored Normal file
View File

@@ -0,0 +1,40 @@
var test = require('tape');
var markov = require('../');
var EventEmitter = require('events').EventEmitter;
test('stream', function (t) {
t.plan(3);
var m = markov(1);
var to = setTimeout(function () {
t.fail('never finished');
}, 5000);
var em = new EventEmitter;
m.seed(em, function () {
clearTimeout(to);
var counts = {};
for (var i = 0; i < 100; i++) {
var w = m.next('the');
counts[w.key] = (counts[w.key] || 0) + 1;
}
t.deepEqual(Object.keys(counts).sort(), [ 'cat', 'cow' ]);
t.ok(40 <= counts.cat && counts.cat <= 60);
t.ok(40 <= counts.cow && counts.cow <= 60);
});
setTimeout(function () {
em.emit('data', 'The cow says');
}, 100);
setTimeout(function () {
em.emit('data', 'moo.\nThe ');
}, 150);
setTimeout(function () {
em.emit('data', 'cat says meow.\n');
em.emit('end');
}, 200);
});