Advertisement
VssA

Untitled

Feb 16th, 2024
902
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System;
  3. using System.Linq;
  4.  
  5. namespace TextAnalysis
  6. {
  7.     static class TextGeneratorTask
  8.     {
  9.         public static string ContinuePhrase(Dictionary<string, string> nextWords, string beginParse, int wordsCount)
  10.         {
  11.             var words = beginParse.Split().ToList();
  12.             for (var i = 0; i < wordsCount; i++)
  13.             {
  14.                 if (words.Count > 1 && nextWords.ContainsKey(words[words.Count - 2] + " " + words[words.Count - 1]))
  15.                     words.Add(nextWords[words[words.Count - 2] + " " + words[words.Count - 1]]);
  16.                 else if (nextWords.ContainsKey(words[words.Count - 1]))
  17.                     words.Add(nextWords[words[words.Count - 1]]);
  18.                 else break;
  19.             }
  20.             return string.Join(" ", words);
  21.         }
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement