Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Text;
- namespace TextAnalysis
- {
- static class TextGeneratorTask
- {
- public static string GetSentence(string sentence, string begin, Dictionary<string, string> nextWords)
- {
- var builder = new StringBuilder();
- var array = sentence.Split();
- builder.Append(sentence);
- builder.Append(" ");
- builder.Append(nextWords[begin]);
- return builder.ToString();
- }
- public static string[] GetWrapArray(string[] last, string word)
- {
- last[0] = last[1];
- last[1] = word;
- return last;
- }
- public static string ContinuePhrase(
- Dictionary<string, string> next, string str, int count)
- {
- var last = new string[] { " ", str.Split()[str.Split().Length - 1] };
- if (str.Split().Length >= 2)
- last[0] = str.Split()[str.Split().Length - 2];
- for (int i = 0; i < count; i++)
- {
- if (next.ContainsKey(last[0] + " " + last[1]))
- {
- str = GetSentence(str, last[0] + " " + last[1], next);
- last[0] = last[1];
- last[1] = next[last[0] + " " + last[1]];
- }
- else
- {
- if (next.ContainsKey(last[1]))
- {
- str = GetSentence(str, last[1], next);
- last[0] = last[1];
- last[1] = next[last[0] + " " + last[1]];
- }
- else
- {
- return str;
- }
- }
- }
- return str;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement