How to parse an Unstructured International Address in PHP using NLP

There are few worse headaches for a business than dealing with improperly formatted addresses from customers. While manually fixing can work in the short term, it’s generally better to have an automatic solution in place. Here’s where Natural Language Processing (NLP) comes in. It will allow us to apply proper structure to any international address all on its own. And here’s the best part, we are going to implement this with little to no effort by using an API.

First off, we shall use this command to install our client via command line.

composer require cloudmersive/cloudmersive_validate_api_client

Wait for that to finish, then call this function:

<?phprequire_once(__DIR__ . '/vendor/autoload.php');// Configure API key authorization: Apikey$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// $config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Apikey', 'Bearer');$apiInstance = new Swagger\Client\Api\AddressApi(// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.// This is optional, `GuzzleHttp\Client` will be used as GuzzleHttp\Client(),$config);$input = new \Swagger\Client\Model\ParseAddressRequest(); // \Swagger\Client\Model\ParseAddressRequest | Input parse requesttry {$result = $apiInstance->addressParseString($input);print_r($result);} catch (Exception $e) {echo 'Exception when calling AddressApi->addressParseString: ', $e->getMessage(), PHP_EOL;}?>

Already done. Now any address you input will be analyzed using NLP on the API’s side, and sent back to you in proper format. Problem solved!

Image for post

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store