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
- {
- static class SentencesParserTask
- {
- public static List<List<string>> ParseSentences(string text)
- {
- var sentencesList = new List<List<string>>();
- var sentences = ParseSentence(text);
- foreach (var sentence in sentences)
- {
- if (sentence.Length != 0)
- {
- sentencesList.Add(ParseWords(sentence));
- }
- }
- return sentencesList;
- }
- private static List<string> ParseWords(string sentence)
- {
- var wordsList = new List<string>();
- var sentenceBuilder = new StringBuilder();
- foreach (var symbol in sentence)
- {
- if (char.IsLetter(symbol) || symbol == '\'')
- {
- sentenceBuilder.Append(char.ToLower(symbol));
- }
- else
- {
- if (sentenceBuilder.Length == 0)
- {
- continue;
- }
- wordsList.Add(sentenceBuilder.ToString());
- sentenceBuilder.Clear();
- }
- }
- return wordsList;
- }
- private static List<string> ParseSentence(string text)
- {
- var sentenceList = new List<string>();
- var sentenceArray = text.Split('.', '!', '?', ';', ':', '(', ')');
- foreach (var sentence in sentenceArray)
- {
- if (!string.IsNullOrEmpty(sentence))
- {
- sentenceList.Add(sentence);
- }
- }
- return sentenceList;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement