]> code.communitydata.science - cdsc_reddit.git/blob - similarities/cosine_similarities.py
update pushshift dumps.
[cdsc_reddit.git] / similarities / cosine_similarities.py
1 import pandas as pd
2 import fire
3 from pathlib import Path
4 from similarities_helper import similarities, column_similarities
5 from functools import partial
6
7 def cosine_similarities(infile, term_colname, outfile, min_df=None, max_df=None, included_subreddits=None, topN=500, exclude_phrases=False, from_date=None, to_date=None, tfidf_colname='tf_idf'):
8
9     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)
10
11 # change so that these take in an input as an optional argument (for speed, but also for idf).
12 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):
13
14 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):
15
16     return cosine_similarities(infile,
17                                'term',
18                                outfile,
19                                min_df,
20                                max_df,
21                                included_subreddits,
22                                topN,
23                                exclude_phrases,
24                                from_date,
25                                to_date
26                                )
27
28 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):
29     return cosine_similarities(infile,
30                                'author',
31                                outfile,
32                                min_df,
33                                max_df,
34                                included_subreddits,
35                                topN,
36                                exclude_phrases=False,
37                                from_date=from_date,
38                                to_date=to_date
39                                )
40
41 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):
42     return cosine_similarities(infile,
43                                'author',
44                                outfile,
45                                min_df,
46                                max_df,
47                                included_subreddits,
48                                topN,
49                                exclude_phrases=False,
50                                from_date=from_date,
51                                to_date=to_date,
52                                tfidf_colname='relative_tf'
53                                )
54
55
56 if __name__ == "__main__":
57     fire.Fire({'term':term_cosine_similarities,
58                'author':author_cosine_similarities,
59                'author-tf':author_tf_similarities})
60

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