python - jionlp地址解析库

1. jionlp安装

pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple jionlp

github地址 https://github.com/dongrixinyu/JioNLP

2. 简单使用

import jionlp as jio
# 地址
address = '武侯区红牌楼街19号红星大厦9楼2号'
# 指定参数town_village(bool),可获取乡镇、村、社区两级详细地名
# 指定参数change2new(bool)可自动将旧地址转换为新地址
res = jio.parse_location(address, change2new=True, town_village=True)
print(res)
# {'province': '四川省',
#  'city': '成都市',
#  'county': '武侯区',
#  'detail': '红牌楼街19号红星大厦9楼2号',
#  'full_location': '四川省成都市武侯区红牌楼街19号红星大厦9楼2号',
#  'orig_location': '武侯区红牌楼街19号红星大厦9楼2号',
#  'town': None,
#  'village': None}

address = '河南省邓州市刘集镇'
res = jio.parse_location(address, change2new=True, town_village=True)
print(res)
# {'province': '河南省',
#  'city': '南阳市',
#  'county': '邓州市',
#  'detail': '刘集镇',
#  'full_location': '河南省南阳市邓州市刘集镇',
#  'orig_location': '河南省邓州市刘集镇',
#  'town': '刘集镇',
#  'village': None}

3. 更多使用

jionlp这个库还提供了其他许多功能,例如,身份证解析,电话号码归属地、运营商解析等,可以去github查看说明文档
身份证解析

idCard = '52010320171109002X'
res = jio.parse_id_card(idCard)
print(res)

# {'province': '贵州省',
#  'city': '贵阳市',
#  'county': '云岩区',
#  'birth_year': '2017',
#  'birth_month': '11',
#  'birth_day': '09',
#  'gender': '女',
#  'check_code': 'x'}
posted @   wstong  阅读(882)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示