.NET port of Kate Compton's Tracery. Now on NuGet!
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
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 can be used as a source instead of JSON:
---
origin: "#sentence#"
sentence: "#greeting# #place#"
place:
- "world"
- "galaxy"
- "universe"
greeting:
- "Hello"
- "Hey"
- "Sup"
Feature | Status |
---|---|
Capitalize All | ✔️ |
Capitalize | ✔️ |
In Quotes | ✔️ |
Comma | ✔️ |
🐝 Speak | ✔️ |
Pluralize | ✔️ |
Past-tensifiy | ✔️ |
Custom modifiers | ✔️ |
Saving data & actions | ✔️ |