public static IEnumerable <IWord> QuestionSentenceByWordLength(this IList <ISentence> sentence, int length) { var sign = new PunctuationSign("?"); var questionSentences = sentence.Where(x => sign.Equals(x.Last())); ISet <IWord> set = new HashSet <IWord>(); foreach (var s in questionSentences) { var words = s.GetWords().Where(x => x.Length == length).ToList(); words.ForEach(x => set.Add(x)); } return(set); }
public void Run() { IWord[] words = new Word[5] { new Word("hello"), new Word("world"), new Word("how"), new Word("are"), new Word("you") }; Gap space = new Gap(" "); Gap space1 = new Gap(" "); IGap tab = new Gap("\t"); IGap newLine = new Gap("\n"); IPunctuationSign comma = new PunctuationSign(", "); IPunctuationSign dash = new PunctuationSign("-"); IPunctuationSign dot = new PunctuationSign("."); IPunctuationSign mark = new PunctuationSign("! "); IPunctuationSign q = new PunctuationSign("?"); IToken q1 = new PunctuationSign("?"); ISentence sentence = new Sentence(new List <IToken>()); var any = sentence.Last(); sentence.Add(tab); sentence.Add(dash); sentence.Add(words[0]); sentence.Add(space); sentence.Add(words[4]); sentence.Add(dot); sentence.Add(tab); sentence.Add(words[2]); sentence.Add(space); sentence.Add(words[3]); sentence.Add(mark); Console.WriteLine(sentence.ToString()); sentence.Remove(words[3]); sentence.Remove(words[4]); Console.WriteLine(sentence.ToString()); }