Perform Named Entity Recognition using NLP in PHP
1 min readJul 1, 2021
Natural Language Processing technology can be incredibly helpful for an array of tasks that formerly required days and even weeks of research. In this brief tutorial, we will demonstrate how you can use an NLP API in PHP to scan an input text string and automatically extract the named entities, saving you from a lot of manual coding and researching.
Let’s begin the operation by running this command to install the SDK:
composer require cloudmersive/cloudmersive_nlp_api_client
Now, we can call the function with the following code:
<?php
require_once(__DIR__ . '/vendor/autoload.php');// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');$apiInstance = new Swagger\Client\Api\ExtractEntitiesApi(
new GuzzleHttp\Client(),
$config
);
$value = new \Swagger\Client\Model\ExtractEntitiesRequest(); // \Swagger\Client\Model\ExtractEntitiesRequest | Input stringtry {
$result = $apiInstance->extractEntitiesPost($value);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling ExtractEntitiesApi->extractEntitiesPost: ', $e->getMessage(), PHP_EOL;
}
?>
The entity type and entity text will be returned for all named entities that were identified.