]> code.communitydata.science - cdsc_reddit.git/blob - similarities/cosine_similarities.py
c1e99c99fcba91991997d5171bf35296cc0921cf
[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
6 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'):
7
8     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)
9
10
11 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):
12     return cosine_similarities('/gscratch/comdata/output/reddit_similarity/tfidf/comment_terms.parquet',
13                                'term',
14                                outfile,
15                                min_df,
16                                max_df,
17                                included_subreddits,
18                                topN,
19                                exclude_phrases,
20                                from_date,
21                                to_date)
22
23 def author_cosine_similarities(outfile, min_df=2, max_df=None, included_subreddits=None, topN=10000, from_date=None, to_date=None):
24     return cosine_similarities('/gscratch/comdata/output/reddit_similarity/tfidf/comment_authors.parquet',
25                                'author',
26                                outfile,
27                                min_df,
28                                max_df,
29                                included_subreddits,
30                                topN,
31                                exclude_phrases=False,
32                                from_date=from_date,
33                                to_date=to_date)
34
35 def author_tf_similarities(outfile, min_df=2, max_df=None, included_subreddits=None, topN=10000, from_date=None, to_date=None):
36     return cosine_similarities('/gscratch/comdata/output/reddit_similarity/tfidf/comment_authors.parquet',
37                                'author',
38                                outfile,
39                                min_df,
40                                max_df,
41                                included_subreddits,
42                                topN,
43                                exclude_phrases=False,
44                                from_date=from_date,
45                                to_date=to_date,
46                                tfidf_colname='relative_tf')
47
48
49 if __name__ == "__main__":
50     fire.Fire({'term':term_cosine_similarities,
51                'author':author_cosine_similarities,
52                'author-tf':author_tf_similarities})
53

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