1 from pyspark.sql import functions as f
2 from pyspark.sql import SparkSession
3 from pyspark.sql import Window
4 from similarities_helper import build_weekly_tfidf_dataset
8 ## TODO:need to exclude automoderator / bot posts.
9 ## TODO:need to exclude better handle hyperlinks.
11 spark = SparkSession.builder.getOrCreate()
12 df = spark.read.parquet("/gscratch/comdata/output/reddit_ngrams/comment_terms.parquet")
14 include_subs = pd.read_csv("/gscratch/comdata/output/reddit_similarity/subreddits_by_num_comments.csv")
16 include_subs = set(include_subs.loc[include_subs.comments_rank <= 25000]['subreddit'])
18 # remove [deleted] and AutoModerator (TODO remove other bots)
19 # df = df.filter(df.author != '[deleted]')
20 # df = df.filter(df.author != 'AutoModerator')
22 df = build_weekly_tfidf_dataset(df, include_subs, 'term')
25 df.write.parquet('/gscratch/comdata/output/reddit_similarity/tfidf_weekly/comment_terms.parquet', mode='overwrite', compression='snappy')