public async Task ConvertToCSVFromSentences() { SentenceProcessResult sentences = new SentenceProcessResult(); sentences.Sentences.Add(new Sentence("Mary had a little lamb.")); sentences.Sentences.Add(new Sentence("Peter called for the wolf, and Aesop came. ")); sentences.Sentences.Add(new Sentence("Cinderella likes shoes.")); string csvResultString = await _sut.ConvertSentencesAsync(sentences); Assert.NotEmpty(csvResultString); }
public async Task <SentenceProcessResult> ProcessSentenceAsync(string inputSentences) { SentenceProcessResult result = new SentenceProcessResult(); List <string> sentenceStrings = inputSentences.Split(_sentenceSplitters, StringSplitOptions.RemoveEmptyEntries).ToList(); foreach (var tempSentence in sentenceStrings) { if (!string.IsNullOrEmpty(tempSentence)) { result.Sentences.Add(new Sentence(tempSentence).RemoveEmptyWords().OrderAlphabetically()); } } return(result); }
public async Task <string> ConvertSentencesAsync(SentenceProcessResult sentencesToProcess) { XmlDocument xmlDoc = new XmlDocument(); var rootElement = xmlDoc.CreateElement("text"); xmlDoc.AppendChild(rootElement); for (int i = 0; i < sentencesToProcess.Sentences.Count(); i++) { if (sentencesToProcess.Sentences[i].Words?.Count() > 0) { XmlNode tempSentenceNode = CreateSentenceNode(xmlDoc, sentencesToProcess.Sentences[i]); rootElement.AppendChild(tempSentenceNode); } } return(xmlDoc.OuterXml.ToString()); }
public async Task <string> ConvertSentencesAsync(SentenceProcessResult sentences) { StringBuilder sb = new StringBuilder(""); int maxLenght = sentences.Sentences.Max(d => d.Words.Count()); sb.AppendLine(CreateHeaderRow(maxLenght)); for (int i = 0; i < sentences.Sentences.Count; i++) { if (sentences.Sentences[i].Words.Count() > 0) { sb.Append("Sentence "); sb.Append(i + 1); sb.AppendLine(ConvertSentenceToString(sentences.Sentences[i])); } } return(sb.ToString()); }
public async Task ConvertToXMLFromSentences() { SentenceProcessResult sentences = new SentenceProcessResult(); sentences.Sentences.Add(new Sentence("Mary had a little lamb.")); sentences.Sentences.Add(new Sentence("Peter called for the wolf, and Aesop came. ")); sentences.Sentences.Add(new Sentence("Cinderella likes shoes.")); string xmlResultString = await _sut.ConvertSentencesAsync(sentences); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlResultString); var nodeResult = xmlDoc.SelectSingleNode("/text/sentence/word"); Assert.NotNull(nodeResult); Assert.Equal("Mary", nodeResult.InnerText); Assert.NotEmpty(xmlResultString); }
public async Task <string> ConvertSentencesAsync(SentenceProcessResult sentences, WordConvertingMethod method) { IWordConverter converter = _converterProvider.GetConverterByMethod(method); return(await converter.ConvertSentencesAsync(sentences)); }