BotWithPatterns

getResponse(string $text) : array

train() : void 

finalResponse(string $resp) : string

newResponse(string $resp): string

onDefaultResp(callable $func): void

exportModel(string $filepath): bool

importModel(string $filepath): bool

improveDataset(string $tag, string $userText, string $jsonPath, bool $jsonPretty = false): bool
  
        

Methods

getResponse(string $text) : array
This method takes text/query of type string and return an array. The array contains the name of matched tag and the bot response.


    
    ['tag' => $tag, 'resp' => $resp] = $bot->getResponse("Hello Chatman");

    echo $resp;

        

finalResponse(string $resp) : string
This method takes one argument of type string . It is extremely useful when you want to control bot response from a function. It will set the final response of the chatbot, which means the bot will not change its response.


        
    $customResponse = $bot->finalResponse("This is my custom response.");

    ['tag' => $tag, 'resp' => $resp] = $bot->getResponse("Hello Chatman");

    echo $resp;

    //OUTPUT : This is my custom response.
  
      

newResponse(string $resp) : string
This method accepts one argument of type string. It will return the argument. It is useful when you want to send multiple responses without blocking getResponse method. It will also update the last bot response in session.


      
    $customResponse = $bot->newResponse("This is my new response.");

    ['tag' => $tag, 'resp' => $resp] = $bot->getResponse("Hello Chatman");

    echo $customResponse . "<br>";
    echo $resp;

    /* OUTPUT : 
    
    This is my new response.
    Hi, how can I help you ?

    */

    

train() : void
This method is used to train the chatbot.


    
    $bot->train()

      

onDefaultResp(callable $func): void
You might want to call a function if the chatbot failed to predict any response. This method takes an argument of type string but it should be a name of a function. You can also pass a static method name.


      
    function defaultResp($userText){
        //perform task
    }

    onDefaultResp('defaultResp');

    

exportModel(string $filepath): bool
This method is used to export the trained model for future use. Before using this method make sure the folder is not write protected.


      
    $bot->exportModel("/folder/myModel");

    

imporModel(string $filepath): bool
This method is used to import the trained model.


      
    $bot->importModel("/folder/myModel");

    

improveDataset(string $tag, string $userText, string $jsonPath, bool $jsonPretty = false): bool
This method is used to improve the dataset of json file. It will update the patterns array if the user query was not there. This method should be called after getting the response from chatbot.


      
    ['tag' => $tag, 'resp' => $resp] = $bot->getResponse("Hello Chatman");
    $userQuery = "Who are you ?";
    improveDataset($tag, $userQuery, "chatbot-duplicate.json",true);

Properties

data : array
Contains Dataset.

isFinalResponse : bool
Is final response set or not ?

stopWords : array
Contains stop words. You can add or remove any stop word.

defaultMsg : string
Contains default message.