Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System;
- namespace TextAnalysis
- {
- static class SentencesParserTask
- {
- public static List<List<string>> ParseSentences(string text)
- {
- var sentencesList = new List<List<string>>();
- List<string> sentences = new List<string>();
- FillSentences(sentences,text);
- for (int i = 0; i < sentences.Count; i++)
- {
- sentences[i] = sentences[i].Trim();
- List<string> words = new List<string>();
- DivideByWords(words,sentences[i]);
- if (words.Count > 0)
- sentencesList.Add(words);
- }
- return sentencesList;
- }
- public static void DivideByWords(List<string> words, string sentence)
- {
- string wordTemp = "";
- for (int j = 0; j < sentence.Length; j++)//foreach simbol
- {
- if (char.IsLetter(sentence[j]) || sentence[j] == '\'')
- {
- wordTemp += sentence[j];
- }
- else
- {
- if (wordTemp != "")
- {
- words.Add(wordTemp.ToLower());
- wordTemp = "";
- }
- }
- }
- if (wordTemp != "")
- {
- words.Add(wordTemp.ToLower());
- }
- }
- public static void FillSentences(List<string> sentences, string text)
- {
- string part = "";
- string separators = ".!?;:()";
- for (int i = 0; i < text.Length; i++)
- {
- if (separators.IndexOf(text[i]) == -1)
- {
- part += text[i];
- }
- else
- {
- if (part != "")
- {
- sentences.Add(part.ToLower());
- part = "";
- }
- }
- }
- if (part != "")
- {
- sentences.Add(part.ToLower());
- part = "";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement