Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 5.12 KB | None | 0 0
  1. diff --git a/src/categories.rs b/src/categories.rs
  2. index f8eb1c1..d0ddcf2 100644
  3. --- a/src/categories.rs
  4. +++ b/src/categories.rs
  5. @@ -525,16 +525,21 @@ pub fn run(_source_dir: PathBuf) -> std::string::String {
  6.      let ru_news_per_category = ru_text_corpus.predict_category();
  7.      let en_news_per_category = en_text_corpus.predict_category();
  8.  
  9. -    // let en_news_per_category = ru_news_per_category.clone()
  10. -
  11.      let json = json!([
  12. -        {CATEGORIES[0]: ([&ru_news_per_category[0][..], &en_news_per_category[0][..]]).concat()},
  13. -        {CATEGORIES[1]: ([&ru_news_per_category[1][..], &en_news_per_category[1][..]]).concat()},
  14. -        {CATEGORIES[2]: ([&ru_news_per_category[2][..], &en_news_per_category[2][..]]).concat()},
  15. -        {CATEGORIES[3]: ([&ru_news_per_category[3][..], &en_news_per_category[3][..]]).concat()},
  16. -        {CATEGORIES[4]: ([&ru_news_per_category[4][..], &en_news_per_category[4][..]]).concat()},
  17. -        {CATEGORIES[5]: ([&ru_news_per_category[5][..], &en_news_per_category[5][..]]).concat()},
  18. -        {CATEGORIES[6]: ([&ru_news_per_category[6][..], &en_news_per_category[6][..]]).concat()}
  19. +        {"lang_code": "ru", "category": CATEGORIES[0], "articles": ru_news_per_category[0]},
  20. +        {"lang_code": "ru", "category": CATEGORIES[1], "articles": ru_news_per_category[1]},
  21. +        {"lang_code": "ru", "category": CATEGORIES[2], "articles": ru_news_per_category[2]},
  22. +        {"lang_code": "ru", "category": CATEGORIES[3], "articles": ru_news_per_category[3]},
  23. +        {"lang_code": "ru", "category": CATEGORIES[4], "articles": ru_news_per_category[4]},
  24. +        {"lang_code": "ru", "category": CATEGORIES[5], "articles": ru_news_per_category[5]},
  25. +        {"lang_code": "ru", "category": CATEGORIES[6], "articles": ru_news_per_category[6]},
  26. +        {"lang_code": "en", "category": CATEGORIES[0], "articles": en_news_per_category[0]},
  27. +        {"lang_code": "en", "category": CATEGORIES[1], "articles": en_news_per_category[1]},
  28. +        {"lang_code": "en", "category": CATEGORIES[2], "articles": en_news_per_category[2]},
  29. +        {"lang_code": "en", "category": CATEGORIES[3], "articles": en_news_per_category[3]},
  30. +        {"lang_code": "en", "category": CATEGORIES[4], "articles": en_news_per_category[4]},
  31. +        {"lang_code": "en", "category": CATEGORIES[5], "articles": en_news_per_category[5]},
  32. +        {"lang_code": "en", "category": CATEGORIES[6], "articles": en_news_per_category[6]},
  33.      ]);
  34.  
  35.      let json = serde_json::to_string_pretty(&json);
  36. diff --git a/src/news.rs b/src/news.rs
  37. index 06b9e98..08a11a5 100644
  38. --- a/src/news.rs
  39. +++ b/src/news.rs
  40. @@ -16,8 +16,8 @@ pub fn run(_source_dir: PathBuf) -> String {
  41.      let ru_news = ru_text_corpus.filter_news();
  42.      let en_news = en_text_corpus.filter_news();
  43.  
  44. -    let news: Vec<_> = ru_news.iter().chain(en_news.iter()).collect();
  45. -    let json = json!({ "articles": news });
  46. +    let json = json!([{ "lang_code":  "ru", "articles":  ru_news },
  47. +        { "lang_code":  "en", "articles": en_news }]);
  48.      let json = serde_json::to_string_pretty(&json);
  49.  
  50.      json.unwrap()
  51. diff --git a/src/threads.rs b/src/threads.rs
  52. index 857e653..87d3963 100644
  53. --- a/src/threads.rs
  54. +++ b/src/threads.rs
  55. @@ -20,6 +20,7 @@ use std::sync::mpsc::channel;
  56.  
  57.  #[derive(Debug, Serialize)]
  58.  pub struct Thread {
  59. +    pub lang_code: String,
  60.      pub title: String,
  61.      pub articles: Vec<String>,
  62.  }
  63. @@ -98,6 +99,7 @@ impl TextCorpus {
  64.                  .collect();
  65.  
  66.              threads.push(Thread {
  67. +                lang_code: self.lang().to_string(),
  68.                  title: title.to_string(),
  69.                  articles,
  70.              });
  71. diff --git a/src/top.rs b/src/top.rs
  72. index 825569a..f01e464 100644
  73. --- a/src/top.rs
  74. +++ b/src/top.rs
  75. @@ -33,6 +33,7 @@ pub struct Thread {
  76.  
  77.  #[derive(Debug, Serialize, Clone)]
  78.  pub struct Top {
  79. +    pub lang_code: String,
  80.      pub category: String,
  81.      pub threads: Vec<Thread>,
  82.  }
  83. @@ -141,11 +142,13 @@ impl TextCorpus {
  84.                  });
  85.              }
  86.              tops.push(Top {
  87. +                lang_code: self.lang().to_string(),
  88.                  category: category_name.to_string(),
  89.                  threads: category_threads,
  90.              })
  91.          }
  92.          tops.push(Top {
  93. +            lang_code: self.lang().to_string(),
  94.              category: "any".to_string(),
  95.              threads: any_tops,
  96.          });
  97. @@ -176,20 +179,8 @@ pub fn run(_source_dir: PathBuf) -> std::string::String {
  98.      let ru_tops = ru_text_corpus.build_tops();
  99.      let en_tops = en_text_corpus.build_tops();
  100.  
  101. -    let mut tops = Vec::new();
  102. -    for (ru_tops, en_tops) in ru_tops.iter().zip(en_tops.iter()) {
  103. -        let joint_tops = Top {
  104. -            category: ru_tops.category.clone(),
  105. -            threads: ru_tops
  106. -                .threads
  107. -                .iter()
  108. -                .chain(en_tops.threads.iter())
  109. -                .map(|v| v.clone())
  110. -                .collect(),
  111. -        };
  112. -        tops.push(joint_tops);
  113. -    }
  114. -
  115. +    let tops: Vec<_> = ru_tops.iter().chain(en_tops.iter()).collect();
  116.      let json = serde_json::to_string_pretty(&tops);
  117. +
  118.      json.unwrap()
  119.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement