From: Nathan TeBlunthuis Date: Tue, 3 Aug 2021 22:03:40 +0000 (-0700) Subject: Merge branch 'master' of code:cdsc_reddit X-Git-Url: https://code.communitydata.science/cdsc_reddit.git/commitdiff_plain/14ab979f5910637809dec24617276eb7bd0d9554?hp=f20365c07e93ae71b95af314f869fcdcfb58100f Merge branch 'master' of code:cdsc_reddit --- diff --git a/dumps/pull_pushshift_comments.sh b/dumps/pull_pushshift_comments.sh index 3f6d2c9..40d82d8 100755 --- a/dumps/pull_pushshift_comments.sh +++ b/dumps/pull_pushshift_comments.sh @@ -8,7 +8,5 @@ wget -r --no-parent -A 'RC_201*.bz2' -U $user_agent -P $output_dir -nd -nc $base wget -r --no-parent -A 'RC_201*.xz' -U $user_agent -P $output_dir -nd -nc $base_url wget -r --no-parent -A 'RC_201*.zst' -U $user_agent -P $output_dir -nd -nc $base_url -# starting in 2020 we use daily dumps not monthly dumps -wget -r --no-parent -A 'RC_202*.gz' -U $user_agent -P $output_dir -nd -nc $base_url/daily/ ./check_comments_shas.py diff --git a/similarities/cosine_similarities.py b/similarities/cosine_similarities.py index 38b1d7c..cc681b1 100644 --- a/similarities/cosine_similarities.py +++ b/similarities/cosine_similarities.py @@ -8,9 +8,9 @@ def cosine_similarities(infile, term_colname, outfile, min_df=None, max_df=None, return similarities(infile=infile, simfunc=column_similarities, term_colname=term_colname, outfile=outfile, min_df=min_df, max_df=max_df, included_subreddits=included_subreddits, topN=topN, exclude_phrases=exclude_phrases,from_date=from_date, to_date=to_date, tfidf_colname=tfidf_colname) -def term_cosine_similarities(outfile, min_df=None, max_df=None, included_subreddits=None, topN=500, exclude_phrases=False, from_date=None, to_date=None): +def term_cosine_similarities(outfile, infile='/gscratch/comdata/output/reddit_similarity/tfidf/comment_terms_100k.parquet', min_df=None, max_df=None, included_subreddits=None, topN=500, exclude_phrases=False, from_date=None, to_date=None): - return cosine_similarities('/gscratch/comdata/output/reddit_similarity/tfidf/comment_terms_100k.parquet', + return cosine_similarities(infile, 'term', outfile, min_df, @@ -22,8 +22,8 @@ def term_cosine_similarities(outfile, min_df=None, max_df=None, included_subredd to_date ) -def author_cosine_similarities(outfile, min_df=2, max_df=None, included_subreddits=None, topN=10000, from_date=None, to_date=None): - return cosine_similarities('/gscratch/comdata/output/reddit_similarity/tfidf/comment_authors_100k.parquet', +def author_cosine_similarities(outfile, infile='/gscratch/comdata/output/reddit_similarity/tfidf/comment_authors_100k.parquet', min_df=2, max_df=None, included_subreddits=None, topN=10000, from_date=None, to_date=None): + return cosine_similarities(infile, 'author', outfile, min_df, @@ -35,8 +35,8 @@ def author_cosine_similarities(outfile, min_df=2, max_df=None, included_subreddi to_date=to_date ) -def author_tf_similarities(outfile, min_df=2, max_df=None, included_subreddits=None, topN=10000, from_date=None, to_date=None): - return cosine_similarities('/gscratch/comdata/output/reddit_similarity/tfidf/comment_authors_100k.parquet', +def author_tf_similarities(outfile, infile='/gscratch/comdata/output/reddit_similarity/tfidf/comment_authors_100k.parquet', min_df=2, max_df=None, included_subreddits=None, topN=10000, from_date=None, to_date=None): + return cosine_similarities(infile, 'author', outfile, min_df, diff --git a/similarities/similarities_helper.py b/similarities/similarities_helper.py index 57a36ca..3ace8f2 100644 --- a/similarities/similarities_helper.py +++ b/similarities/similarities_helper.py @@ -60,7 +60,7 @@ def reindex_tfidf(infile, term_colname, min_df=None, max_df=None, included_subre if included_subreddits is None: included_subreddits = select_topN_subreddits(topN) else: - included_subreddits = set(open(included_subreddits)) + included_subreddits = set(map(str.strip,map(str.lower,open(included_subreddits)))) if exclude_phrases == True: tfidf = tfidf.filter(~f.col(term_colname).contains("_")) diff --git a/similarities/tfidf.py b/similarities/tfidf.py index 30033a8..7f579fa 100644 --- a/similarities/tfidf.py +++ b/similarities/tfidf.py @@ -11,7 +11,7 @@ def _tfidf_wrapper(func, inpath, outpath, topN, term_colname, exclude, included_ df = df.filter(~ f.col(term_colname).isin(exclude)) if included_subreddits is not None: - include_subs = list(open(included_subreddits)) + include_subs = set(map(str.strip,map(str.lower, open(included_subreddits)))) else: include_subs = select_topN_subreddits(topN) @@ -28,40 +28,44 @@ def tfidf_weekly(inpath, outpath, topN, term_colname, exclude, included_subreddi return _tfidf_wrapper(build_weekly_tfidf_dataset, inpath, outpath, topN, term_colname, exclude, included_subreddits) def tfidf_authors(outpath='/gscratch/comdata/output/reddit_similarity/tfidf/comment_authors.parquet', - topN=25000): + topN=25000, + included_subreddits=None): return tfidf("/gscratch/comdata/output/reddit_ngrams/comment_authors.parquet", outpath, topN, 'author', ['[deleted]','AutoModerator'], - included_subreddits=None + included_subreddits=included_subreddits ) def tfidf_terms(outpath='/gscratch/comdata/output/reddit_similarity/tfidf/comment_terms.parquet', - topN=25000): + topN=25000, + included_subreddits=None): return tfidf("/gscratch/comdata/output/reddit_ngrams/comment_terms.parquet", outpath, topN, 'term', [], - included_subreddits=None + included_subreddits=included_subreddits ) def tfidf_authors_weekly(outpath='/gscratch/comdata/output/reddit_similarity/tfidf_weekly/comment_authors.parquet', - topN=25000): + topN=25000, + included_subreddits=None): return tfidf_weekly("/gscratch/comdata/output/reddit_ngrams/comment_authors.parquet", outpath, topN, 'author', ['[deleted]','AutoModerator'], - included_subreddits=None + included_subreddits=included_subreddits ) def tfidf_terms_weekly(outpath='/gscratch/comdata/output/reddit_similarity/tfidf_weekly/comment_terms.parquet', - topN=25000): + topN=25000, + included_subreddits=None): return tfidf_weekly("/gscratch/comdata/output/reddit_ngrams/comment_terms.parquet", @@ -69,7 +73,7 @@ def tfidf_terms_weekly(outpath='/gscratch/comdata/output/reddit_similarity/tfidf topN, 'term', [], - included_subreddits=None + included_subreddits=included_subreddits )