地址标准化城市解析以地址为准,匹配接口城市以输入为准

This commit is contained in:
xuhe
2021-04-26 22:39:07 +08:00
parent 7739232f1d
commit 43c88aa693
4 changed files with 20 additions and 8 deletions
@@ -167,7 +167,7 @@ public class AddressParserServiceImpl implements AddressParserService {
Building matchedBuilding;
//keywords使用aliyun接口返回的poi
AliyunBo aliyunBo = null;
if(params.isUseAliyunApi()){
if(params.isUseAliyunApi() && AddressParserGoal.Match.equals(addr.getAddressParserGoal())){
aliyunBo = aliyunService.addressStand(params.getAddress(), params.getCity());
if(aliyunBo != null){
String poi = ((aliyunBo.getPoi() == null ? "":aliyunBo.getPoi()) + (aliyunBo.getSubpoi() == null ? "":aliyunBo.getSubpoi())).replaceAll("\\s*", "");
@@ -201,11 +201,11 @@ public class AddressParserServiceImpl implements AddressParserService {
matchedBuilding.setSearchAddress(addr);
matchedBuilding.setSuggestName(getSuggestName(matchedBuilding));
matchedBuilding.setSuggestAddress(getSuggestAddress(matchedBuilding));
if(params.isUseAliyunApi() && aliyunBo != null){
if(params.isUseAliyunApi() && aliyunBo != null && AddressParserGoal.Match.equals(addr.getAddressParserGoal())){
completBuildingField(matchedBuilding, aliyunBo, params);
}
Address tempAddr = matchedBuilding.getSearchAddress();
if(StringUtils.isBlank(tempAddr.getProvince()) || StringUtils.isBlank(tempAddr.getCity()) || StringUtils.isBlank(tempAddr.getDistrict())|| StringUtils.isBlank(tempAddr.getStreet())){
if((StringUtils.isBlank(tempAddr.getProvince()) || StringUtils.isBlank(tempAddr.getCity()) || StringUtils.isBlank(tempAddr.getDistrict())|| StringUtils.isBlank(tempAddr.getStreet())) && AddressParserGoal.Match.equals(addr.getAddressParserGoal())){
// List<AddressMatchMetaData> metaDatas = addressRepoService.findAllByKeyword(null, params.getBuildingType(), new ArrayList<String>() {{add(tempAddr.getOrgAddress());}}, tempAddr.getLng(), tempAddr.getLat(), 100, false);
tempAddr.addKeyword(tempAddr.getOrgAddress());
List<AddressMatchMetaData> metaDatas = findMatchMetaData(tempAddr, params.getBuildingType(), MetaDataType.MAP, false);
@@ -385,6 +385,7 @@ public class AddressParserServiceImpl implements AddressParserService {
addr.setSuggestDistrict(params.getSuggestDistrict());
addr.setSuggestName(params.getSuggestName());
addr.setPreciseLevel(params.getPreciseLevel());
addr.setAddressParserGoal(params.getAddressParserGoal());
addr.setProvince(params.getProvince());
addr.setDebugName(params.getDebugName());
return AddressProcessors.process(addr);
@@ -78,6 +78,16 @@ public class Address {
private AliyunBo aliyunBo;
public AddressParserGoal getAddressParserGoal() {
return addressParserGoal;
}
public void setAddressParserGoal(AddressParserGoal addressParserGoal) {
this.addressParserGoal = addressParserGoal;
}
/**地址解析目的*/
private AddressParserGoal addressParserGoal;
public AliyunBo getAliyunBo() {
return aliyunBo;
}
@@ -52,8 +52,8 @@ public class CityProcessor extends AbstractAddressProcessor {
}
if(StringUtils.isNotBlank(city) && CityStatus.SURE != address.getCityStatus() ){
String formatCity = RegionData.formatCity(city);
String possibleCity = parseCityFromAddress(orgAddress, address);
String confirmCity = null;
String possibleCity = AddressParserGoal.Match.equals(address.getAddressParserGoal()) ? parseCityFromAddress(orgAddress, address) : null;
String confirmCity = AddressParserGoal.Match.equals(address.getAddressParserGoal()) ? null : formatCity;
/**如果省份和城市信息相互矛盾 则用区域推断城市*/
if(StringUtils.isNotBlank(address.getProvince()) && !ProvinceData.belongTo(formatCity, address.getProvince())){
List<String> possibleCities = speculateCityNameByRegion(address, city);
@@ -62,7 +62,7 @@ public class CityProcessor extends AbstractAddressProcessor {
confirmCity = formatCity;
}
}
if(formatCity == null || !formatCity.equals(possibleCity)){
if(AddressParserGoal.Match.equals(address.getAddressParserGoal()) && (formatCity == null || (possibleCity!=null && !formatCity.equals(possibleCity)))){
confirmCity = possibleCity;
}
if(null != confirmCity){
@@ -2,6 +2,7 @@ package com.fangjia.service.address.processor;
import com.fangjia.core.RegionData;
import com.fangjia.service.address.mode.Address;
import com.fangjia.service.address.mode.AddressParserGoal;
import com.fangjia.service.address.mode.CityStatus;
import com.fangjia.service.address.mode.ProvinceData;
import org.apache.commons.lang.StringUtils;
@@ -24,9 +25,9 @@ public class ProvinceProcessor extends AbstractAddressProcessor {
String orgAddress = address.getAddress();
String[] provinceInfo = getProvince(orgAddress);
/*if(provinceInfo == null && address.getCity() != null){
if(provinceInfo == null && address.getCity() != null && !AddressParserGoal.Match.equals(address.getAddressParserGoal())){
provinceInfo = getProvince(address.getCity());
}*/
}
if (null != provinceInfo) {
String province = provinceInfo[NAME_IDX];
if (provinceInfo[FULL_NAME_IDX] != null) {//全称匹配