Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace TextAnalysis
- {
- static class SentencesParserTask
- {
- public static List<string> SplitSentenceIntoWords(string sentence)
- {
- var words = sentence.Split(' ', '^');
- var wordList = new List<String>();
- foreach (string word in words)
- {
- var clearWord = word;
- bool wordIsClear = false;
- for (var i = 0; i < clearWord.Length; i++)
- {
- if (!char.IsLetter(clearWord[i]) && clearWord[i] != '\'')
- {
- clearWord = clearWord.Remove(i, 1);
- i--;
- while (!char.IsLetter(clearWord[0]))
- {
- clearWord = clearWord.Remove(0, 1);
- }
- wordList.Add(clearWord.ToLower());
- wordIsClear = true;
- }
- }
- if (!wordIsClear)
- {
- wordList.Add(word);
- }
- }
- return wordList;
- }
- public static List<List<string>> ParseSentences(string text)
- {
- var sentencesList = new List<List<string>>();
- var sentences = text.Split('.', '!', '?', ';', ':', '(', ')');
- foreach (string sentence in sentences)
- {
- if (!sentence.Equals(""))
- sentencesList.Add(SplitSentenceIntoWords(sentence));
- }
- return sentencesList;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement