private static string CleanToEnglish(string s0) { string sent2 = StaticAIMLUtils.ForOutputTemplate(s0); var s = StaticAIMLUtils.ToEnglish(sent2, null); s = StaticAIMLUtils.Trim(s).Trim(' ', ',', '-', ' ', ' '); return(s); }
public static string Trim(string unifiable) { return(StaticAIMLUtils.Trim(unifiable)); }
public static List <string> SentenceBreaker(string sentence, Func <string, string> post) { var OutputSentences = new List <string>(); if (string.IsNullOrEmpty(sentence)) { return(OutputSentences); } sentence = StaticAIMLUtils.ReplacePairs(sentence, " />", "/>", " >", ">", "<br>", "<br/>", "<p>", "<p/>", "</p>", "<p/>", "<br/>", "\n", "<p/>", "\n", "\r", "\n").Replace("\n", " \n "); if (sentence.Trim(symcs).Length == 0) { return(OutputSentences); } bool dontBreak = false; if (sentence.StartsWith("<!--")) { string s1 = sentence; int endof = sentence.IndexOf("-->"); if (endof == sentence.Length - 3) { dontBreak = true; } } if (sentence.StartsWith("@")) { dontBreak = true; } else if (sentence.IndexOfAny(symc) == -1) { dontBreak = true; } if (dontBreak) { string s1 = sentence; if (post != null) { s1 = post(s1); } if (!string.IsNullOrEmpty(s1)) { OutputSentences.Add(s1); } return(OutputSentences); } var sp = new HashSet <string>(); sp.Add("."); sp.Add("!"); sp.Add("?"); foreach (var splitter in AltBot.Splitters) { sp.Add(splitter); } foreach (var s00 in sentence.Split('\n', '\r')) { var s0 = s00; while (s0.Trim().Length > 0) { s0 = StaticAIMLUtils.Trim(s0).Trim(' ', ',', '-', ' ', '.'); if (string.IsNullOrEmpty(s0)) { continue; } bool usedBreaker = false; foreach (string c in sp) { String NeedAfter = " "; int ia = (s0 + NeedAfter).IndexOf(c + NeedAfter); if (ia == -1) { continue; } if (s0.Length > ia + 3) { string twochars = s0.Substring(ia, 2); if (twochars == ".x") { continue; } if (twochars == "!-") { continue; } if (twochars == ": ") { continue; } } if (ia > 1) { string s = s0.Substring(0, ia + 1); s = CleanToEnglish(s); if (!string.IsNullOrEmpty(s)) { if (post != null) { s = post(s); } if (!string.IsNullOrEmpty(s)) { OutputSentences.Add(s); } } usedBreaker = true; s0 = s0.Substring(ia + 1); } //if (usedBreaker) break; } if (usedBreaker) { continue; } string s1 = CleanToEnglish(s0); //if (string.IsNullOrEmpty(s1) && !s1.Contains("<")) continue; if (post != null) { s1 = post(s1); } if (!string.IsNullOrEmpty(s1)) { OutputSentences.Add(s1); } s0 = ""; continue; } } return(OutputSentences); }