Skip to content

HelloMichaelLoke/grammy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

This is a JVM port of Kate Compton's story-grammar generator - Tracery

Maven Build Status codecov

Usage

Example 1

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"

Example 2

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

Maven

<dependency>
    <groupId>com.github.almasb</groupId>
    <artifactId>tracery</artifactId>
    <version>0.0.1</version>
</dependency>

Gradle

compile 'com.github.almasb:tracery:0.0.1'

Uber-jar

Pre-compiled version available from Releases.

Notes

This implementation only loosely follows the original specification by Kate Compton. So, given the same data, the output may differ.

Contact

Gmail

Packages

No packages published

Languages

  • Kotlin 97.2%
  • Java 2.8%