Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. using System.Collections.Generic;
  2.  
  3. namespace TextAnalysis
  4. {
  5. static class TextGeneratorTask
  6. {
  7. public static string ContinuePhrase(
  8. Dictionary<string, string> nextWords,
  9. string phraseBeginning,
  10. int wordsCount)
  11. {
  12. var result = phraseBeginning;
  13. for (var i = 0; i < wordsCount; i++)
  14. {
  15. var splitedSentences = phraseBeginning.Split(' ');
  16. if ((splitedSentences.Length >= 2) && (nextWords.ContainsKey(splitedSentences[splitedSentences.Length - 1] + " " + splitedSentences[splitedSentences.Length - 2])))
  17. {
  18. result += " " + nextWords[splitedSentences[splitedSentences.Length - 1] + " " + splitedSentences[splitedSentences.Length - 2]];
  19. }
  20. else if ((nextWords.ContainsKey(splitedSentences[splitedSentences.Length - 1]) && (splitedSentences.Length >= 1)))
  21. {
  22. result += " " + nextWords[splitedSentences[splitedSentences.Length - 1]];
  23. }
  24. }
  25. return result;
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement