This is a JVM port of Kate Compton's story-grammar generator - Tracery
Given the following JSON:
{
"emotion" : ["happy", "sad", "proud"]
}
We can create Grammar
as follows:
String json = ...
Grammar grammar = Tracery.createGrammar(json);
String output = grammar.flatten("#emotion#");
// output is one of "happy", "sad" or "proud"
Input:
{
"sentence": ["The #color# #animal# of the #natureNoun# is called #name#"],
"color": ["orange","blue","white","black","grey","purple","indigo","turquoise"],
"animal": ["unicorn","raven","sparrow","coyote","eagle","owl","zebra","duck","kitten"],
"natureNoun": ["ocean","mountain","forest","cloud","river","tree","sky","sea","desert"],
"name": ["Arjun","Yuuma","Darcy","Mia","Chiaki","Izzi","Azra","Lina"]
}
Code:
Grammar grammar = ...
grammar.flatten("#sentence#");
Possible Output:
The orange zebra of the sky is called Mia
<dependency>
<groupId>com.github.almasb</groupId>
<artifactId>tracery</artifactId>
<version>0.0.1</version>
</dependency>
compile 'com.github.almasb:tracery:0.0.1'
Pre-compiled version available from Releases.
This implementation only loosely follows the original specification by Kate Compton. So, given the same data, the output may differ.