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)
- {
- if (text == null) return null;
- text = text.ToLower();
- string[] sentences = text.Split('.', '!', '?', ';', ':', '(', ')');
- var listOfSentences = ParseToList(sentences);
- return listOfSentences;
- }
- public static List<List<string>> ParseToList(string[] sentences)
- {
- var listOfSentences = new List<List<string>>();
- foreach (var sentence in sentences)
- {
- var words = new List<string>();
- string temp = "";
- string tempSentence = sentence + " ";
- if (sentence.Length > 0)
- {
- for(int i = 0 ; i < tempSentence.Length;i++)
- {
- if (char.IsLetter(tempSentence[i]) || tempSentence[i] == '\'' ) temp += tempSentence[i];
- else
- {
- if (temp.Length > 0)
- {words.Add(temp);
- temp = "";
- }
- }
- }
- listOfSentences.Add(words);
- }
- }
- return listOfSentences;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement