Guest User

Untitled

a guest
Dec 29th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. # Importing the libraries
  2. from chatterbot import ChatBot
  3. from chatterbot.trainers import ListTrainer
  4.  
  5.  
  6. def convert_to_ascii(statement):
  7. """
  8. Converts unicode characters to ASCII character equivalents.
  9. For example: "på fédéral" becomes "pa federal".
  10. """
  11. import unicodedata
  12.  
  13. text = unicodedata.normalize('NFKD', statement.text)
  14. text = text.encode('ascii', 'ignore').decode('utf-8')
  15.  
  16. statement.text = str(text)
  17. return statement
  18.  
  19.  
  20. chatbot = ChatBot(
  21. 'Bob the Bot',
  22. preprocessors=[
  23. 'chatterbot.preprocessors.clean_whitespace'
  24. ],
  25. )
  26. #create the bot
  27. conv = open('chats.txt','r', encoding = 'utf-8', errors= 'ignore').read().split('\n')
  28.  
  29.  
  30. trainer = ListTrainer(chatbot)
  31.  
  32.  
  33.  
  34. trainer.train(conv) #train the bot
  35. preprocessors = [
  36. 'chatterbot.preprocessors.clean_whitespace']
  37. logic_adapters = ['chatterbot.logic.BestMatch']
  38.  
  39. while True:
  40. request = input('You: ')
  41. response = chatbot.get_response(request)
  42. print('bot:', response)
Advertisement
Add Comment
Please, Sign In to add comment