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 @ 2023-07-09 21:04  wstong  阅读(598)  评论(0编辑  收藏  举报