Advertisement
Guest User

Untitled

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