Advertisement
Guest User

Untitled

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