File size: 683 Bytes
f307bb6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import spacy
from spacy.lang.en.stop_words import STOP_WORDS

# Load spaCy's English language model
nlp = spacy.load('en_core_web_sm')

def extract_keywords(question):
    # Process the question using spaCy NLP pipeline
    doc = nlp(question)
    
    # Extract keywords by removing stopwords, punctuation, and selecting nouns/adjectives
    keywords = [token.text for token in doc if token.is_stop == False and token.is_punct == False and token.pos_ in ['NOUN', 'ADJ', 'VERB']]
    
    return keywords

# Example chatbot question
question = "What is the weather like in New York City today?"

# Extract keywords
keywords = extract_keywords(question)

print("Keywords:", keywords)