zerodahero/address-normalization
Composer 安装命令:
composer require zerodahero/address-normalization
包简介
Converts mailing addresses into a normalized format
README 文档
README
Purpose
The main purpose of this package is as the first layer of address normalization and standardization. Recommended use is to pre-parse/normalize an address and compare to an existing cache/record set using the hash functions.
A way to normalize US mailing addresses without the need for an external service. This is a port of the perl module Geo::StreetAddress::US originally written by Schuyler D. Erle.
This is a fork from khartnett/address-normalization -- kudos for the original work!
Limitations
This is a very basic normalizer. It realistically only handles US-based addresses, and should not be considered dependable for strict address-to-address comparison. This normalizer does not verify the validity of the address! If you are dependent on accurate addresses, you need to be using some other means (3rd party service, most likely) to verify an address.
Why?
I forked and added features to this package because I needed a decent first-layer to pre-normalize addresses before sending them our standardization service. This helps us limit the number of calls and strict dependence on the service, but also lets us catch a few easy-to-match scenarios here and there, which is a better user experience.
Alternatives
Libpostal is probably the best of its class in this area. I decided not to use Libpostal because: (1) It requires a few Gbs of space, which is undesirable in my current environment, and (2) it's probably overkill, since I consider our 3rd party service to be authoritative in the matter anyway.
Installation
composer require zerodahero/address-normalization
Usage
Normalizing
<?php use ZeroDaHero\Normalizer; $normalizer = new Normalizer(); // This returns a \ZeroDaHero\Address object with the parsed components $address = $normalizer->parse('204 southeast Smith Street Harrisburg, or 97446'); $address->getAddressComponents(); /* output: [ "number" => "204", "street" => "Smith", "street_type" => "St", "unit" => "", "unit_prefix" => "", "suffix" => "", "prefix" => "SE", "city" => "Harrisburg", "state" => "OR", "postal_code" => "97446", "postal_code_ext" => null, "street_type2" => null, "prefix2" => null, "suffix2" => null, "street2" => null, ] */ $address->toString(); /* string_result: "204 SE Smith St, Harrisburg, OR 97446" */
Comparing
<?php use ZeroDaHero\Normalizer; $normalizer = new Normalizer(); $address1 = $normalizer->parse('204 southeast Smith Street Harrisburg, or 97446'); $address2 = $normalizer->parse('204 SE Smith St. Harrisburg, Oregon 97446'); // Same street, different number $address3 = $normalizer->parse('207 SE Smith St. Harrisburg, Oregon 97446'); $address1->is($address2); // true $address2->is($address3); // false $address1->isSameStreet($address3); // true // or can compare hashes directly $address1->getFullHash() === $address2->getFullHash(); // true
Formatting
<?php use ZeroDaHero\Normalizer; $normalizer = new Normalizer(); $address = $normalizer->parse('204 southeast Smith Street Harrisburg, or 97446'); $address->toString(); // or (string) $address; /* string: "204 SE Smith St, Harrisburg, OR 97446" */ $address->toArray(); /* array: [ '204 SE Smith St', 'Harrisburg, OR 97446' ]
Hashing
If you only need to make use of a consistent way of hashing (e.g. if you're starting with a dependable 5-part address, such as from a 3rd party service), you can build a SimpleAddress.
<?php use ZeroDaHero\SimpleAddress; $address = new SimpleAddress('1234 Main St NE', null, 'Minneapolis', 'MN', '55401'); $address->getHash(); // full hash minus zip $address->getFullHash(); // full hash including zip // or do it all with the factory method: SimpleAddress::hashFromParts('1234 Main St NE', null, 'Minneapolis', 'MN', '55401'); // CANNOT hash street, since the component parts don't exist $address->getStreetHash(); // throws exception
zerodahero/address-normalization 适用场景与选型建议
zerodahero/address-normalization 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 120.07k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2019 年 11 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「address」 「mailing」 「normalization」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 zerodahero/address-normalization 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zerodahero/address-normalization 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 zerodahero/address-normalization 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Maps in minutes. Powered by the Google Maps API.
Redirects TYPO3 visitors automatic or with a suggestlink to another language and/or root page.
Module adding custom shipping attribute for what3words address
De/normalize business objects without tightly coupling them to your normalization format
Mailing module for HiPanel
Powerful newsletter system for TYPO3
统计信息
- 总下载量: 120.07k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-11-18