Skip to content

Instantly share code, notes, and snippets.

@mkhorasani
Created October 21, 2020 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkhorasani/1e57dd6cd2a3481ad28ead3ffded86ee to your computer and use it in GitHub Desktop.
Save mkhorasani/1e57dd6cd2a3481ad28ead3ffded86ee to your computer and use it in GitHub Desktop.
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