def test_jieba_extract(): """地址全部在句子开头的情况""" pca, addr = addressparser._jieba_extract('湖北武汉复兴路111号') print(pca, addr) assert addr == '复兴路111号' assert pca.province == '湖北省' assert pca.province_pos == 0 assert pca.city == '武汉市' assert pca.city_pos == 2
def test_jieba_extract2(): """地址在句子中间的情况""" pca, addr = addressparser._jieba_extract('我家的地址是湖北武汉武昌区复兴路111号') assert addr == '我家的地址是湖北武汉武昌区复兴路111号' assert pca.province == '湖北省' assert pca.province_pos == 6 assert pca.city == '武汉市' assert pca.city_pos == 8 assert pca.area == '武昌区' assert pca.area_pos == 10
def test_jieba_extract3(): """测试地名出现两次省名的情况""" pca, addr = addressparser._jieba_extract('我家的地址是湖北武汉武昌区复兴路111号上海市') assert addr == '我家的地址是湖北武汉武昌区复兴路111号上海市' assert pca.province == '湖北省' assert pca.province_pos == 6 assert pca.city == '武汉市' assert pca.city_pos == 8 assert pca.area == '武昌区' assert pca.area_pos == 10