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

This commit is contained in:
Starbeamrainbowlabs 2018-09-03 16:38:20 +01:00
parent 22faead8b4
commit 6b79d8c5bb
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 4 additions and 4 deletions

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++;
}

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();