Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Text;
- using System.Collections.Generic;
- namespace TextAnalysis
- {
- static class SentencesParserTask
- {
- public static List<string> GetWords(string sentence)
- {
- var words = new List<string>();
- var word = new StringBuilder();
- foreach (var item in sentence)
- {
- if (item == '\''|| char.IsLetter(item))
- {
- word.Append(char.ToLower(item));
- }
- else
- {
- if (word.Length != 0)
- {
- words.Add(word.ToString());
- word.Clear();
- }
- }
- }
- if (word.Length != 0)
- words.Add(word.ToString());
- return words;
- }
- public static List<List<string>> ParseSentences(string text)
- {
- var sentencesArr = text.Split( '.', '!', '?', ';', ':', ')', '(' );
- var sentencesList = new List<List<string>>();
- foreach (var sentence in sentencesArr)
- {
- List<string> words = GetWords(sentence);
- if (words.Count != 0)
- {
- sentencesList.Add(words);
- }
- }
- return sentencesList;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement