BotWithoutPatterns
getResponse(string $text) : string train() : void finalResponse(string $resp) : string newResponse(string $resp): string onDefaultResp(callable $func): void exportModel(string $filepath): bool importModel(string $filepath): bool
Methods
getResponse(string $text) : string
This method takes text/query of type string and return the bot response as string.
$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 chatbot will not change its response.
$customResponse = $bot->finalResponse("This is my custom response.");
$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 sent argument. It is useful when you want to send multiple responses without blocking getResponse method. It will also update the last bot response in sessions.
$customResponse = $bot->newResponse("This is my new response.");
$resp = $bot->getResponse("Hello Chatman");
$customResponse2 = $bot->newResponse("This is my 2nd new response.");
echo $customResponse . "<br>";
echo $resp . "<br>";
echo $customResponse2;
/* OUTPUT :
This is my new response.
Hi, how can I help you ?
This is my 2nd new response.
*/
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 path 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");
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.