.github/workflows | ||
data | ||
img | ||
scribblings | ||
src | ||
.gitignore | ||
info.rkt | ||
LICENSE | ||
main.rkt | ||
README.org |
MRG is a template based text generator closely following the perchance grammar and borrowing features (or non-features) from similar generators such as rant, tracery, lorem ipsum, dada engine etc. MRG aims to be simple to use and easy to read. Extensibility is possible but shouldn’t be at the expense of readability or simplicity. Extraneous syntax is kept to a minimum.
Generators are usually built around substitution from lists (such as this example from the perchance documentation).
output
Your [pack] contains [item], [item] and [item].
pack
purse
backpack
bag
pack
knapsack
rucksack
item
a few coins
an old {silver|bronze} ring
a handkerchief
a shard of bone
some lint
a tin of tea leaves
This template generates sentences like “Your purse contains some lint, a few coins and a handkerchief.” or “Your knapsack contains a few coins, a shard of bones and an old silver ring.”
Writing templates
Templates are written in plain text with placeholders for text that can be replaced. They are usually based around lists of words or phrases. Special characters are limited to the square and curly brackets. i.e. “[ ]” and “{ }”. Some examples can be found in the data folder
The inclusion of a word in square brackets, like [word]
will select something from the list
called word
. A list begins with a single
word label and is followed by lines indented with 2 spaces.
Curly brackets can be used to indicate a choice, {this|that|the other}
or a range of numbers
{1-101}
and can be used to generate the
correct article or plural for a word using {a}
or {s}
(e.g.
fish{s}
generates “fishes” and ox{s}
generates “oxen”)
There are a few modifier functions that can be used to filter the
output such as [word.modifier]
(e.g..
[mouse.plural]
give “mice” or [mouse.upcase]
gives “MOUSE”)
A template needs to include an output
label with at least one item. An element is chosen randomly from the
output
list and used to generate a single
output text.
output
one word
The output
items can select from a list
like so…
output
[word]
word
lonely
Install
The package can be installed via the racket package manager
racp pkg install moonrat
or installed manually from github
git clone https://github.com/zzkt/moonrat
There an emacs mode for editing templates included (which can be installed via melpa)
package install moonrat M-x
and configured as required…
use-package moonrat
(setq moonrat-command "raco moonrat") ;; or “moonrat -v“
:init ("\\.mg\\'" . moonrat-mode))
:mode ((
:bind (:map moonrat-mode-map"C-c g" . moonrat-generate))) (
Generate
Save a template in a file and run moonrat
to generate text on the command
line…
raco moonrat data/music-genre.mg
further details…
raco moonrat -h
or from a racket programme
#lang racket
(require moonrat)
(load-generator-file "music-genre.mg")
(generate)
Moon Grade Ranter
Darius Kazemi has compiled a collection of copora for “the creation of weird internet stuff” specifically for text generation. MRG includes a basic conversion utility to help use the corpora lists with moonrat. The converted lists are not validated in any way and will almost certainly need some manual coercion to be useful.
copora can be converted from a given url or file…
raco cp2mg -u https://raw.githubusercontent.com/dariusk/corpora/master/data/colors/fictional.json
raco cp2mg -f data/corpora/interjections.json -o data/interjections.mg
Weird Machinery
The templates are almost certainly a weird machine capable of unexpected machinations using list substitution (well formed recursive lists) and choice (even without assignment). Implementation is left as an exercise for the reader (see also string rewriting and antigram)
Syntax, grammar and reference
output
a word
a [word]
{word|another word}
{a} thing
some thing{s}
a [word.plural]
[the four word title.title-case]
a [nested.list.word]
// comments are on a line by themselves (not yet inline)
(to be continued…)
links & further
Included, precluded, transcluded and occluded…