SHARE
TWEET

Untitled

a guest Dec 16th, 2018 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections.Generic;
  2. using System.Text;
  3.  
  4. namespace TextAnalysis
  5. {
  6.     static class TextGeneratorTask
  7.     {
  8.         public static string GetSentence(string sentence, string begin, Dictionary<string, string> nextWords)
  9.         {
  10.             var builder = new StringBuilder();
  11.             var array = sentence.Split();
  12.             builder.Append(sentence);
  13.             builder.Append(" ");
  14.             builder.Append(nextWords[begin]);
  15.             return builder.ToString();
  16.         }
  17.  
  18.         public static string[] GetWrapArray(string[] last, string word)
  19.         {
  20.             last[0] = last[1];
  21.             last[1] = word;
  22.             return last;
  23.         }
  24.  
  25.         public static string ContinuePhrase(
  26.             Dictionary<string, string> next, string str, int count)
  27.         {
  28.             var last = new string[] { " ", str.Split()[str.Split().Length - 1] };
  29.             if (str.Split().Length >= 2)
  30.                 last[0] = str.Split()[str.Split().Length - 2];
  31.             for (int i = 0; i < count; i++)
  32.             {
  33.                 if (next.ContainsKey(last[0] + " " + last[1]))
  34.                 {
  35.                     str = GetSentence(str, last[0] + " " + last[1], next);
  36.                     last[0] = last[1];
  37.                     last[1] = next[last[0] + " " + last[1]];
  38.                 }
  39.                 else
  40.                 {
  41.                     if (next.ContainsKey(last[1]))
  42.                     {
  43.                         str = GetSentence(str, last[1], next);
  44.                         last[0] = last[1];
  45.                         last[1] = next[last[0] + " " + last[1]];
  46.                     }
  47.                     else
  48.                     {
  49.                         return str;
  50.                     }
  51.                 }
  52.             }
  53.             return str;
  54.         }
  55.     }
  56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top