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