Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with Python and Json
#1
Hello,

I'm starting to build a simple chatbot and I need help getting the chatbot's response from it's json dictionary/vocabulary.

I want to have it so when I say a greeting pattern like "hi", "hello", etc... the chatbot will respond with a random greeting response from the json.
Now if I say an easter egg like: "Open the pod bay doors", I want the chatbot to pick the correct response (which would be: "I'm afraid I can't do that")

My question is how would I go about programming this?

(Also, I'm using Manjaro -Arch Linux and I'm having a hard time downloading tensorflow, tflearn, chatterbot, ect.. right now, so it would be greatly appreciated if you could show me how to do this without the need for deep learning modules like that, because I've been looking all over the internet and all the tutorials/examples include one or more of those modules (Although I got nltk to work but I'm still learning how it works))


Thanks in advance.


This is my json right now:

{"intents": [
    {"tag": "greeting",
        "patterns": ["Hello", "Hey", "Hi", "Good day"],
        "responses": ["Hello Commander. How may I be of service?", 
                    "Welcome back Commander. It's good to see you again"],
        "context": [""]
    },
    {"tag":"farewell",
        "patterns": ["Bye", "See you later", "Goodbye", "I'm leaving", "See you tomorrow"],
        "responses":["Farewell", "Ok, see you", "Goodbye", "Finally, I can enjoy some rest", 
                    "Enjoy your day", "Have a nice day"],
        "context":[""]
    },
    {"tag":"thanks",
        "patterns":["Thanks", "Thank you", "Thanks a lot", "Awesome, thanks"],
        "responses":["No problem", "Happy to help", "Glad to be of service", "My pleasure",
                    "It's no big deal"],
        "context":[""]
    },
    {"tag":"noAnswer",
        "patterns":[],
        "responses":["Sorry, I can't understand you", "I'm not sure I understand"],
        "context":[""]
    },
    {"tag":"about",
        "patterns":["Who are you?", "How old are you?", "Can you get smarter?", "Are you happy?",
                    "What's your favourite movie?", "What's your favourite song?", "Where are you?"],
        "responses":["I am Baxter", "Old enough. Now go fetch me a beer. It's been a rough day",
                     "If you program me to", "Is anyone really happy?", "The Terminator", 
                     "Jimmy cliff's: I can see clearly now", "I'm everywhere and nowhere"],
        "context":[""]
    },
    {"tag":"easterEggs",
        "patterns":["Open the pod bay doors", "Who you gonna call?", "I am your father",  
                    "May the force be with you", "What is your power level?", "Testing"],
        "responses":["I'm afraid I can't do that", "Ghostbusters!", "No, that's not true. That's impossible", 
                    "And may the force be with you, always", "It's over nine-thousand!", "Receiving, over"],
        "context":[""]
    },
    {"tag":"other",
        "patterns":["Will you marry me", "Are we friends", "I'm busy"],
        "responses":["A life long commitment with you? I'm going to need some time to think about it",
                    "It's a great show, but it's nowhere near reality", "Then why are you bothering me?"],
        "context":[""]
    }
]}
Reply
#2
Would this work like an array where I would call the appropriate index to the question/Easter egg I trigger?

Like this link I found on google
although this isn't meant for python, can it be done like that in python, where I can choose what answer from my Json will be printed to the screen? If so, how?

Thanks.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Split json into separate json based on node value CzarR 1 5,681 Jul-08-2022, 07:55 PM
Last Post: Larz60+
  difficulties to chage json data structure using json module in python Sibdar 1 2,101 Apr-03-2020, 06:47 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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