/// <summary> /// Method to replace words of certain length in choosen centence by substring of any length /// </summary> /// <param name="text"></param> /// <param name="sentenceNumber"></param> /// <param name="wordLength"></param> /// <param name="sentenceElements"></param> /// <returns></returns> public static Text.Implementation.Text ReplacesWordsInSentenceWithSubstring(IText text, int sentenceNumber, int wordLength, ICollection <ISentenceElement> sentenceElements) { var sentenceIndex = sentenceNumber - 1; var sentencesForNewText = new List <Sentence>(); var elementsForNewSentences = new List <ISentenceElement>(); elementsForNewSentences.AddRange(ReplaceWord(text.Sentences[sentenceIndex], x => x.Length == wordLength, sentenceElements)); // adding new sentence elements to a list var newSentence = new Sentence(elementsForNewSentences); for (int i = 0; i < sentenceIndex; i++) // Adding sentences before changed sentence to text { sentencesForNewText.Add(text.Sentences[i]); } sentencesForNewText.Add(newSentence); // Adding changed sentence to text for (int i = sentenceIndex + 1; i < text.Sentences.Count; i++) // Adding sentences after changed sentence to text { sentencesForNewText.Add(text.Sentences[i]); } var newText = new Text.Implementation.Text(sentencesForNewText); // initializing new text from new sentences return(newText); }
/// <summary> /// Method to delete words starting with consonant from sentence /// </summary> /// <param name="text"></param> /// <param name="wordLength"></param> /// <returns></returns> public static Text.Implementation.Text DeleteWordsStartingWithConsonant(Text.Implementation.Text text, int wordLength) { var newSentences = text.Sentences .Select(x => RemoveWordsFromSentence(x, y => y.Length == wordLength && !y.StartsWithVovel())) .Where(x => x.SentenceElements.OfType <IWord>().Any() && x.SentenceElements.Count > 0).ToList(); // Removing words from sentence if they satisfy certain conditions return(new Text.Implementation.Text(newSentences)); }