Dessert of the Real: A Pre-Partum

After a sprint Monday afternoon, I prepared a proof of concept for my upcoming generative fan-non-fiction adventure based on the works of Slavoj Žižek: Dessert of the Real. I brought it to a local demo night for indie developers, but had little courage (and still less success) presenting it to attendees; I took the opportunity to tweet about it since it was functional and deployed.

A couple people asked about its functioning (and someone broke my server trying to figure it out on their own) so here is a pre-partum on its current design. Ideally, I’ll clean up the general hackiness and provide a re-usable project for others to generate similar experiences using different corpora, but that isn’t the shape it’s currently in. Right now, it goes a little something like this:

Building Blocks

We begin with a folder full of text files which make up the corpus, with Markdown formatting and two linebreaks between each excerpt. In this case: the text of 6 Žižek books (The Puppet and The Dwarf; The Year of Dreaming Dangerously; Violence; Tarrying With the Negative; First as Tragedy, Then as Farce; and The Parallax View) which have been manually massaged to remove end-note annotations and to trim excerpts to a very imprecise “reasonable length.” These source files themselves are not available on the GitHub page or on the deployed server (for obvious reasons.)

We next want a list of common terms to use as links between excerpts. The list for Dessert of the Real is found in zizekKeys.js, which is an object with many named regular expressions. In theory, generating a usable index programatically is possible, but it’s done manually in this case. Utilizing perl-like look-behinds within Javascript regular expressions would make this index more robust (avoiding conflicts of like phrases) and is planned as an improvement (if practical.)

Stacking Them Up

With these two elementary components, we can create a database of excerpts, each featuring an array of the keywords found within, something like:

With this database, we can make a rudimentary API to serve a random excerpt featuring a target keyword:

Showing Them Off

With this, all that’s left is presentation and interface on the front-end. I’m using Undum, a hypertext library designed for interactive fiction, which features a Situation/Action model for changing state. In my current version, each new excerpt is a dynamically generated Situation, given the name of the target keyword. This complicates some things, particularly breaking Undum’s “Save” and “Restore” functionality, but was the simplest approach from an implementation standpoint.

The changes to Undum for minimum viable behavior were: one change to a regular expression, one conditional check, and a short function to POST the request to our corpus server. Links to “make” a Situation based on the corpus server’s result are identified by the format ./%keyword—so we add % as an acceptable character for link verification, check if it’s present when processing a link, and shunt flow to our makeThenGo() function if so.

And so on…

This is the core functionality, though if you’ve played through (please do! I check logs to find targets for further development prior to final release) you may notice some Žižekian content which isn’t lifted directly from the corpus. These are composed using a node port of Matthew Boston‘s “trigrams” library, and a slight modification of Nathaniel K. Smith‘s prosaic.

There’s quite a bit still to do with Dessert of the Real, and much more to make a somewhat more “turn-key” system for others to use, but the fundamentals of the structure are strong, and relatively straight-forward. I’m looking forward to more imaginative work with corpora and generative text in the future.