Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/src/categories.rs b/src/categories.rs
- index f8eb1c1..d0ddcf2 100644
- --- a/src/categories.rs
- +++ b/src/categories.rs
- @@ -525,16 +525,21 @@ pub fn run(_source_dir: PathBuf) -> std::string::String {
- let ru_news_per_category = ru_text_corpus.predict_category();
- let en_news_per_category = en_text_corpus.predict_category();
- - // let en_news_per_category = ru_news_per_category.clone()
- -
- let json = json!([
- - {CATEGORIES[0]: ([&ru_news_per_category[0][..], &en_news_per_category[0][..]]).concat()},
- - {CATEGORIES[1]: ([&ru_news_per_category[1][..], &en_news_per_category[1][..]]).concat()},
- - {CATEGORIES[2]: ([&ru_news_per_category[2][..], &en_news_per_category[2][..]]).concat()},
- - {CATEGORIES[3]: ([&ru_news_per_category[3][..], &en_news_per_category[3][..]]).concat()},
- - {CATEGORIES[4]: ([&ru_news_per_category[4][..], &en_news_per_category[4][..]]).concat()},
- - {CATEGORIES[5]: ([&ru_news_per_category[5][..], &en_news_per_category[5][..]]).concat()},
- - {CATEGORIES[6]: ([&ru_news_per_category[6][..], &en_news_per_category[6][..]]).concat()}
- + {"lang_code": "ru", "category": CATEGORIES[0], "articles": ru_news_per_category[0]},
- + {"lang_code": "ru", "category": CATEGORIES[1], "articles": ru_news_per_category[1]},
- + {"lang_code": "ru", "category": CATEGORIES[2], "articles": ru_news_per_category[2]},
- + {"lang_code": "ru", "category": CATEGORIES[3], "articles": ru_news_per_category[3]},
- + {"lang_code": "ru", "category": CATEGORIES[4], "articles": ru_news_per_category[4]},
- + {"lang_code": "ru", "category": CATEGORIES[5], "articles": ru_news_per_category[5]},
- + {"lang_code": "ru", "category": CATEGORIES[6], "articles": ru_news_per_category[6]},
- + {"lang_code": "en", "category": CATEGORIES[0], "articles": en_news_per_category[0]},
- + {"lang_code": "en", "category": CATEGORIES[1], "articles": en_news_per_category[1]},
- + {"lang_code": "en", "category": CATEGORIES[2], "articles": en_news_per_category[2]},
- + {"lang_code": "en", "category": CATEGORIES[3], "articles": en_news_per_category[3]},
- + {"lang_code": "en", "category": CATEGORIES[4], "articles": en_news_per_category[4]},
- + {"lang_code": "en", "category": CATEGORIES[5], "articles": en_news_per_category[5]},
- + {"lang_code": "en", "category": CATEGORIES[6], "articles": en_news_per_category[6]},
- ]);
- let json = serde_json::to_string_pretty(&json);
- diff --git a/src/news.rs b/src/news.rs
- index 06b9e98..08a11a5 100644
- --- a/src/news.rs
- +++ b/src/news.rs
- @@ -16,8 +16,8 @@ pub fn run(_source_dir: PathBuf) -> String {
- let ru_news = ru_text_corpus.filter_news();
- let en_news = en_text_corpus.filter_news();
- - let news: Vec<_> = ru_news.iter().chain(en_news.iter()).collect();
- - let json = json!({ "articles": news });
- + let json = json!([{ "lang_code": "ru", "articles": ru_news },
- + { "lang_code": "en", "articles": en_news }]);
- let json = serde_json::to_string_pretty(&json);
- json.unwrap()
- diff --git a/src/threads.rs b/src/threads.rs
- index 857e653..87d3963 100644
- --- a/src/threads.rs
- +++ b/src/threads.rs
- @@ -20,6 +20,7 @@ use std::sync::mpsc::channel;
- #[derive(Debug, Serialize)]
- pub struct Thread {
- + pub lang_code: String,
- pub title: String,
- pub articles: Vec<String>,
- }
- @@ -98,6 +99,7 @@ impl TextCorpus {
- .collect();
- threads.push(Thread {
- + lang_code: self.lang().to_string(),
- title: title.to_string(),
- articles,
- });
- diff --git a/src/top.rs b/src/top.rs
- index 825569a..f01e464 100644
- --- a/src/top.rs
- +++ b/src/top.rs
- @@ -33,6 +33,7 @@ pub struct Thread {
- #[derive(Debug, Serialize, Clone)]
- pub struct Top {
- + pub lang_code: String,
- pub category: String,
- pub threads: Vec<Thread>,
- }
- @@ -141,11 +142,13 @@ impl TextCorpus {
- });
- }
- tops.push(Top {
- + lang_code: self.lang().to_string(),
- category: category_name.to_string(),
- threads: category_threads,
- })
- }
- tops.push(Top {
- + lang_code: self.lang().to_string(),
- category: "any".to_string(),
- threads: any_tops,
- });
- @@ -176,20 +179,8 @@ pub fn run(_source_dir: PathBuf) -> std::string::String {
- let ru_tops = ru_text_corpus.build_tops();
- let en_tops = en_text_corpus.build_tops();
- - let mut tops = Vec::new();
- - for (ru_tops, en_tops) in ru_tops.iter().zip(en_tops.iter()) {
- - let joint_tops = Top {
- - category: ru_tops.category.clone(),
- - threads: ru_tops
- - .threads
- - .iter()
- - .chain(en_tops.threads.iter())
- - .map(|v| v.clone())
- - .collect(),
- - };
- - tops.push(joint_tops);
- - }
- -
- + let tops: Vec<_> = ru_tops.iter().chain(en_tops.iter()).collect();
- let json = serde_json::to_string_pretty(&tops);
- +
- json.unwrap()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement