1. Go to this page and download the library: Download nigel/wit_parser library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nigel / wit_parser example snippets
use Nigel\WitParser\WitParserService;
class YourController extends Controller
{
public function parseMessage()
{
$parser = new WitParserService();
$result = $parser->parse("What's the weather in New York?");
// Access parsed data
$intent = $result->intent; // e.g., "get_weather"
$confidence = $result->confidence; // e.g., 0.95
$entities = $result->entities; // Array of entities
$raw = $result->raw; // Raw API response
}
}
use Nigel\WitParser\WitManagerService;
class YourController extends Controller
{
public function manageWit()
{
$manager = new WitManagerService();
// Create a new entity
$entity = $manager->createEntity('location', [
['value' => 'New York'],
['value' => 'London']
]);
// Get all entities
$entities = $manager->getEntities();
// Create a new intent
$intent = $manager->createIntent('get_weather', [
['text' => 'What\'s the weather in New York?'],
['text' => 'How\'s the weather in London?']
]);
// Get all intents
$intents = $manager->getIntents();
// Get app info
$appInfo = $manager->getAppInfo();
}
}