private static Sentence ReadSentence(StreamReader sr, char c) { Sentence sentence = new Sentence(); if (c >= 'а' && c <= 'я' || c >= 'А' && c <= 'Я' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') { sentence.AddSentenceItem(ReadWord(sr, ref c)); } while (!sr.EndOfStream) { c = (char)sr.Read(); if (c >= 'а' && c <= 'я' || c >= 'А' && c <= 'Я' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') { sentence.AddSentenceItem(ReadWord(sr, ref c)); } if (c != ' ') { Punctuation punct = ReadPunctuation(sr, c); sentence.AddSentenceItem(punct); switch (punct.ToString()) { case ".": { sentence.SetSentenceType(SentenceType.declarative); } return(sentence); case "!": { sentence.SetSentenceType(SentenceType.exclamative); } return(sentence); case "?": { sentence.SetSentenceType(SentenceType.interrogative); } return(sentence); case "...": { sentence.SetSentenceType(SentenceType.threeDots); } return(sentence); default: { break; } } } } return(sentence); }
private static Punctuation ReadPunctuation(StreamReader sr, char c) { Punctuation punctuation = new Punctuation(); bool flag = true; punctuation.AddPunc(c); do { c = (char)sr.Read(); if (c == '.') { punctuation.AddPunc(c); } else { flag = false; } } while (flag); return(punctuation); }
private Sentence CreateSectence(List <ISentenceItem> items) { if (items == null || items.Count == 0) { throw new ArgumentNullException(nameof(items)); } Punctuation endPunctuation = items[items.Count - 1] as Punctuation; if (endPunctuation == null) { throw new ArgumentException("Last sentence item must be punctuation."); } items.Remove(endPunctuation); if (items[0] is Separator) { items.Remove(items[0]); } return(new Sentence(items, endPunctuation)); }