Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Linq;
- namespace TextAnalysis
- {
- static class SentencesParserTask
- {
- public static List<List<string>> ParseSentences(string text)
- {
- char[] expressionsForLines = { '.', '!', '?', ';', ':', '(', ')' };
- var sentencesList = new List<List<string>>();
- List<string> lines = text.Split(expressionsForLines).ToList();
- int lineCounter = 0;
- foreach (var line in lines)
- {
- bool lineIsEmpty = true;
- int wordCounter = 0;
- int charCounter = 0;
- for (int i = 0; i < line.Length; i++)
- {
- if ((char.IsLetter(line[i])) || (line[i] == '\''))
- {
- lineIsEmpty = false;
- charCounter = i;
- break;
- }
- }
- if (lineIsEmpty) continue;
- sentencesList.Add(new List<string>());
- bool wordIsEmpty = true;
- for (int i = charCounter; i < line.Length; i++)
- {
- if ((char.IsLetter(line[i])) || (line[i] == '\''))
- {
- if (sentencesList[lineCounter].Count == wordCounter)
- {
- sentencesList[lineCounter].Add("");
- wordIsEmpty = false;
- }
- sentencesList[lineCounter][wordCounter] += char.ToLower(line[i]);
- }
- else if (wordIsEmpty)
- {
- continue;
- }
- else
- {
- wordCounter++;
- wordIsEmpty = true;
- }
- }
- lineCounter++;
- }
- return sentencesList;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement