python - jionlp地址解析库

发布时间 2023-07-09 21:07:53作者: wstong

1. jionlp安装

pip3 install -i 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}