daily pastebin goal
9%
SHARE
TWEET

Untitled

a guest Apr 27th, 2018 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from chatterbot import ChatBot
  2. from chatterbot.trainers import ListTrainer
  3. from bs4 import BeautifulSoup
  4. import re
  5. import mysql.connector
  6.  
  7.  
  8.  
  9. bot = ChatBot(
  10.     'Teddy',
  11.     storage_adapter='chatterbot.storage.SQLStorageAdapter',
  12.     input_adapter='chatterbot.input.TerminalAdapter',
  13.     output_adapter='chatterbot.output.TerminalAdapter',
  14.     database='./database.sqlite3'
  15. )
  16. bot.set_trainer(ListTrainer)
  17.  
  18. cnx = mysql.connector.connect(user='XXXX', password='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
  19.                               host='127.0.0.1',
  20.                               database='my_wiki')
  21. cursor = cnx.cursor()
  22. print('Loading wiki data...')
  23. cursor.execute("SELECT old_text FROM text")
  24. result = cursor.fetchall()
  25. for row in result:
  26.   s = str(row[0])
  27.   name = re.findall(r"'''(.*?)'''", s)
  28.   if name:
  29.     what = name[0]
  30.     soup = BeautifulSoup(what)
  31.     data = re.sub("[[]", '', soup.text)
  32.     data1 = re.sub("[]]", '', data)
  33.     data2 = re.sub("[']", '', data1).encode('utf-8').strip()
  34.     print(data2)
  35.     str1 = str('Who is ' + data2)
  36.     str2 = str('What is ' + data2)
  37.     str3 = str('When is ' + data2)
  38.     str4 = str('Why is ' + data2)
  39.     str5 = str('Why are ' + data2)
  40.     newString = ''
  41.     validLetters = ".abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
  42.     newString = ''.join([char for char in s if char in validLetters]).encode('utf-8').strip()
  43.     bot.train([
  44.       str1,
  45.       newString,
  46.     ])
  47.     bot.train([
  48.       str2,
  49.       newString,
  50.     ])
  51.     bot.train([
  52.       str3,
  53.       newString,
  54.     ])
  55.     bot.train([
  56.       str4,
  57.       newString,
  58.     ])
  59.     bot.train([
  60.       str5,
  61.       newString,
  62.     ])
  63.     print(newString)
  64.  
  65. print('Done loading wiki data...')
  66. while True:
  67.     try:
  68.      bot_input = bot.get_response(None)
  69.  
  70.     except(KeyboardInterrupt, EOFError, SystemExit):
  71.         cnx.close()
  72.         break
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top