]> code.communitydata.science - cdsc_reddit.git/blob - tfidf_authors.py
f06a8ce72f4ec995d4dcaa8a2d4abf42b0d447df
[cdsc_reddit.git] / tfidf_authors.py
1 from pyspark.sql import SparkSession
2 from similarities_helper import build_tfidf_dataset
3
4 ## TODO:need to exclude automoderator / bot posts.
5 ## TODO:need to exclude better handle hyperlinks. 
6 spark = SparkSession.builder.getOrCreate()
7
8 df = spark.read.parquet("/gscratch/comdata/users/nathante/reddit_tfidf_test_authors.parquet_temp/part-00000-d61007de-9cbe-4970-857f-b9fd4b35b741-c000.snappy.parquet")
9
10 include_subs = set(open("/gscratch/comdata/users/nathante/cdsc-reddit/top_25000_subs_by_comments.txt"))
11 include_subs = {s.strip('\n') for s in include_subs}
12 df = df.filter(df.author != '[deleted]')
13 df = df.filter(df.author != 'AutoModerator')
14
15 df = build_tfidf_dataset(df, include_subs, 'author')
16
17 df.cache()
18
19 df.write.parquet('/gscratch/comdata/users/nathante/subreddit_tfidf_authors.parquet',mode='overwrite',compression='snappy')

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