Add additional protection against blank n-grams

This commit is contained in:
Starbeamrainbowlabs 2018-09-03 21:23:37 +01:00
parent 7285459604
commit 8f4a3f41bd
Signed by: sbrl
GPG key ID: 1BE5172E637709C2

View file

@ -94,6 +94,7 @@ namespace MarkovGrams
string[] parts = str.Split(" ".ToCharArray());
for (int i = 0; i < parts.Length - order; i++) {
string ngram = string.Join(" ", parts.Skip(i).Take(order)).Trim();
if (ngram.Trim().Length == 0) continue;
if (!results.ContainsKey(ngram))
results[ngram] = 0;
results[ngram]++;