Bugfix: Correct word-level generation to be a sliding-window
This commit is contained in:
parent
22faead8b4
commit
6b79d8c5bb
2 changed files with 4 additions and 4 deletions
|
@ -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++;
|
||||
}
|
||||
|
|
|
@ -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…
Reference in a new issue