headshot of andytuba (they or he)

   

Tracery in action

We can write a Tracery grammar which provides the template.

A quick example 🥪 #

First, start with a plain sentence:

"We go together like peanut butter and strawberry jelly.

Now identify parts of the sentence that could be replaced with other words or phrases.

We go together like peanut some nut butter and strawberry some fruit jelly.

Now that you have a template with placeholders ...

We go together like some nut butter and some fruit jelly.

... what options can go in the placeholders?

Options for some nut:

Options for some fruit:


Tracery grammar representation of this 🥪 sandwich #

Tracery grammars are represented as { "json": blobs }.
The main template is the "origin" value.
The placeholders are marked off with #hash signs#.
The options for the placeholders go in the "placeholder's value".

{
"origin": "We go together like #some nut# butter and #some fruit# jelly.",
"some nut": ["peanut", "almond", "avocado", "tree nut"],
"some fruit": ["strawberry", "raspberry", "avocado", "snozzberry"]
}

Potential variations #

If we asked a 🤖Tracery engine to flatten that grammar into a final product, we might come out with results like:

Demo: tracery.io editor #

Let's do it live: copy-paste the grammar, then click the "reroll" button.

Demo: emptyjug.xxx/tracery #

(Click the 🎲 button.)