+def _week_similarities(week, simfunc, tfidf_path, term_colname, min_df, max_df, included_subreddits, topN, outdir:Path):
+ term = term_colname
+ term_id = term + '_id'
+ term_id_new = term + '_id_new'
+ print(f"loading matrix: {week}")
+ entries, subreddit_names = reindex_tfidf(infile = tfidf_path,
+ term_colname=term_colname,
+ min_df=min_df,
+ max_df=max_df,
+ included_subreddits=included_subreddits,
+ topN=topN,
+ week=week)
+ mat = csr_matrix((entries[tfidf_colname],(entries[term_id_new], entries.subreddit_id_new)))
+ print('computing similarities')
+ sims = column_similarities(mat)
+ del mat
+ sims = pd.DataFrame(sims.todense())
+ sims = sims.rename({i: sr for i, sr in enumerate(subreddit_names.subreddit.values)}, axis=1)
+ sims['_subreddit'] = names.subreddit.values
+ outfile = str(Path(outdir) / str(week))
+ write_weekly_similarities(outfile, sims, week, names)