GithubHelp home page GithubHelp logo

martletandco / tracery-go Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 45 KB

An (currently incomplete) implementation of the Tracery text-expansion library by GalaxyKate

License: Apache License 2.0

Go 100.00%

tracery-go's Introduction

tracery-go

An (currently incomplete) implementation of the Tracery text-expansion library by GalaxyKate

import "github.com/martletandco/tracery-go"
g := tracery.NewGrammar()
g.PushRule("toggle", "flop")
g.PushRule("animal", "fox", "dog", "snail", "whale", "cow", "emu")
g.PushRule("pace", "quick", "slow", "sluggard", "rapid", "brisk")
g.PushRule("colour", "brown", "red", "purple", "orange")
g.PushRule("disposition", "lazy", "alert", "bored", "distracted", "eager")
out := g.Flatten("[toggle:flip]The #pace# #colour# #animal# jumped over the #disposition# #animal# to #toggle#[toggle:POP] #toggle#")
fmt.Println(out)

Outputs

The rapid red fox jumped over the eager emu

See in the Go Playground

Note that due to caching and other reasons random numbers to not really work in the playground

List of important features missing

  • Load/save to/from JSON
  • Parse errors
  • Expand for grammar debugging*
  • CBDQ compatibility†
  • (Probably many others that have escaped me just now)

List of less important but still missing features

  • Convenience functions for serialising/deserialising rules
  • A command line wrapper for ad-hock usage
  • Adding rules in bulk
  • Adding modifiers in bulk

List of ideas to explore

  • Symbol/modifier missing handler

  • Improve indefinite article application1

  • Mode option to support new versions or different compatibility

  • Add short hand for an in-place random selection based on [x:1,2,3]#x#

  • *Parses and 'expands' eagerly, rather than lazily as the original does, so I'm not sure the same interface works

  • †Some features are implemented, such as the Random Push (i.e. [x:1,2])

tracery-go's People

Contributors

martletandco avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.