Skip to content

josh-perry/Tracery.Net

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status NuGet version

Tracery.Net

.NET port of Kate Compton's Tracery. Now on NuGet!

Minimal example

var grammar = new TraceryNet.Grammar(new FileInfo("grammar.json"));
var output = grammar.Flatten("#origin#");
Console.WriteLine(output);

Where grammar.json is:

{
    "origin": "The #person# was feeling... #mood#",
    "person": ["girl", "dwarf", "cat", "dragon"],
    "mood": ["bashful", "dopey", "happy", "sleepy", "sneezy", "grumpy"]
}

Example outputs:

The dwarf was feeling grumpy.
The girl was feeling sneezy.
The girl was feeling sleepy.
The dwarf was feeling grumpy.
The dragon was feeling dopey.

See TraceryNetExample project for more

Custom modifiers

var json = "{" +
           "    'origin': '#sentence.toUpper#'," +
           "    'sentence': 'hello cat'" +
           "}";

var grammar = new TraceryNet.Grammar(json);
grammar.AddModifier("toUpper", modifier);

var output = grammar.Flatten("#origin#");

Where modifier is something like this:

Func<string, string> modifier = delegate (string i)
{
    return i.ToUpper();
};

Output:

HELLO CAT

YAML

YAML can be used as a source instead of JSON:

--- 
origin: "#sentence#"
sentence: "#greeting# #place#"
place:
  - "world"
  - "galaxy"
  - "universe"
greeting:
  - "Hello"
  - "Hey"
  - "Sup"

Status

Feature Status
Capitalize All ✔️
Capitalize ✔️
In Quotes ✔️
Comma ✔️
🐝 Speak ✔️
Pluralize ✔️
Past-tensifiy ✔️
Custom modifiers ✔️
Saving data & actions ✔️

About

.NET port of Kate Compton's Tracery

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published