import nltk
from nltk.tokenize import word_tokenize
from nltk.corpus import wordnet
# Initialize the NLTK data
nltk.download('punkt')
nltk.download('wordnet')
# Define a dictionary to store the AI assistant's knowledge
knowledge = {
'hello': 'Hello! How can I assist you today?',
'how are you': 'I\'m doing great, thanks for asking!',
'what is your name': 'My name is Friday',
'default': 'I didn\'t understand that. Can you please rephrase?'
}
# Define a function to process user input
def process_input(input_text):
# Tokenize the input text
tokens = word_tokenize(input_text)
# Check if the input text matches any of the known phrases
for phrase, response in knowledge.items():
if phrase in input_text.lower():
return response
# If no match is found, return the default response
return knowledge['default']
# Define a function to interact with the AI assistant
def interact():
print('Welcome to the AI Assistant!')
while True:
user_input = input('You: ')
response = process_input(user_input)
print('AI Assistant:', response)
# Start the interaction
interact()
I'll guide you through the process of building a basic AI assistant using Python
and the Natural Language Processing (NLP) library, NLTK. We'll create a simple
chatbot that can understand and respond to basic user queries.
AI Assistant Requirements:
1.Python 3.8 or later
2.NLTK library (install using pip install nltk)
3.nltk.download('punkt') for tokenization
4.nltk.download('wordnet') for wordnet