Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 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. var listOfSentences = new List<List<string>>();
  12. if (text == null) return null;
  13. text = text.ToLower();
  14. string[] sentences = text.Split('.', '!', '?', ';', ':', '(', ')');
  15. foreach (var sentence in sentences)
  16. {
  17. if (sentence.Length > 0)
  18. {
  19. var words = ParseToList(sentence);
  20. if (words.Count > 0) listOfSentences.Add(words);
  21. }
  22. }
  23. return listOfSentences;
  24. }
  25.  
  26. public static List<string> ParseToList(string sentence)
  27. {
  28. var word = new List<string>();
  29. string temp = "";
  30. string tempSentence = sentence + " ";
  31. for (int i = 0; i < tempSentence.Length; i++)
  32. if (char.IsLetter(tempSentence[i]) || tempSentence[i] == '\'')
  33. temp += tempSentence[i];
  34. else
  35. if (temp.Length > 0)
  36. {
  37. word.Add(temp);
  38. temp = "";
  39. }
  40.  
  41. return word;
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement