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