public IEnumerable<IWordsTokenizer> Parse(string text) { if (string.IsNullOrEmpty(text)) { throw new ArgumentException("Value cannot be null or empty.", nameof(text)); } string[] sentences = splitter.Split(text).ToArray(); string saved = string.Empty; for (int i = 0; i < sentences.Length; i++) { string currentSentence = sentences[i].Trim(); while (currentSentence.Length > 1 && currentSentence[currentSentence.Length - 2] == ' ') { currentSentence = currentSentence.Remove(currentSentence.Length - 2, 1); } if (string.IsNullOrWhiteSpace(currentSentence)) { continue; } if (i < sentences.Length - 1) { string nextSentence = sentences[i + 1]; bool found = currentSentence.Count(char.IsLetterOrDigit) <= 2; if (!found) { for (int j = 0; j < nextSentence.Length && j <= 3; j++) { if (nextSentence[j] == '.') { found = true; break; } } } if (found) { saved += currentSentence; continue; } } if (!string.IsNullOrWhiteSpace(saved)) { currentSentence = saved + " " + currentSentence; } IWordsTokenizer wordsTokenizer = TokenizerFactory.Create(currentSentence); saved = string.Empty; if (wordsTokenizer != NullWordsTokenizer.Instance) { yield return wordsTokenizer; } } }
public async Task <string> TranslatePronoumAsync(string content) { var contents = RegexSplitter.Split(content, pronoumRegexPattern); var sb = new StringBuilder(); foreach (var item in contents) { var translanted = await _nameCallContentFormatter.GetFormattedContentAsync(item); sb.Append(translanted); } return(sb.ToString()); }