Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Text;
- using System;
- using System.Linq;
- namespace TextAnalysis
- {
- static class SentencesParserTask
- {
- static char[] separatorCharacters = new char[] {'.', '!', '?', ';', ':', '(', ')'};
- public static List<List<string>> ParseSentences(string text)
- {
- var sentencesList = new List<List<string>>();
- string[] workText = GetWorkingText(ref text);
- foreach (var word in workText)
- {
- if (word != "")
- {
- word.Trim();
- var list = findOutWordList(word + " ");
- if (list != null)
- sentencesList.Add(list);
- }
- }
- Console.WriteLine(string.Join(", ", sentencesList));
- return sentencesList;
- }
- private static string[] GetWorkingText(ref string text)
- {
- text = text.ToLower();
- var workText = @text.Split(separatorCharacters);
- return workText;
- }
- private static List<string> findOutWordList(string word)
- {
- var wordList = new List<string>();
- var strBuilder = new StringBuilder();
- foreach (var symbol in word)
- {
- if (char.IsLetter(symbol) || symbol == '\'')
- {
- strBuilder.Append(symbol);
- }
- else
- {
- var finWord = strBuilder.ToString();
- finWord.Trim();
- if (finWord != "")
- {
- wordList.Add(finWord);
- strBuilder = new StringBuilder();
- }
- }
- }
- return wordList;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement