predicthq/address-formatter-templates
最新稳定版本:v1.0.0
Composer 安装命令:
composer require predicthq/address-formatter-templates
包简介
Address formatter templates from https://github.com/OpenCageData/address-formatting - used with the predicthq/address-formatter package.
关键字:
README 文档
README
address formatting
A quick example
Given a set of address parts
house_number: 17
road: Rue du Médecin-Colonel Calbairac
neighbourhood: Lafourguette
suburb: Toulouse Ouest
postcode: 31000
city: Toulouse
county: Toulouse
state: Midi-Pyrénées
country: France
country_code: FR
you want to write logic to compile addresses in the format consumers expect
17 Rue du Médecin-Colonel Calbairac
31000 Toulouse
France
or perhaps simply
Rue du Médecin-Colonel Calbairac
Toulouse
France
This repository contains templates for various address formats used in territories around the world. It also contains test cases.
Which addresses we're talking about
The intended use-case is database or geocoding systems (forward, reverse, autocomplete) where we know both the country of the address and the language of the user/reader. The address is displayed to a consumer (for example in an app) and not used to print on an envelope for actual postal delivery. We use it to format output from the OpenCage Geocoder.
We have to deal with
- incomplete data
- anything with a name (peaks, bridges, bus stops)
Unlike physical post (office) mail we don't have to deal with
- apartment/flat number, floor numbers
- PO boxes
- translating the language of the (destination) address. Whatever language is input is output.
Processing logic
Our goal with this repository is a series of (programming) language independent templates. Those templates can then be processed by whatever software you like.
We've written, use and maintain a working implementation of a processer in Perl, see (CPAN: Geo::Address::Formatter, github repo). There is also an open-source implementation in PHP.
We would love there to be other langauge implementations. If you do write a processor, please let us know so we can list it here.
Coverage
As of Sat 25 Mar 2017 coverage is:
We are aware of 248 territories
We have tests for 250 (100%) territories
We have rules for 249 (100%) territories
0 (0%) territories have neither rules nor tests
We need more language specific abbreviations, please see conf/abbreviations
A detailed breakdown of test and configuration coverage can be found by running bin/coverage.pl -d. A list of all known territories is in conf/country_codes.yaml Note: the list is simple all officially assigned ISO 3166-1 alpha-2 codes, and is not a political statement on whether or not these territories are or are not or should or should not be political states.
File format
The files are in YAML format. The templates are written in Mustache. Both formats are human readable, strict, solve escaping and support comments. YAML allows references (called "ankers") to avoid copy&paste, Mustache allows sub-templates (called "partials").
How to add your country/territory
- edit the .yaml testcase for the country/territory in
testcases/countries. The file names correspond to the appropriate ISO 3166-1 alpha-2 code - seeconf/country_codes.yaml
- a good way to get sample data is:
- find an addressed location (house, business, etc) in your target territory in OpenStreetMap
- get the coordinates (lat, long) of the location
- put the coordinates into the OpenCage Geocoder demo page
- look at the resulting JSON in the Raw Response tab
- edit
conf/countries/worldwide.yaml
- Possibly your country/territory uses an existing generic format as
defined at the top of the file. If so, great, just map you
country_code to the generic template. You may still want to add
clean up code (see the entry for
DEas an example). - If not you need to define a new generic rule set
- possibly you will need to define new state/region mappings in
conf/state_codes.yaml
- possibly you will need to define new state/region mappings in
- to test you will now need to process the .yaml test via a processer (see above) and ensure the input leads to the desired output.
If in doubt, please get in touch via github issues.
Formatting rules
Currently we support the following formatting rules:
replace:regex that operates on the input values, useful for removing bureaucratic cruft like "London Borough of ". Note if you define the regex starting with format X=, for example city= it should operate only on values with that keypostformat_replace:regex that operates on the final outputadd_component:with a value of the formcomponent=XXXXchange_country:change the country value of the input, useful for dependent territories. Can include a substitution like$stateso that that component value is then inserted into the new country value. Seetestcases/countries/sh.yamlfor an example.use_country:use the formating configuration of another country, useful for dependent territories to avoid duplicating configuration
The future
More tests! For every rule about addresses there are exceptions and edge cases to consider. More test cases are always needed.
Planned features
- basic error checking, for example ignore things which obviously can not be postcodes
- define rules for postcode format specifically
We welcome your pull requests. Together we can address the world!
Who are we?
We run the OpenCage Geocoder.
We also run #geomob, a meetup of London location based service developers where we do our best to highlight geoinnovation.
Further reading
Here's our blog post anouncing this project and the motivations behind it.
You may enjoy Michael Tandy's Falsehoods Programmers Believe about Addresses.
If it's actual address data you're after, check out OpenAddresses.
If you want to turn longitude, latitude into well formatted addresses or placenames, well that's what a geocoder does. Check out ours: OpenCage Geocoder.
If all this convinces you that address are evil, please check out what3words which allows you to dispense with them entirely.
predicthq/address-formatter-templates 适用场景与选型建议
predicthq/address-formatter-templates 是一款 基于 Perl 开发的 Composer 扩展包,目前已累计 177.6k 次下载、GitHub Stars 达 3, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「address」 「templates」 「predicthq」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 predicthq/address-formatter-templates 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 predicthq/address-formatter-templates 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 predicthq/address-formatter-templates 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Address formatter using country templates from https://github.com/OpenCageData/address-formatting
CakePHP 4.x AdminLTE Theme.
Maps in minutes. Powered by the Google Maps API.
Redirects TYPO3 visitors automatic or with a suggestlink to another language and/or root page.
Bookdown.io With Bootswatch Styles And Prism Syntax Highlighting
统计信息
- 总下载量: 177.6k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 25
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 未知