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?
#10
Removing the chatterbot part (just interested in the input parser):
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)

for k, line in enumerate(conv):
    print(f"{k}: {line}")
The result is:
Output:
0: What are some common warning signs of stress and/or depression in men? 1: General signs of stress: Fast heart rate Muscle tension Increase in blood pressure Tense stomach 2: Long-term signs of stress: Frequent cold or flu Headaches Trouble sleeping Skin problems Digestion problems Poor concentration Negative thoughts Speech problems Anxiety Irritability Feelings of helplessness Poor eating Being accident prone Aggression.
So as you can see, only 3 lines (some of them really long) If you see it better, the conv array is:
[
  'What are some common warning signs of stress and/or depression in men?',
  'General signs of stress:  Fast heart rate  Muscle tension  Increase in blood pressure  Tense stomach',
  'Long-term signs of stress:  Frequent cold or flu  Headaches  Trouble sleeping  Skin problems  Digestion problems  Poor concentration  Negative thoughts  Speech problems  Anxiety  Irritability  Feelings of helplessness  Poor eating  Being accident prone  Aggression.'
]
You might need to improve the punctuation and format (i.e. there are many double spaces in the strings)
Reply


Messages In This Thread
RE: How to add multiple lines response in chatterbot? - by killerrex - May-17-2018, 12:25 PM

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