Created
October 21, 2020 19:04
-
-
Save mkhorasani/1e57dd6cd2a3481ad28ead3ffded86ee to your computer and use it in GitHub Desktop.
This file contains 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
def keyphrases(file,min_word,max_word,num_phrases): | |
text = file | |
text = text.lower() | |
text = ''.join(s for s in text if ord(s)>31 and ord(s)<126) | |
text = text | |
text = re.sub(' +', ' ', text) | |
text = text.translate(str.maketrans('', '',string.punctuation)) | |
text = ''.join([i for i in text if not i.isdigit()]) | |
r = Rake(min_length = min_word, max_length = max_word) | |
r.extract_keywords_from_text(text) | |
phrases = r.get_ranked_phrases() | |
if num_phrases < len(phrases): | |
phrases = phrases[0:num_phrases] | |
return phrases |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment