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