Advertisement
mikhailemv

Untitled

Oct 14th, 2022
1,162
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Collections.Generic;
  4.  
  5. namespace TextAnalysis
  6. {
  7.     static class SentencesParserTask
  8.     {
  9.         public static List<List<string>> ParseSentences(string text)
  10.         {
  11.             var sentences = new List<List<string>>();
  12.             var separators = new char[] { '.', '!', '?', ':', ';', '(', ')' };
  13.             var arrayProcessedSentences = text.ToLower().Split(separators);
  14.  
  15.             foreach (var currentSentence in arrayProcessedSentences)
  16.             {
  17.                 var listWords = ConvertSentencesToWords(currentSentence);
  18.                 if (listWords.Count > 0)
  19.                     sentences.Add(listWords);
  20.             }
  21.  
  22.             return sentences;
  23.         }
  24.  
  25.         public static List<string> ConvertSentencesToWords(string currentString)
  26.         {
  27.             var builderString = new StringBuilder();
  28.             var listWords = new List<string>();
  29.  
  30.             for (var j = 0; j < currentString.Length; j++)
  31.             {
  32.                 var currentChar = currentString[j];
  33.                 if (char.IsLetter(currentChar) | currentChar == '\'')
  34.                     builderString.Append(currentChar);
  35.                 if (!char.IsLetter(currentChar) && !(currentChar == '\'') || j == currentString.Length - 1)
  36.                 {
  37.                     if (builderString.Length > 0)
  38.                         listWords.Add(builderString.ToString());
  39.                     builderString.Clear();
  40.                 }
  41.             }
  42.  
  43.             return listWords;
  44.         }  
  45.     }
  46. }
Advertisement
Comments
  • operazi
    1 year
    # text 0.19 KB | 0 0
    1. https://operazi.com/ar/Articles/Details/%D8%B7%D8%B1%D9%82-%D8%B9%D9%84%D8%A7%D8%AC-%D9%84%D9%84%D8%A5%D9%85%D8%B3%D8%A7%D9%83-%D8%B3%D8%B1%D9%8A%D8%B9-%D8%A7%D9%84%D9%85%D9%81%D8%B9%D9%88%D9%84
Add Comment
Please, Sign In to add comment
Advertisement