File size: 503 Bytes
432c28d
 
 
 
 
a6fe56c
432c28d
 
 
a9c2158
432c28d
 
 
 
 
 
 
85adb6e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import nltk
from rake_nltk import Rake

# Download NLTK data (if not already downloaded)
nltk.download('punkt')
nltk.download('stopwords')

def extract_keywords(text):
    # Initialize Rake with stopwords set to None (to keep all words)
    rake = Rake(max_length=2, include_repeated_phrases=False)
    
    # Extract keywords from the input text
    rake.extract_keywords_from_text(text)
    
    # Get the ranked keywords
    ranked_keywords = rake.get_ranked_phrases()
    
    return ranked_keywords