]> code.communitydata.science - cdsc_reddit.git/blob - tfidf_comments.py
Add code for running tf-idf at the weekly level.
[cdsc_reddit.git] / tfidf_comments.py
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_tfidf_dataset
5
6 ## TODO:need to exclude automoderator / bot posts.
7 ## TODO:need to exclude better handle hyperlinks. 
8
9 spark = SparkSession.builder.getOrCreate()
10 df = spark.read.parquet("/gscratch/comdata/users/nathante/reddit_tfidf_test.parquet_temp")
11
12 include_subs = set(open("/gscratch/comdata/users/nathante/cdsc-reddit/top_25000_subs_by_comments.txt"))
13 include_subs = {s.strip('\n') for s in include_subs}
14
15 df = build_tfidf_dataset(df, include_subs, 'term')
16
17 df.write.parquet('/gscratch/comdata/users/nathante/subreddit_tfidf.parquet',mode='overwrite',compression='snappy')
18 spark.stop()

Community Data Science Collective || Want to submit a patch?