LexiconLang.Core
1.5.0
dotnet add package LexiconLang.Core --version 1.5.0
NuGet\Install-Package LexiconLang.Core -Version 1.5.0
<PackageReference Include="LexiconLang.Core" Version="1.5.0" />
<PackageVersion Include="LexiconLang.Core" Version="1.5.0" />
<PackageReference Include="LexiconLang.Core" />
paket add LexiconLang.Core --version 1.5.0
#r "nuget: LexiconLang.Core, 1.5.0"
#:package LexiconLang.Core@1.5.0
#addin nuget:?package=LexiconLang.Core&version=1.5.0
#tool nuget:?package=LexiconLang.Core&version=1.5.0
LexiconLang.Net
A complete C#/.NET port of the deterministic procedural generation system LexiconLang. Designed for games, tabletop tools, and narratives, focusing on absolute determinism, composability, and 1-to-1 parity with the TypeScript library.
Features
- Absolute Determinism: The entire generation tree is driven by a hierarchical
Contextseeded randomly or strictly.Context.Child("node")automatically forks the Random Number Generator to maintain isolated state streams—meaning adding or removing content elsewhere won't shift unrelated lists! - Data-Driven & Composable: Use small atomic string/object generators combined via
Combinators.Repeat,Compose,WeightedList, etc. - Tracery-style Grammars:
LexiconLang.Grammarsupports complex, recursively expanded templates and custom text modifiers (#name.capitalize#). - Markov Models:
LexiconLang.Markovallows you to train text models to procedurally generate cohesive names and prose. - Phonotactics & Glyphs:
LexiconLang.LanguageandLexiconLang.Glyphsenable generation of culturally distinct languages, unique words, and corresponding SVG procedural runes/glyphs. - Content Packs out-of-the-box:
LexiconLang.Fantasy,LexiconLang.SciFi, andLexiconLang.Modern.
Included Packages
LexiconLang.Core(RNG,Context, Combinators)LexiconLang.GrammarLexiconLang.MarkovLexiconLang.LanguageLexiconLang.GlyphsLexiconLang.Fantasy,LexiconLang.SciFi,LexiconLang.Modern
Usage Examples
1. Minimal Quickstart
using System;
using LexiconLang.Core;
using LexiconLang.Fantasy;
class Program
{
static void Main()
{
// 1. Initialize root context with a deterministic seed
var ctx = LexiconContext.Create("hello-world");
// 2. Generate random results from an included content pack
var faction = FantasyEncounters.FactionGenerator.Generate(ctx.Child("faction"));
var title = FantasyEncounters.TitleGenerator.Generate(ctx.Child("title"));
Console.WriteLine($"The {title} of {faction}");
}
}
2. Custom Generators
public record IronKnight(string Name, string Rank);
var house = Combinators.OneOf<string, object?>("Vael", "Kessel", "Vorden", "Bayard");
var rank = Combinators.WeightedList<string, object?>(new[]
{
new Weighted<string>("Squire", 4),
new Weighted<string>("Knight", 8),
new Weighted<string>("Knight-Captain", 2),
});
var ironKnight = Combinators.Compose<IronKnight, object?>("ironknight", ctx =>
{
return new IronKnight(
"Sir " + house.Generate(ctx.Child("name")),
rank.Generate(ctx.Child("rank"))
);
});
var rootCtx = LexiconContext.Create("iron-watch");
var k = ironKnight.Generate(rootCtx.Child("watch:0"));
3. Grammars (Tracery Style)
var rules = new GrammarRules<object?>
{
{ "start", new Weighted<string>[]
{
new ("#prefix.capitalize# #element.capitalize# #form.capitalize#", 5),
new ("the #adj.capitalize# #form.capitalize#", 2)
}
},
{ "prefix", new[] { "lesser", "greater", "true" } },
{ "element", new[] { "fire", "frost", "shadow" } },
{ "form", new[] { "bolt", "ward", "veil" } },
{ "adj", new[] { "unsleeping", "patient", "errant" } }
};
var spellName = new Grammar<object?>(rules);
var ctx = LexiconContext.Create("spellbook");
// Prints e.g. "Greater Shadow Bolt"
Console.WriteLine(spellName.Generate(ctx));
4. Markov Model
var corpus = new[] { "caernarfon", "carmarthen", "ceredigion", "conwy", "gwynedd" };
var entries = corpus.Select(x => new TrainEntry(x));
// Train the generator
var model = Trainer.Train(entries, new TrainOptions(Order: 3, MinLength: 5, MaxLength: 12));
var townName = Sampler.AsGenerator<object?>(model);
var ctx = LexiconContext.Create("welsh-towns");
Console.WriteLine(townName.Generate(ctx));
5. Culture & Glyphs
var ctx = LexiconContext.Create("glyph-demo");
// Generate a culturally appropriate name and translation
var dwarfName = Templates.GenerateName(FantasyCultures.Dwarvish, "given", ctx.Child("dwarf"));
// Setup the glyph system to be phoneme-based
var visualSystem = new VisualGlyphSystem(
Name: "dwarvish-runes",
Strategy: MappingStrategy.Phoneme,
Complexity: Complexity.Medium,
Format: RenderFormat.Svg,
Palette: new[] { "#333", "#666" }
);
// Map the generated name strictly structure-to-glyph
var dwarfGlyphs = GlyphGenerator.GlyphsFor(dwarfName, visualSystem, ctx.Child("dwarf"));
Build and test
dotnet build -warnaserror
dotnet test LexiconLang.Net.slnx
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (7)
Showing the top 5 NuGet packages that depend on LexiconLang.Core:
| Package | Downloads |
|---|---|
|
LexiconLang.Language
Lexicon, phonotactics, archetypes, and template-based language generation for LexiconLang .NET. |
|
|
LexiconLang.Grammar
Tracery-style grammar parsing and expansion for LexiconLang .NET. |
|
|
LexiconLang.Markov
Markov training and deterministic sampling for LexiconLang .NET. |
|
|
LexiconLang.SciFi
Sci-fi content pack, cultures, and semantic data for LexiconLang .NET. |
|
|
LexiconLang.Fantasy
Fantasy content pack, cultures, and semantic data for LexiconLang .NET. |
GitHub repositories
This package is not used by any popular GitHub repositories.