]> code.communitydata.science - cdsc_reddit.git/blobdiff - similarities/cosine_similarities.py
Merge branch 'excise_reindex' of code:cdsc_reddit into excise_reindex
[cdsc_reddit.git] / similarities / cosine_similarities.py
index c1e99c99fcba91991997d5171bf35296cc0921cf..b9bab17b44a97a78070bd17f7cfc1dad407d0130 100644 (file)
@@ -2,14 +2,18 @@ import pandas as pd
 import fire
 from pathlib import Path
 from similarities_helper import similarities, column_similarities
 import fire
 from pathlib import Path
 from similarities_helper import similarities, column_similarities
+from functools import partial
 
 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'):
 
     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)
 
 
 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'):
 
     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)
 
-
+# change so that these take in an input as an optional argument (for speed, but also for idf).
 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):
 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):
-    return cosine_similarities('/gscratch/comdata/output/reddit_similarity/tfidf/comment_terms.parquet',
+
+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):
+
+    return cosine_similarities(infile,
                                'term',
                                outfile,
                                min_df,
                                'term',
                                outfile,
                                min_df,
@@ -18,10 +22,11 @@ def term_cosine_similarities(outfile, min_df=None, max_df=None, included_subredd
                                topN,
                                exclude_phrases,
                                from_date,
                                topN,
                                exclude_phrases,
                                from_date,
-                               to_date)
+                               to_date
+                               )
 
 
-def author_cosine_similarities(outfile, min_df=2, max_df=None, included_subreddits=None, topN=10000, from_date=None, to_date=None):
-    return cosine_similarities('/gscratch/comdata/output/reddit_similarity/tfidf/comment_authors.parquet',
+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):
+    return cosine_similarities(infile,
                                'author',
                                outfile,
                                min_df,
                                'author',
                                outfile,
                                min_df,
@@ -30,10 +35,11 @@ def author_cosine_similarities(outfile, min_df=2, max_df=None, included_subreddi
                                topN,
                                exclude_phrases=False,
                                from_date=from_date,
                                topN,
                                exclude_phrases=False,
                                from_date=from_date,
-                               to_date=to_date)
+                               to_date=to_date
+                               )
 
 
-def author_tf_similarities(outfile, min_df=2, max_df=None, included_subreddits=None, topN=10000, from_date=None, to_date=None):
-    return cosine_similarities('/gscratch/comdata/output/reddit_similarity/tfidf/comment_authors.parquet',
+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):
+    return cosine_similarities(infile,
                                'author',
                                outfile,
                                min_df,
                                'author',
                                outfile,
                                min_df,
@@ -43,7 +49,8 @@ def author_tf_similarities(outfile, min_df=2, max_df=None, included_subreddits=N
                                exclude_phrases=False,
                                from_date=from_date,
                                to_date=to_date,
                                exclude_phrases=False,
                                from_date=from_date,
                                to_date=to_date,
-                               tfidf_colname='relative_tf')
+                               tfidf_colname='relative_tf'
+                               )
 
 
 if __name__ == "__main__":
 
 
 if __name__ == "__main__":

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