Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Text;
  3. using System;
  4. using System.Linq;
  5.  
  6. namespace TextAnalysis
  7. {
  8. static class SentencesParserTask
  9. {
  10. static char[] separatorCharacters = new char[] {'.', '!', '?', ';', ':', '(', ')'};
  11.  
  12. public static List<List<string>> ParseSentences(string text)
  13. {
  14. var sentencesList = new List<List<string>>();
  15. string[] workText = GetWorkingText(ref text);
  16. foreach (var word in workText)
  17. {
  18. if (word != "")
  19. {
  20. word.Trim();
  21. var list = findOutWordList(word + " ");
  22. if (list != null)
  23. sentencesList.Add(list);
  24. }
  25.  
  26. }
  27. Console.WriteLine(string.Join(", ", sentencesList));
  28. return sentencesList;
  29. }
  30. private static string[] GetWorkingText(ref string text)
  31. {
  32. text = text.ToLower();
  33. var workText = @text.Split(separatorCharacters);
  34. return workText;
  35. }
  36.  
  37. private static List<string> findOutWordList(string word)
  38. {
  39. var wordList = new List<string>();
  40. var strBuilder = new StringBuilder();
  41. foreach (var symbol in word)
  42. {
  43. if (char.IsLetter(symbol) || symbol == '\'')
  44. {
  45. strBuilder.Append(symbol);
  46. }
  47. else
  48. {
  49. var finWord = strBuilder.ToString();
  50. finWord.Trim();
  51. if (finWord != "")
  52. {
  53. wordList.Add(finWord);
  54. strBuilder = new StringBuilder();
  55. }
  56. }
  57. }
  58. return wordList;
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement