Python Forum
How to add multiple lines response in chatterbot?
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to add multiple lines response in chatterbot?
#2
(May-16-2018, 06:48 AM)PrateekG Wrote:
conv = open('chats.txt','r').readlines()
In that line you are splitting all the multiple lines answers in single line entries of your table.
You need to fix a convention for your chat.txt file so you can recognise multiple lines responses.
The easiest thing is to use some well known format (json, yaml, .ini files...) but if you want to create your own, here is an example of a code that will concatenate lines that start with a space to the previous line:
with open('chats.txt','rt') as fd:
    conv = []
    last = ''
    for line in fd:
        # Remove newline and whitespaces only from the end of the line
        line = line.rstrip()
        if line.startswith(' '):
            last += line
        else:
            if last:
                conv.append(last)
            last = line
# Add the final string... last will be '' ony if the file is empty
if last:
    conv.append(last)
As format is not great (using spaces to specify the indent... where I have seen that Rolleyes) and you need to clean up more (remove duplicate spaces, check that any question has answers...), but shows you some ideas about how to preprocess your input to the chatbot.
Reply


Messages In This Thread
RE: How to add multiple lines response in chatterbot? - by killerrex - May-16-2018, 07:59 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Amazon AWS - how to install the library chatterbot wpaiva 9 4,114 Feb-01-2020, 08:18 AM
Last Post: brighteningeyes
  Scrape multiple lines with regex greetings 2 3,158 Jul-04-2018, 09:09 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020