JSON Dataset

A dataset in machine learning is, quite simply, a collection of data pieces that can be treated by a computer as a single unit for analytic and prediction purposes.

There are two ways to create datasets to train Chatman.
1-With Patterns
2-Without Patterns.

With Patterns

BotWithPatterns class is used to train Chatman with this dataset.


        
    {
      "intents": [

      {"tag": "intro",
        "patterns": ["Hello", "Hi", "Hi there", "hey", "Whats up"],
        "responses": ["Hi, how can I help you ?", "Hey, do you need any help ?", "How are you doing?", "Greetings !"]
      },

      {"tag": "age",
        "patterns": ["how old are you?", "can i know your age", "what is your age"],
        "responses": ["I am 19 years old", "My age is 19", "My birthday is Jan 5th and I was born in 2002, so I am 19 years old !"]
      }]
    
    }

      
    

This is a json file, where 'intents' is an array containing tags, patterns and responses. Chatman needs this data to learn.
You can say patterns are user inputs, and responses are the bot answers. tag is just describing the category of patterns and responses.

If a pattern matches, the bot will pick a random response from responses array of matched tag.

Calling Function

You might want to call a function when a pattern matches. You can do this by providing a “function” name. The function name should be in string without round brackets. You can also write class's static method name.

      
    {
      "intents": [

      {"tag": "price",
        "patterns": ["What is the price of ", "can you tell me the price of"],
        "function" : "PriceFinder",
        "responses": ["yes"]
      },

      {"tag": "age",
        "patterns": ["how old are you?", "can i know your age", "what is your age"],
        "function" : "Check::AgeMatched",
        "responses": ["I am 19 years old"]
      }]
    
    }
    
    

The function will receive four parameters.

1-UserText : User original text.
2-CleanText : User cleaned text after lemmatizing and removing stop words.
3-MatchedTag : The name of matched tag.
4-BotResponse : Response which bot picked for this pattern.

        

      function PriceFinder($userText, $cleanText, $tag, $botResp){
          //perform task
      }
        
      

Without Patterns

BotWithoutPatterns class is used to train Chatman with this dataset.

If you want a simple chatbot without any complex questions then this approach is fast and easy.

        
    {
      "responses": [
          "My name is chatman",
          "We accept paypal and credit cards as payment",
          "I speak English"
        ]
  }
    
      

Calling Function

You can also call a function if a response matches to the query, chatbot will call the function. To use a function simply write function name inside curly brackets in response string.

        
    {
      "responses": [
          "My name is chatman {NameMatched()}",
          "We accept paypal and credit cards as payment",
          "I speak English"
        ]
  }
    
      

The function will receive three parameters.

1-UserText : User original text.
2-CleanText : User cleaned text after lemmatizing and removing stop words.
3-BotResponse : Response which chatbot has picked.

        

      function NameMatched($userText, $cleanText, $botResp){
          //perform task
      }