Skip to content

Commit

Permalink
Propagate class library changes to example project
Browse files Browse the repository at this point in the history
  • Loading branch information
kesac committed Oct 11, 2023
1 parent a9d581f commit 7b3d918
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Syllabore/Syllabore.Example/JPGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public JPGenerator()
.WithVowels("io").Weight(2)
.WithVowels("eu")
.WithProbability(x => x
.OfLeadingConsonantIsSequence(0.1)))
.OfLeadingConsonants(1.0, 0.1)))
.UsingTransform(x => x
.ReplaceAll("hu", "fu")
.ReplaceAll("si", "shi")
Expand Down
12 changes: 11 additions & 1 deletion Syllabore/Syllabore.Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void Main(string[] args)

var g = new NameGenerator();

for (int i = 0; i < 5; i++)
for (int i = 0; i < 20; i++)
{
Console.WriteLine(g.Next());
}
Expand Down Expand Up @@ -507,6 +507,16 @@ public static void Main(string[] args)
}
}

Separator();

{
var englishNames = new WeightedGenerator();
for (int i = 0; i < 20; i++)
{
Console.WriteLine(englishNames.Next());
}
}

}

public static void Separator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public class RandomTextGenerator : NameGenerator

public RandomTextGenerator()
{
var provider = new SyllableGenerator()
var syllables = new SyllableGenerator()
.WithConsonants(AlphanumericCharacters)
.WithVowels(AlphanumericCharacters);

this.UsingSyllables(provider);
this.UsingFilter(new NameFilter());
this.UsingSyllables(syllables);

this.UsingSyllableCount(8);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public SpaceshipGeneratorV3()
.OfLeadingConsonants(1.0)
.OfTrailingConsonants(0.0)))
.UsingFilter(x => x
.DoNotAllowPattern(@"(\w)\1\1")) // Regex for three consecutive same letters
.DoNotAllow(@"(\w)\1\1")) // Regex for three consecutive same letters
.UsingSyllableCount(3); // In our case, this changes prefix length, not syllable count

_shipGenerator = new NameGenerator();
Expand Down
12 changes: 6 additions & 6 deletions Syllabore/Syllabore.Example/Spaceship/SpaceshipGeneratorV4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ public SpaceshipGeneratorV4()
.OfLeadingConsonants(1.0)
.OfTrailingConsonants(0.0)))
.UsingFilter(x => x
.DoNotAllowPattern(@"(\w)\1\1"))
.DoNotAllow(@"(\w)\1\1"))
.UsingSyllableCount(3);

_shipGenerator = new NameGenerator()
.UsingSyllables(x => x
.WithVowels("aoi")
.WithVowelSequences("ei", "ia", "ou", "eu")
.WithLeadingConsonants("rstlmn").Weight(4)
.WithLeadingConsonants("cdgp").Weight(2))
.WithVowels("aoi") // Don't need to separate vowels with commas if they're not sequences
.WithVowelSequences("ei", "ia", "ou", "eu") // For sequences though, we'll obviously need the commas
.WithLeadingConsonants("rstlmn").Weight(4) // Weights are relative to each other
.WithLeadingConsonants("cdgp").Weight(2)) // So this line says "2 out of 6" or 33% of the time
.UsingFilter(x => x
.DoNotAllowPattern(@"(\w)\1")) // Two of the same letters consecutively
.DoNotAllow(@"(\w)\1")) // Regex again, for two of the same letters consecutively
.UsingSyllableCount(3);
}

Expand Down
4 changes: 2 additions & 2 deletions Syllabore/Syllabore.Example/Spaceship/SpaceshipGeneratorV5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public SpaceshipGeneratorV5()
.OfLeadingConsonants(1.0)
.OfTrailingConsonants(0.0)))
.UsingFilter(x => x
.DoNotAllowPattern(@"(\w)\1\1"))
.DoNotAllow(@"(\w)\1\1"))
.UsingSyllableCount(3);

_shipGenerator = new NameGenerator()
Expand All @@ -41,7 +41,7 @@ public SpaceshipGeneratorV5()
.WithTransform(x => x.ReplaceSyllable(-1, "rus"))
.WithTransform(x => x.ReplaceSyllable(-1, "vium")))
.UsingFilter(x => x
.DoNotAllowPattern(@"(\w)\1"))
.DoNotAllow(@"(\w)\1"))
.UsingSyllableCount(3);
}

Expand Down
80 changes: 80 additions & 0 deletions Syllabore/Syllabore.Example/WeightedGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Syllabore.Example
{
public class WeightedGenerator : NameGenerator
{

public WeightedGenerator()
{
var consonants = new []
{
new { Letter = "b", Weight = 100 },
new { Letter = "c", Weight = 100 },
new { Letter = "d", Weight = 250 },
new { Letter = "f", Weight = 100 },
new { Letter = "g", Weight = 50 },
new { Letter = "h", Weight = 250 },
new { Letter = "j", Weight = 10 },
new { Letter = "k", Weight = 50 },
new { Letter = "l", Weight = 500 },
new { Letter = "m", Weight = 500 },
new { Letter = "n", Weight = 500 },
new { Letter = "p", Weight = 100 },
new { Letter = "q", Weight = 10 },
new { Letter = "r", Weight = 1000 },
new { Letter = "s", Weight = 2000 },
new { Letter = "t", Weight = 2000 },
new { Letter = "v", Weight = 10 },
new { Letter = "w", Weight = 10 },
new { Letter = "x", Weight = 10 },
new { Letter = "z", Weight = 10 }
};

var vowels = new[]
{
new { Letter = "a", Weight = 1000 },
new { Letter = "e", Weight = 1000 },
new { Letter = "i", Weight = 1000 },
new { Letter = "o", Weight = 1000 },
new { Letter = "y", Weight = 50 },
new { Letter = "u", Weight = 50 }
};

var syllables = new SyllableGenerator();

foreach(var consonant in consonants)
{
syllables.WithConsonants(consonant.Letter).Weight(consonant.Weight);
}

foreach (var vowel in vowels)
{
syllables.WithVowels(vowel.Letter).Weight(vowel.Weight);
}

this.UsingSyllables(syllables);

this.UsingSyllableCount(2, 3);

this.UsingProbability(x => x
.OfTrailingConsonants(0.33)
.OfLeadingVowelsInStartingSyllable(0.25)
.OfLeadingConsonants(1.0)
);

this.DoNotAllow(
"fd", "vf", "hf", "cv", // Just looks weird anywhere
"ht", "hc", "hw", // Inverted sequences
"ss", "tt", "rr",
"[wq][aeiou]$",
"[aeiou][ghqzpj]$" // weird endings
);

}
}
}

0 comments on commit 7b3d918

Please sign in to comment.