Git Product home page Git Product logo

nladdresslexer's Introduction

Dutch address parser

Dutch address parser is a library to parse address lines into the segments street, number and suffix.

packagist version

Example: Plein 1926 12 A

Will be parsed to:

Street Number Suffix
Plein 1926 12 A

Installation

Composer is used to install this package

composer require noxxienl/nladdressparser

Usage

use noxxienl\nladdresslexer\Parser;

$parser = new Parser;
$parser->evaluate('Plein 1926 12 A');

echo $parser->getStreet() . "\r\n"; // Plein 1926
echo $parser->getNumber() . "\r\n"; // 12
echo $parser->getSuffix() . "\r\n"; // A

echo $parser->getOriginalString();

Usage with splitting address

Sometimes you may have address that does not have the format street, number & suffix. To let the parser correctly do its work you need to split the string on your own before the parser can do its work.

For example: 50 A, Ringweg Zuid / Rijksweg A20

use noxxienl\nladdresslexer\Parser;

$parser = new Parser;

list($number, $street) = explode(', ', '50 A, Ringweg Zuid / Rijksweg A20');
$parser->evaluate($street, $number);

echo $parser->getStreet() . "\r\n"; // Ringweg Zuid / Rijgsweg A20
echo $parser->getNumber() . "\r\n"; // 50
echo $parser->getSuffix() . "\r\n"; // A

echo $parser->getOriginalString();

Usage for splitting only numbers

Sometimes you may wish to split only the number and suffix. You can do so by setting the formatting of the parser to the following before executing the parsing:

Parser::setAddressFormat([
    Parser::T_NUMBER,
    Parser::T_SUFFIX,
]);

Be carefull: When setting the address format, it is changed for every parsing to beyond that point. Reset the format to its original state when you want to parse a full address:

Parser::setAddressFormat([
    Parser::T_STREET,
    Parser::T_NUMBER,
    Parser::T_SUFFIX,
]);

Testing

Testing is done using pestphp. (https://pestphp.com/)

./vendor/bin/pest

To run the tests.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Bugs

Submit a issue to the github repository and if you can find the fix be sure to also submit a pull request!

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.