Created
July 19, 2019 15:17
-
-
Save ritvikmath/30db1e1a3b93c685087c8dfa0f06d02b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #initialize tf-idf dictionary for secret speech | |
| tfidf_dict_secret = {} | |
| #initalize bush and obama scores to zero | |
| bush_score = 0 | |
| obama_score = 0 | |
| #for each phrase in the secret TF dictionary... | |
| for phrase, tf in d_secret.items(): | |
| #get the importance of this phrase in the bush tf-idf dictionary | |
| bush_weight = tfidf_dict_bush[phrase] if phrase in tfidf_dict_bush.keys() else 0 | |
| #get the importance of this phrase in the obama tf-idf dictionary | |
| obama_weight = tfidf_dict_obama[phrase] if phrase in tfidf_dict_obama.keys() else 0 | |
| #scale the importance of this phrase by its frequncy in the secret document | |
| bush_score += bush_weight*tf | |
| obama_score += obama_weight*tf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment