Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 = text.Split('.', '!', '?', ';', ':', '(', ')');
- foreach (var sentence in sentences)
- {
- var newsentence = "";
- var listOfSentences = new List<string>();
- var result = ParseSentencesIntoWords(sentence);
- if (newsentence.Length > 0)
- listOfSentences.Add(newsentence.ToLower());
- if (result.Count > 0)
- sentencesList.Add(result);
- }
- return sentencesList;
- }
- public static List<string> ParseSentencesIntoWords(string sentence)
- {
- var listOfSentences = new List<string>();
- var newsentence = "";
- foreach (var letter in sentence)
- {
- if (char.IsLetter(letter) || letter == '\'')
- {
- newsentence += letter.ToString();
- }
- else if(newsentence.Length > 0)
- {
- listOfSentences.Add(newsentence.ToLower());
- newsentence = "";
- }
- }
- if (newsentence.Length > 0)
- listOfSentences.Add(newsentence.ToLower());
- return listOfSentences;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement