Code Monkey home page Code Monkey logo

geocoding's Introduction

Java 8 CI

介绍

本项目旨在将不规范(或者连续)的文本地址进行尽可能的标准化, 以及对两个地址进行相似度的计算

地理编码技术, 主要分为如下步骤

  • 地址标准库
  • 地址标准化
  • 相似度计算

pom

<dependencies>
    <dependency>
        <groupId>io.patamon.geocoding</groupId>
        <artifactId>geocoding</artifactId>
        <version>1.1.6</version>
    </dependency>
</dependencies>

<repositories>
    <repository>
        <id>patamon.release.repository</id>
        <name>github release repository</name>
        <url>https://raw.github.com/icemimosa/maven/release/</url>
    </repository>
</repositories>

1. 数据测试

方法调用: Geocoding

  • normalizing: 标准化
  • analyze: 解析成分词文档
  • similarity: 相似度计算
  • similarityWithResult: 相似度计算, 返回包含更多丰富的数据

1.1 标准化

>> 输入: 山东青岛市北区山东省青岛市市北区水清沟街道九江路20号大都会3号楼2单元1303
>> 输出:
Address(
	provinceId=370000000000, province=山东省, 
	cityId=370200000000, city=青岛市, 
	districtId=370203000000, district=市北区, 
	streetId=370203030000, street=水清沟街道, 
	townId=null, town=null, 
	villageId=null, village=null, 
	road=九江路, 
	roadNum=20号, 
	buildingNum=3号楼2单元1303, 
	text=大都会
)
>> 输入: 上海上海宝山区宝山区【新沪路5811-802  水韵华庭 】 (水韵华庭附近)
>> 输出: 
Address(
	provinceId=310000000000, province=上海, 
	cityId=310100000000, city=上海市, 
	districtId=310113000000, district=宝山区, 
	streetId=null, street=null, 
	townId=null, town=null, 
	villageId=null, village=null, 
	road=新沪路, 
	roadNum=58弄, 
	buildingNum=11-802, 
	text=水韵华庭水韵华庭附近
)
  • 返回的对象解释
    • province相关: 省
    • city相关: 市
    • district相关: 区、县
    • street相关: 街道
    • town相关: 乡镇
    • village相关: 村
    • road: 道路
    • roadNum: 路号
    • buildingNum: 建筑物号
    • text: 标准化后为匹配的地址。一般包含小区, 商场名称等信息

注: 如果对text的结果不是很满意, 比如出现重复或不准确, 可以通过分词的手段解决

1.2 相似度

>> 输入:
  浙江金华义乌市南陈小区82号
  浙江金华义乌市稠城街道浙江省义乌市宾王路99号后面南陈小区82号
>> 输出: 
  0.8451542547285166
>> 输入:
  山东省沂水县四十里堡镇东艾家庄村206号
  浙江金华义乌市南陈小区82号
>> 输出:
  0.0

1.3 自定义地址设置

// 100000000000 代表**的ID
Geocoding.addRegionEntry(88888888, 100000000000, "尼玛省", RegionType.Province)
Geocoding.addRegionEntry(8888888, 88888888, "尼玛市", RegionType.City)
Geocoding.addRegionEntry(888888, 8888888, "泥煤市", RegionType.District)

>> 输入: **尼玛省尼玛市泥煤市泥煤大道888号xxx
>> 输出:
Address(
	provinceId=88888888, province=尼玛省, 
	cityId=8888888, city=尼玛市, 
	districtId=888888, district=泥煤市, 
	streetId=null, street=null, 
	townId=null, town=null, 
	villageId=null, village=null, 
	road=泥煤大道, 
	roadNum=888号, 
	buildingNum=null, 
	text=xxx
)

Tips: 可以从「国家标准地址库」中获取「父级城市ID」

2. 说明

2.1 标准地址库

项目目前采用的是 淘宝物流4级地址 的标准地址库

也可以采用国家的标准地址库 (对应的github库, **5级行政区域mysql库)

2.1.1 导入**5级行政区域mysql库注意事项

  1. 本测试配置基于Server version: 8.0.21 MySQL Community Server - GPL环境,其它可能略有差异,可通过下面两个SQL确认配置是否OK
show variables like '%CHARACTER%';
show variables like '%max_allowed_packet%';
  1. 设置max_allowed_packet,[mysqld]下max_allowed_packet = 2000M,[mysqldump]下max_allowed_packet = 2000M
  2. 设置字符集,[client]下default-character-set=utf8mb4,[mysqld]下character-set-server=utf8mb4和init_connect='SET NAMES utf8mb4',[mysql]下default-character-set=utf8mb4

2.2 标准化

  1. 首先基于正则提取出道路、建筑物号等信息
  2. 省市区等匹配
    1. 将标准的地址库建立倒排索引
    2. 将文本从起始位置开始, 采用最大长度优先的方式匹配所有词条
    3. 对所有匹配结果进行标准行政区域从属关系校验

2.3 相似度计算

  1. 对输入的两个地址进行标准化
  2. 对省市区等信息分配不同的权重
  3. 对道路号, 建筑号进行语义处理, 分配权重
  4. 对剩余文本(text)使用IK Analyzer进行分词
  5. 对两个结果集使用余弦相似度算法计算相似度

项目参考address-semantic-search,简化了流程,修复了各种不规则错误,使得使用更加方便。

Release Log

  • 1.1.3
    • 新增自定义地址设置
  • 1.1.4
    • 修复一些匹配错误的bug
  • 1.1.6
    • 升级地址库和包版本, 修复一些匹配错误的地址

geocoding's People

Contributors

icemimosa avatar dependabot-preview[bot] avatar overcat avatar cheese8 avatar

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.