michielgerritsen / extract-address-parts
Get the (Dutch) street, house number, and extension from a concatenated string
Installs: 2 979
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^7.0|^8.0
- ext-mbstring: *
Requires (Dev)
- phpunit/phpunit: ^9.2
README
Extract information from Dutch addresses
I have been in this situation multiple times: You need to provide an housernumber and addition for some API. But the provided dataset only has the complete address. This library tries to solve this issue. For instance:
- Kerkstraat 95A
- Street:
Kerkstraat
- Housenumber:
95
- Addition:
A
- Street:
This library has 3 ways available to extract the data:
AddressExtraction
- The default. Tries to extract by using regex.PrecisionAddressExtraction
- This uses library files with all known Dutch streetnames and tries to match them.CombinedAddressExtraction
- A combination of the previoius 2: It tries thePrecisionAddressExtraction
first, and if that fails, fallsback to theAddressExtraction
.
This is a lightweight repository, it has no external dependencies, except for PHPUnit for testing.
Installation
composer require michielgerritsen/extract-address-parts
Usage
AddressExtraction
use MichielGerritsen\ExtractAddressParts\AddressExtraction; use MichielGerritsen\ExtractAddressParts\PrecisionAddressExtraction; use MichielGerritsen\ExtractAddressParts\CombinedAddressExtraction; use MichielGerritsen\ExtractAddressParts\VO\AddressExtractionResult; use MichielGerritsen\ExtractAddressParts\Exceptions\AddressExtractionError; /** @var AddressExtractionResult $result */ try { $result = (new AddressExtraction())->process(['Kerkstraat 95A']); $result = (new PrecisionAddressExtraction())->process(['Kerkstraat 95A']); $result = (new CombinedAddressExtraction())->process(['Kerkstraat 95A']); } catch (AddressExtractionError $exception) { die('Uh oh, this address seems to be invalid.'); } $result->getStreet(); // Kerkstraat $result->getHousenumber(); // 95 $result->getAddition(); // A
Contributing
Pull the repository, run composer install
. Testing can be done by composer test
.