Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

qwantz example for testing, doesn't quite work yet

  • Loading branch information...
commit 2818e9c08fa33f279f0510ae1cc7e3d6b8b39cb2 1 parent 4629d45
@substack authored
8 README.markdown
@@ -3,4 +3,10 @@ markov
Generate markov chains for chatbots and freestyle rap contests.
-Work in progress.
17 example/qwantz.js
@@ -0,0 +1,17 @@
+var util = require('util');
+var fs = require('fs');
+var markov = require('markov');
+var m = markov(2);
+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());
+ console.log(res);
+ util.print('> ');
+ });
50 example/qwantz.txt
@@ -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!
+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!
+Is stomping really the answer to your 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!
+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 feel today that my actions will be charged with symbolism.
+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.
+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).
+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.
+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?
37 index.js
@@ -96,6 +96,43 @@ module.exports = function (order) {
} || undefined;
+ self.forward = function (cur, limit) {
+ var res = [];
+ do {
+ var next =;
+ if (next) {
+ cur = next.key;
+ res.push(next.word);
+ }
+ } while (next && limit === 0 || res.length < limit)
+ return res;
+ };
+ self.backward = function (cur, limit) {
+ var res = [];
+ do {
+ var prev = self.prev(cur);
+ if (prev) {
+ cur = prev.key;
+ res.unshift(prev.word);
+ }
+ } while (prev && limit === 0 || res.length < limit)
+ return res;
+ };
+ self.fill = function (cur, limit) {
+ var f = self.forward(cur, limit);
+ var b = self.backward(cur, limit - f.length);
+ return b.concat(f);
+ };
+ self.respond = function (text, limit) {
+ var cur = || self.pick();
+ return self.fill(cur, limit);
+ };
return self;
3  package.json
@@ -8,7 +8,8 @@
"main" : "./index.js",
"directories" : {
- "lib" : "."
+ "lib" : ".",
+ "example" : "./example"
"scripts" : {
"test" : "expresso"
Please sign in to comment.
Something went wrong with that request. Please try again.