Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System;
- using System.Linq;
- namespace TextAnalysis
- {
- static class TextGeneratorTask
- {
- public static string ContinuePhrase(Dictionary<string, string> nextWords, string beginParse, int wordsCount)
- {
- var words = beginParse.Split().ToList();
- for (var i = 0; i < wordsCount; i++)
- {
- if (words.Count > 1 && nextWords.ContainsKey(words[words.Count - 2] + " " + words[words.Count - 1]))
- words.Add(nextWords[words[words.Count - 2] + " " + words[words.Count - 1]]);
- else if (nextWords.ContainsKey(words[words.Count - 1]))
- words.Add(nextWords[words[words.Count - 1]]);
- else break;
- }
- return string.Join(" ", words);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement