Advertisement
Guest User

Untitled

a guest
Oct 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Text;
  3.  
  4. namespace TextAnalysis
  5. {
  6.     static class SentencesParserTask
  7.     {
  8.         public static List<List<string>> ParseSentences(string text)
  9.         {
  10.             var sentencesList = new List<List<string>>();
  11.             var sentences = text.Split('.', '!', '?', ';', ':', '(', ')');
  12.             foreach (var sentence in sentences)
  13.             {
  14.                 var newsentence = "";
  15.                 var listOfSentences = new List<string>();
  16.                 var result = ParseSentencesIntoWords(sentence);
  17.                 if (newsentence.Length > 0)
  18.                     listOfSentences.Add(newsentence.ToLower());
  19.                 if (result.Count > 0)
  20.                     sentencesList.Add(result);
  21.             }
  22.  
  23.             return sentencesList;
  24.         }
  25.  
  26.         public static List<string> ParseSentencesIntoWords(string sentence)
  27.         {
  28.             var listOfSentences = new List<string>();
  29.             var newsentence = "";
  30.             foreach (var letter in sentence)
  31.             {
  32.                 if (char.IsLetter(letter) || letter == '\'')
  33.                 {
  34.                     newsentence += letter.ToString();
  35.  
  36.                 }
  37.  
  38.                 else if(newsentence.Length > 0)
  39.                 {
  40.                     listOfSentences.Add(newsentence.ToLower());
  41.                     newsentence = "";
  42.                 }
  43.             }
  44.             if (newsentence.Length > 0)
  45.                 listOfSentences.Add(newsentence.ToLower());
  46.  
  47.             return listOfSentences;
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement