Browse Source

Bugfix: Correct word-level generation to be a sliding-window

master
Starbeamrainbowlabs 2 years ago
parent
commit
6b79d8c5bb
Signed by: sbrl GPG Key ID: 1BE5172E637709C2
2 changed files with 4 additions and 4 deletions
  1. +2
    -2
      MarkovGrams/UnweightedMarkovChain.cs
  2. +2
    -2
      MarkovGrams/WeightedMarkovChain.cs

+ 2
- 2
MarkovGrams/UnweightedMarkovChain.cs View File

@ -77,7 +77,7 @@ namespace MarkovGrams
while((Mode == GenerationMode.CharacterLevel ? result.Length : result.Split(' ').Length) < length)
{
// The substring that the next ngram in the chain needs to start with
string nextStartsWith = Mode == GenerationMode.CharacterLevel ? lastNgram.Substring(1) : lastNgram.Split(' ').Last();
string nextStartsWith = Mode == GenerationMode.CharacterLevel ? lastNgram.Substring(1) : string.Join(" ", lastNgram.Split(' ').Skip(1));
// Get a list of possible n-grams we could choose from next
List<string> nextNgrams = ngrams.FindAll(gram => gram.StartsWith(nextStartsWith));
choiceCounts.Add(nextNgrams.Count);
@ -90,7 +90,7 @@ namespace MarkovGrams
if (Mode == GenerationMode.CharacterLevel)
result += nextNgram[nextNgram.Length - 1];
else
result += ' ' + string.Join(" ", nextNgram.Split(' ').Skip(1));
result += ' ' + nextNgram.Split(' ').Last();
lastNgram = nextNgram; i++;
}


+ 2
- 2
MarkovGrams/WeightedMarkovChain.cs View File

@ -92,7 +92,7 @@ namespace MarkovGrams
{
wrandom.ClearContents();
// The substring that the next ngram in the chain needs to start with
string nextStartsWith = Mode == GenerationMode.CharacterLevel ? lastNgram.Substring(1) : lastNgram.Split(' ').Last();
string nextStartsWith = Mode == GenerationMode.CharacterLevel ? lastNgram.Substring(1) : string.Join(" ", lastNgram.Split(' ').Skip(1));
// Get a list of possible n-grams we could choose from next
Dictionary<string, double> convNextNgrams = new Dictionary<string, double>();
ngrams.Where(gram_data => gram_data.Key.StartsWith(nextStartsWith))
@ -109,7 +109,7 @@ namespace MarkovGrams
if (Mode == GenerationMode.CharacterLevel)
result += nextNgram[nextNgram.Length - 1];
else
result += ' ' + string.Join(" ", nextNgram.Split(' ').Skip(1));
result += ' ' + nextNgram.Split(' ').Last();
lastNgram = nextNgram; i++;
}
wrandom.ClearContents();


Loading…
Cancel
Save