edited the chatbook to prevent loop

master
Your Name 7 years ago
parent 661df78c14
commit c7642722e2

@ -114,5 +114,5 @@ tts: output/chatbot.txt ocr/output.txt ## text to speech. Dependencies: espea
ttssr-human-only: ocr/output.txt ## Loop: text to speech-speech recognition. Dependencies: espeak, pocketsphinx
bash src/ttssr-loop-human-only.sh ocr/output.txt
chatbook: ocr/output.txt
chatbook: ocr/output.txt #chatbot based on the knowledge of the scans Dependencies: nltk_rake, irc, nltk
python3 src/chatbook.py

@ -4,6 +4,7 @@ import random
from nltk.tokenize import sent_tokenize, word_tokenize
import json
#from thread import start_new_thread
import os
r= Rake()
@ -14,36 +15,44 @@ def chunks(l, n):
class HelloBot(irc.bot.SingleServerIRCBot):
def __init__(self, channel, nickname, server, port=6667, index=None):
print("connecting to chatroom...")
irc.bot.SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
self.channel = channel
self.index = index
def on_welcome(self, c, e):
c.join(self.channel)
print("joined chatroom")
def on_privmsg(self, c, e):
pass
def on_pubmsg(self, c, e):
print(e.arguments, e.source)
msg = e.arguments[0]
msg=e.arguments[0]
incoming_msg = e.arguments[0]
print(incoming_msg)
r.extract_keywords_from_text(msg)
#r.get_ranked_phrases_with_scores()
listOfKeys = r.get_ranked_phrases()
for keyWord in listOfKeys:
if keyWord in self.index:
msg = (index.get(keyWord)[0].get('sentence'))
msg_where = "I found this in {}".format(index.get(keyWord)[0].get('filename'))
else:
msg = "I don't know anything about that"
msg_where = ""
msg_where = ""
for chunk in chunks(msg, 400):
c.privmsg(self.channel, chunk)
if incoming_msg != "I don't know anything about that":
for keyWord in listOfKeys:
if keyWord in self.index:
msg = (index.get(keyWord)[0].get('sentence'))
msg_where = "I found this in {}".format(index.get(keyWord)[0].get('filename'))
else:
msg = "I don't know anything about that"
msg_where = ""
for chunk in chunks(msg, 400):
c.privmsg(self.channel, chunk)
print(chunk)
c.privmsg(self.channel, msg_where)
c.privmsg(self.channel, msg_where)
@ -68,6 +77,8 @@ if __name__ == "__main__":
index={}
#print(index)
myhost = os.uname()[1]
bot = HelloBot(args.channel, args.nickname, args.server, args.port, index)
bot = HelloBot(args.channel, "{0}-{1}-bot".format(myhost, len(index)), args.server, args.port, index)
bot.start()

Loading…
Cancel
Save