|
| 1 | +# Filtering |
| 2 | + |
| 3 | +### Filtering symbol combos |
| 4 | + |
| 5 | +Generators let you block symbol combinations or patterns from showing up in names.  |
| 6 | + |
| 7 | +Consider the following generator that does not create names with two consecutive `t` symbols:   |
| 8 | + |
| 9 | +```csharp |
| 10 | +var names = new NameGenerator() |
| 11 | + .Any(x => x |
| 12 | + .First("st") |
| 13 | + .Middle("aeiou") |
| 14 | + .Last("st")) |
| 15 | + .Filter("tt"); // Prevent two t's in a row |
| 16 | +``` |
| 17 | + |
| 18 | +<details> |
| 19 | + |
| 20 | +<summary>See non-fluent version</summary> |
| 21 | + |
| 22 | +```csharp |
| 23 | +var consonants = new SymbolGenerator("st"); |
| 24 | +var vowels = new SymbolGenerator("aeiou"); |
| 25 | + |
| 26 | +var syllableGenerator = new SyllableGenerator() |
| 27 | + .Add(SymbolPosition.First, consonants) |
| 28 | + .Add(SymbolPosition.Middle, vowels) |
| 29 | + .Add(SymbolPosition.Last, consonants); |
| 30 | + |
| 31 | +var nameFilter = new NameFilter() |
| 32 | + .Add(new FilterConstraint(FilterCondition.MatchesPattern, "tt")); |
| 33 | + |
| 34 | +var names = new NameGenerator() |
| 35 | + .SetSyllables(SyllablePosition.Any, syllableGenerator) |
| 36 | + .SetFilter(nameFilter) |
| 37 | + .SetSize(2, 3); |
| 38 | +``` |
| 39 | + |
| 40 | +</details> |
| 41 | + |
| 42 | +✅This generator creates names like: |
| 43 | + |
| 44 | +``` |
| 45 | +Tostis |
| 46 | +Sastus |
| 47 | +Tessesos |
| 48 | +``` |
| 49 | + |
| 50 | +❌This generator will never create names like: |
| 51 | + |
| 52 | +``` |
| 53 | +Sottus |
| 54 | +Tottis |
| 55 | +``` |
| 56 | + |
| 57 | +### Filtering through regex |
| 58 | + |
| 59 | +If you are comfortable using [regular expressions](https://en.wikipedia.org/wiki/Regular_expression), you can choose to use in your filter. |
| 60 | + |
| 61 | +The following generator uses the symbols `m` `u`, but uses a filter to prevent `m` from appearing at the beginning of a name and prevents `u` from ending it: |
| 62 | + |
| 63 | +```csharp |
| 64 | +var names = new NameGenerator() |
| 65 | + .Any(x => x |
| 66 | + .First("strlmn") |
| 67 | + .Middle("aeiou")) |
| 68 | + .Filter("^M|u$"); |
| 69 | +``` |
| 70 | + |
| 71 | +<details> |
| 72 | + |
| 73 | +<summary>See non-fluent version</summary> |
| 74 | + |
| 75 | +```csharp |
| 76 | +var consonants = new SymbolGenerator("st"); |
| 77 | +var vowels = new SymbolGenerator("aeiou"); |
| 78 | + |
| 79 | +var syllableGenerator = new SyllableGenerator() |
| 80 | + .Add(SymbolPosition.First, consonants) |
| 81 | + .Add(SymbolPosition.Middle, vowels) |
| 82 | + .Add(SymbolPosition.Last, consonants); |
| 83 | + |
| 84 | +var nameFilter = new NameFilter() |
| 85 | + .Add(new FilterConstraint(FilterCondition.MatchesPattern, "^M|u$")); |
| 86 | + |
| 87 | +var names = new NameGenerator() |
| 88 | + .SetSyllables(SyllablePosition.Any, syllableGenerator) |
| 89 | + .SetFilter(nameFilter) |
| 90 | + .SetSize(2, 3); |
| 91 | +``` |
| 92 | + |
| 93 | +</details> |
| 94 | + |
| 95 | +This generates names like: |
| 96 | + |
| 97 | +``` |
| 98 | +Temaro |
| 99 | +Rima |
| 100 | +Narumi |
| 101 | +``` |
| 102 | + |
| 103 | +### Filtering multiple things at once |
| 104 | + |
| 105 | +Calls to the fluent method `Filter()` implicitly sets a `NameFilter` on the `NameGenerator` you are setting up. There can only be one `NameFilter` on a `NameGenerator`. |
| 106 | + |
| 107 | +❌Don't do this if you want to filter multiple patterns: |
| 108 | + |
| 109 | +```csharp |
| 110 | +var names = new NameGenerator() |
| 111 | + .Any(x => x |
| 112 | + .First("strlmn") |
| 113 | + .Middle("aeiou")) |
| 114 | + .Filter("^M") |
| 115 | + .Filter("u$") |
| 116 | + .Filter("le"); // Only the last filter gets applied |
| 117 | +``` |
| 118 | + |
| 119 | +✅Do this if you want to filter multiple patterns or combos at once: |
| 120 | + |
| 121 | +```csharp |
| 122 | +var names = new NameGenerator() |
| 123 | + .Any(x => x |
| 124 | + .First("strlmn") |
| 125 | + .Middle("aeiou")) |
| 126 | + .Filter(x => x |
| 127 | + .DoNotAllowStart("m") // All of these get applied |
| 128 | + .DoNotAllowRegex("u$") |
| 129 | + .DoNotAllowSubstring("le")); |
| 130 | +``` |
| 131 | + |
| 132 | +This generates names like: |
| 133 | + |
| 134 | +``` |
| 135 | +Lisone |
| 136 | +Nara |
| 137 | +Ronimo |
| 138 | +``` |
| 139 | + |
0 commit comments