Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Newtonsoft.Json.Linq;
  7.  
  8.  
  9.  
  10. namespace HTTPProject
  11. {
  12. public class UniqueWords
  13. {
  14. public string[] UniqueTitleWords { get; set; }
  15. public string[] UniqueBodyWords { get; set; }
  16.  
  17. public static UniqueWords ListCreation()
  18. {
  19. List<string> titles = new List<string>();
  20. List<string> bodies = new List<string>();
  21.  
  22. string textFromFile = System.IO.File.ReadAllText(@"C:\Users\Nick\Desktop\WriteLines.json");
  23.  
  24. JArray PostsArray = JArray.Parse(textFromFile);
  25.  
  26. IList<Values> Posts = PostsArray.Select(p => new Values
  27. {
  28. userId = (int)p["userId"],
  29. id = (int)p["id"],
  30. title = (string)p["title"],
  31. body = (string)p["body"],
  32. }).ToList();
  33.  
  34. for (int i = 0; i < Posts.Count; i++)
  35. {
  36. titles.Add(Posts[i].title.ToString());
  37. bodies.Add(Posts[i].body.ToString());
  38. }
  39.  
  40.  
  41. var titlesArray = string.Join(" ", titles.ToArray()).Split(' ').Distinct().ToArray();
  42. var bodiesArray = string.Join(" ", bodies.ToArray()).Split(' ').Distinct().ToArray();
  43. var words = new UniqueWords();
  44. words.UniqueTitleWords = titlesArray;
  45. words.UniqueBodyWords = bodiesArray;
  46.  
  47. return words;
  48. }
  49. }
  50.  
  51.  
  52. public class Values
  53. {
  54. public int userId { get; set; }
  55. public int id { get; set; }
  56. public string title { get; set; }
  57. public string body { get; set; }
  58.  
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement