地址标准化去优化
This commit is contained in:
+1
@@ -1783,6 +1783,7 @@ public class AddressController {
|
||||
}
|
||||
}
|
||||
dto.append("buildingNumber", address.getBuildingNumber());
|
||||
dto.append("floor", address.getFloor());
|
||||
dto.append("unitNumber", address.getUnitNumber());
|
||||
dto.append("roomNumber", address.getRoomNumber());
|
||||
dto.append("formattedAddress", address.getFormattedAddress());
|
||||
|
||||
+3
-3
@@ -7,14 +7,14 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public interface AddressParserPatterns {
|
||||
|
||||
Pattern FULL_ADDRESS = Pattern.compile("^.{2,}(路|街|大道|巷|道|((零|一|二|三|四|五|六|七|八|九|十|东|南|西|北|复)[线环条甲])|(胡同))(交汇|.{0,3}段|.*弄)?((([甲乙]?[零一二三四五六七八九十百千\\d]+甲?号?)(?!楼)[~\\-~、,-])?([甲乙]?[零一二三四五六七八九十百千\\d])+甲?(号)(?!楼)+([付附]+[零一二三四五六七八九十百千\\d]+(号)?)?)");
|
||||
Pattern FULL_ADDRESS = Pattern.compile("^.{2,}(路|街|大道|巷|道|((零|一|二|三|四|五|六|七|八|九|十|东|南|西|北|复)[线环条甲])|(胡同))(交汇|.{0,3}段|.*弄)?((([甲乙]?[零一二三四五六七八九十百千\\d]+甲?号?)(?!楼)[~\\-~、,-])?([甲乙]?[零一二三四五六七八九十百千\\d])+甲?(号)(?!楼)+([付附]+[零一二三四五六七八九十百千\\d]+(号)?+([-]+[零一二三四五六七八九十百千\\d]+(号)?)?)?)");
|
||||
Pattern STREET = Pattern.compile("^.{2,}(路|街|大道|巷|道|((零|一|二|三|四|五|六|七|八|九|十|东|南|西|北|复)[线环条甲])|(胡同))(交汇|.{0,3}段|.*弄)?");
|
||||
Pattern STREET_NUMBER = Pattern.compile(".*([甲乙]?[零|一三四五六七八九十百千\\d]+甲?(号)(?!楼)?[~\\--~、,])?([甲乙]?[零一二三四五六七八九十百千\\d]+甲?(号)(?!楼)+([付附]+[零一二三四五六七八九十百千\\d]+(号)?)?)");
|
||||
Pattern STREET_NUMBER = Pattern.compile(".*([甲乙]?[零一二三四五六七八九十百千\\d]+甲?(号)(?!楼)?[~\\--~、,])?([甲乙]?[零一二三四五六七八九十百千\\d]+甲?(号)(?!楼)+([付附]+[零一二三四五六七八九十百千\\d]+(号)?+([-]+[零一二三四五六七八九十百千\\d]+(号)?)?)?)");
|
||||
Pattern STAGE_PATTERN = Pattern.compile("(([零一二三四五六七八九十百千\\d]+)期?[,、至到]?)?([零一二三四五六七八九十百千\\d]+)期");
|
||||
Pattern PARTITION_PATTERN = Pattern.compile("(\\w|东|南|北|中|西|甲|乙|丙|丁|零|一|二|三|四|五|六|七|八|九|十)+(区|坊)");
|
||||
Pattern TOWN = Pattern.compile("^.+?(乡|镇|街道)+");
|
||||
Pattern NUMBER = Pattern.compile("\\d+");
|
||||
Pattern STANDARD_ADDRESS = Pattern.compile("^.{2,}(路|街|大道|巷|道|((零|一|二|三|四|五|六|七|八|九|十|东|南|西|北|复)[线环条甲])|(胡同))(交汇|.{0,3}段|.*弄)?((([零一二三四五六七八九十百千\\d])+弄)|([甲乙]?([零一二三四五六七八九十百千\\d]))+号(?!楼)+([付附]+[零一二三四五六七八九十百千\\d]+(号)?)?)");
|
||||
Pattern STANDARD_ADDRESS = Pattern.compile("^.{2,}(路|街|大道|巷|道|((零|一|二|三|四|五|六|七|八|九|十|东|南|西|北|复)[线环条甲])|(胡同))(交汇|.{0,3}段|.*弄)?((([零一二三四五六七八九十百千\\d])+弄)|([甲乙]?([零一二三四五六七八九十百千\\d]))+号(?!楼)+([付附]+[零一二三四五六七八九十百千\\d]+(号)?+([-]+[零一二三四五六七八九十百千\\d]+(号)?)?)?)");
|
||||
Pattern DISTRICT = Pattern.compile("^.{2,}?(区|县)");
|
||||
|
||||
}
|
||||
|
||||
+80
-19
@@ -1,6 +1,7 @@
|
||||
package com.fangjia.service.address;
|
||||
|
||||
import com.fangjia.core.RegionData;
|
||||
import com.fangjia.core.util.CNNMFilter;
|
||||
import com.fangjia.core.util.DataUtil;
|
||||
import com.fangjia.core.util.GeoUtils;
|
||||
import com.fangjia.core.util.StringUtil;
|
||||
@@ -17,6 +18,7 @@ import com.fangjia.service.address.processor.AddressDistrictProcessors;
|
||||
import com.fangjia.service.address.processor.AddressProcessors;
|
||||
import com.fangjia.service.api.AliyunService;
|
||||
import com.fangjia.service.bo.AliyunBo;
|
||||
import com.fangjia.service.bo.MatchAddressScore;
|
||||
import com.fangjia.service.datastore.DistrictService;
|
||||
import com.fangjia.service.mongo.addrepo.AddressRepoService;
|
||||
import com.fangjia.service.mongo.bkoff.HouseLoudongService;
|
||||
@@ -170,7 +172,9 @@ public class AddressParserServiceImpl implements AddressParserService {
|
||||
if(aliyunBo != null){
|
||||
String poi = ((aliyunBo.getPoi() == null ? "":aliyunBo.getPoi()) + (aliyunBo.getSubpoi() == null ? "":aliyunBo.getSubpoi())).replaceAll("\\s*", "");
|
||||
if(StringUtils.isNotBlank(poi)){
|
||||
addr.setKeywords(poi);
|
||||
if(addr.getKeywords()==null || !addr.getKeywords().contains(poi)){
|
||||
addr.setKeywords(poi);
|
||||
}
|
||||
}
|
||||
if(StringUtils.isNotBlank(aliyunBo.getCity())){
|
||||
addr.setSuggestCity(aliyunBo.getCity());
|
||||
@@ -189,6 +193,45 @@ public class AddressParserServiceImpl implements AddressParserService {
|
||||
if(params.isUseAliyunApi() && aliyunBo != null){
|
||||
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())){
|
||||
// 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);
|
||||
// String addressStr = (StringUtils.isBlank(tempAddr.getStreet())?"":tempAddr.getStreet()) + (StringUtils.isBlank(tempAddr.getStreetNumber())?"":tempAddr.getStreetNumber());
|
||||
Map<String,List<AddressMatchMetaData>> metaDataMap = new HashMap<String, List<AddressMatchMetaData>>();
|
||||
if(StringUtils.isBlank(tempAddr.getDistrict()) && !metaDatas.isEmpty()){
|
||||
for(AddressMatchMetaData metaData:metaDatas){
|
||||
if(StringUtils.isNotBlank(metaData.getMapCity())){
|
||||
List<AddressMatchMetaData> metaList = metaDataMap.containsKey(metaData.getMapCity()) ? metaDataMap.get(metaData.getMapCity()) : new ArrayList<AddressMatchMetaData>();
|
||||
metaList.add(metaData);
|
||||
metaDataMap.put(metaData.getMapCity(),metaList);
|
||||
}
|
||||
}
|
||||
String tempCity = "";
|
||||
if(StringUtils.isNotBlank(tempAddr.getCity()) && metaDataMap.containsKey(tempAddr.getCity())){
|
||||
tempCity = tempAddr.getCity();
|
||||
}else{
|
||||
int size = 0;
|
||||
for(String key:metaDataMap.keySet()){
|
||||
if(metaDataMap.get(key).size() > size){
|
||||
size = metaDataMap.get(key).size();
|
||||
tempCity = key;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.isNotBlank(tempCity)){
|
||||
AddressMatchMetaData meta = metaDataMap.get(tempCity).get(0);
|
||||
tempAddr.setProvince(meta.getMapProvince());
|
||||
tempAddr.setCity(meta.getMapCity());
|
||||
tempAddr.setDistrict(meta.getDistrict());
|
||||
if((tempAddr.getKeywords()!=null && tempAddr.getKeywords().equals(meta.getMainName()))){
|
||||
matchedBuilding.setAddress(meta.getAddress());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
matchedBuilding.setSearchAddress(tempAddr);
|
||||
return matchedBuilding;
|
||||
}
|
||||
|
||||
@@ -224,12 +267,25 @@ public class AddressParserServiceImpl implements AddressParserService {
|
||||
if(StringUtils.isBlank(addr.getTownship())){
|
||||
addr.setTownship(aliyunBo.getTown());
|
||||
}
|
||||
addr.setOrgBuildingNumber(aliyunBo.getHouseno());
|
||||
/*addr.setOrgBuildingNumber(aliyunBo.getHouseno());
|
||||
addr.setBuildingNumber(aliyunBo.getHouseno());
|
||||
addr.setOrgUnitNumber(aliyunBo.getCellno());
|
||||
addr.setUnitNumber(aliyunBo.getCellno());
|
||||
addr.setOrgRoomNumber(aliyunBo.getRoomno());
|
||||
addr.setRoomNumber(aliyunBo.getRoomno());
|
||||
addr.setUnitNumber(aliyunBo.getCellno());*/
|
||||
if(aliyunBo.getRoomno()!=null && !aliyunBo.getRoomno().matches(".*(层|楼)$")){
|
||||
addr.setRoomNumber(aliyunBo.getRoomno());
|
||||
addr.setRoomNumber(aliyunBo.getRoomno());
|
||||
}else{
|
||||
addr.setRoomNumber(null);
|
||||
addr.setRoomNumber(null);
|
||||
}
|
||||
|
||||
/*String aliRoom = aliyunBo.getRoomno() == null ? null : aliyunBo.getRoomno().replaceAll("[\u4E00-\u9FA5]", "");
|
||||
String orgRoom = addr.getOrgRoomNumber() == null ? null : addr.getOrgRoomNumber().replaceAll("[\u4E00-\u9FA5]", "");
|
||||
if(orgRoom!=null && orgRoom.equals(aliRoom)){
|
||||
addr.setRoomNumber(aliyunBo.getRoomno());
|
||||
}else{
|
||||
addr.setRoomNumber(null);
|
||||
}*/
|
||||
|
||||
if(StringUtils.isBlank(addr.getStreet())){
|
||||
addr.setStreet(aliyunBo.getRoad());
|
||||
@@ -362,7 +418,7 @@ public class AddressParserServiceImpl implements AddressParserService {
|
||||
* @param metaDataType
|
||||
* @return
|
||||
*/
|
||||
private List<AddressMatchMetaData> findMatchMetaData(final Address address, final BuildingType buildingType, MetaDataType metaDataType){
|
||||
private List<AddressMatchMetaData> findMatchMetaData(final Address address, final BuildingType buildingType, MetaDataType metaDataType, boolean validCity){
|
||||
if(MetaDataType.MAP == metaDataType){
|
||||
List<String> keywords = address.getKeywordList();
|
||||
if(keywords.isEmpty()){
|
||||
@@ -375,7 +431,7 @@ public class AddressParserServiceImpl implements AddressParserService {
|
||||
}
|
||||
keywords.add(standardAddress);
|
||||
}
|
||||
return addressRepoService.findAllByKeyword(address.getCity(), buildingType, keywords, address.getLng(), address.getLat(), 100);
|
||||
return addressRepoService.findAllByKeyword(address.getCity(), buildingType, keywords, address.getLng(), address.getLat(), 100, validCity);
|
||||
}else{
|
||||
return SEAWEED_LOCAL_CACHE.get(new MetaDataCacheKey(address.getCity(), buildingType, MetaDataType.CPDB));
|
||||
}
|
||||
@@ -517,20 +573,20 @@ public class AddressParserServiceImpl implements AddressParserService {
|
||||
scoreResult.setOrgAddress(addr.getOrgAddress());
|
||||
if(buildingType != null) {
|
||||
if(MetaDataType.MAP == metaDataType){
|
||||
metaDatas = findMatchMetaData(addr, buildingType, MetaDataType.MAP);
|
||||
metaDatas.addAll(findMatchMetaData(addr, buildingType, MetaDataType.CPDB));
|
||||
metaDatas = findMatchMetaData(addr, buildingType, MetaDataType.MAP, true);
|
||||
metaDatas.addAll(findMatchMetaData(addr, buildingType, MetaDataType.CPDB, true));
|
||||
}else{
|
||||
metaDatas = findMatchMetaData(addr, buildingType, MetaDataType.CPDB);
|
||||
metaDatas = findMatchMetaData(addr, buildingType, MetaDataType.CPDB, true);
|
||||
}
|
||||
} else {
|
||||
if(MetaDataType.MAP == metaDataType){
|
||||
metaDatas = findMatchMetaData(addr, null, MetaDataType.MAP);
|
||||
metaDatas = findMatchMetaData(addr, null, MetaDataType.MAP, true);
|
||||
}
|
||||
for (BuildingType bt : addr.guessBuildType()) {
|
||||
if(metaDatas == null){
|
||||
metaDatas = findMatchMetaData(addr, bt, MetaDataType.CPDB);
|
||||
metaDatas = findMatchMetaData(addr, bt, MetaDataType.CPDB, true);
|
||||
}else{
|
||||
metaDatas.addAll(findMatchMetaData(addr, bt, MetaDataType.CPDB));
|
||||
metaDatas.addAll(findMatchMetaData(addr, bt, MetaDataType.CPDB, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -967,7 +1023,12 @@ public class AddressParserServiceImpl implements AddressParserService {
|
||||
formattedAddressBuilder.append(address.getStreetNumber());
|
||||
}
|
||||
if(StringUtils.isBlank(address.getStreet()) && StringUtils.isNotBlank(building.getAddress())){
|
||||
formattedAddressBuilder.append(building.getAddress());
|
||||
Address orgAddr = new Address();
|
||||
orgAddr.setOrgAddress(building.getAddress());
|
||||
Address addr = AddressProcessors.process(orgAddr);
|
||||
building.getSearchAddress().setStreet(addr.getStreet());
|
||||
building.getSearchAddress().setStreetNumber(addr.getStreetNumber());
|
||||
formattedAddressBuilder.append((addr.getStreet()==null?"":addr.getStreet())+(addr.getStreetNumber()==null?"":addr.getStreetNumber()));
|
||||
}
|
||||
if(StringUtils.isNotBlank(building.getSuggestName())){
|
||||
formattedAddressBuilder.append(building.getSuggestName());
|
||||
@@ -985,16 +1046,16 @@ public class AddressParserServiceImpl implements AddressParserService {
|
||||
&& address.getStreetNumber().endsWith(address.getOrgBuildingNumber())){
|
||||
|
||||
}else{
|
||||
formattedAddressBuilder.append(address.getBuildingNumber());
|
||||
// formattedAddressBuilder.append(address.getBuildingNumber() + "栋");
|
||||
// formattedAddressBuilder.append(address.getBuildingNumber());
|
||||
formattedAddressBuilder.append(address.getBuildingNumber() + "栋");
|
||||
}
|
||||
|
||||
}
|
||||
if(StringUtils.isNotBlank(address.getOrgUnitNumber())){
|
||||
formattedAddressBuilder.append(address.getUnitNumber());
|
||||
// formattedAddressBuilder.append(address.getUnitNumber() + "单元");
|
||||
// formattedAddressBuilder.append(address.getUnitNumber());
|
||||
formattedAddressBuilder.append(address.getUnitNumber() + "单元");
|
||||
}
|
||||
if(StringUtils.isNotBlank(address.getOrgRoomNumber())){
|
||||
if(StringUtils.isNotBlank(address.getRoomNumber())){
|
||||
formattedAddressBuilder.append(address.getRoomNumber());
|
||||
// formattedAddressBuilder.append(address.getRoomNumber() + "室");
|
||||
}
|
||||
|
||||
+32
-1
@@ -259,7 +259,38 @@ public class AddressFormatterFactory {
|
||||
@Override
|
||||
protected String doFormat(String address) {
|
||||
String matchStr = DataUtil.match(address, TARGET);
|
||||
String formatStr = matchStr + "ºÅ";
|
||||
String formatStr = matchStr.replaceAll("段-","段");
|
||||
if(!matchStr.endsWith("号")){
|
||||
formatStr += "号";
|
||||
}
|
||||
return address.replace(matchStr,formatStr);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 剑南路东段-12号-18号
|
||||
*/
|
||||
formatters.add(new AbstractAddressFormatter(Pattern.compile(".*(路|街|大道|巷|道|((零|一|二|三|四|五|六|七|八|九|十|东|南|西|北|复)[线环条甲])|(胡同))(交汇|.{0,3}段|.*弄)?((([零一二三四五六七八九十百千\\d])+弄)|([甲乙-]?\\d+[号](附\\d+(号)?(-\\d+(号)?)?)?([-][附付、]?\\d+(号(附近)?)?)?))")) {
|
||||
final Pattern TARGET = Pattern.compile("(路|街|大道|巷|道|((零|一|二|三|四|五|六|七|八|九|十|东|南|西|北|复)[线环条甲])|(胡同))(交汇|.{0,3}段|.*弄)?((([零一二三四五六七八九十百千\\d])+弄)|([甲乙-]?\\d+[号](附\\d+(号)?(-\\d+(号)?)?)?([-][附付、]?\\d+(号(附近)?)?)?))");
|
||||
@Override
|
||||
protected String doFormat(String address) {
|
||||
String matchStr = DataUtil.match(address, TARGET);
|
||||
String formatStr = matchStr;
|
||||
if(!matchStr.endsWith("号")){
|
||||
formatStr += "号";
|
||||
}
|
||||
return address.replace(matchStr,formatStr);
|
||||
}
|
||||
});
|
||||
/**
|
||||
* 剑南路东段-12号-18号
|
||||
*/
|
||||
formatters.add(new AbstractAddressFormatter(Pattern.compile("(((路|街|大道|巷|道|段|附|付)-)|(-(附|付)))")) {
|
||||
final Pattern TARGET = Pattern.compile("(((路|街|大道|巷|道|段|附|付)-)|(-(附|付)))");
|
||||
@Override
|
||||
protected String doFormat(String address) {
|
||||
String matchStr = DataUtil.match(address, TARGET);
|
||||
String formatStr = matchStr.replace("-","");
|
||||
return address.replace(matchStr,formatStr);
|
||||
}
|
||||
});
|
||||
|
||||
+18
@@ -44,6 +44,24 @@ public class AddressMatchMetaData {
|
||||
private Double lat;
|
||||
private String map;
|
||||
|
||||
public String getMapProvince() {
|
||||
return mapProvince;
|
||||
}
|
||||
|
||||
public void setMapProvince(String mapProvince) {
|
||||
this.mapProvince = mapProvince;
|
||||
}
|
||||
|
||||
public String getMapCity() {
|
||||
return mapCity;
|
||||
}
|
||||
|
||||
public void setMapCity(String mapCity) {
|
||||
this.mapCity = mapCity;
|
||||
}
|
||||
|
||||
private String mapProvince;
|
||||
private String mapCity;
|
||||
public void addName(String name, float priority){
|
||||
if(StringUtils.isNotBlank(name)){
|
||||
String formatName = AddressParserUtil.standardAddressAndName(name);
|
||||
|
||||
+15
-6
@@ -50,18 +50,23 @@ public class CityProcessor extends AbstractAddressProcessor {
|
||||
return RepeatStatus.NEXT;
|
||||
}
|
||||
}
|
||||
if(StringUtils.isNotBlank(city)){
|
||||
if(StringUtils.isNotBlank(city) && CityStatus.SURE != address.getCityStatus() ){
|
||||
String formatCity = RegionData.formatCity(city);
|
||||
String possibleCity = null;
|
||||
String possibleCity = parseCityFromAddress(orgAddress, address);
|
||||
String confirmCity = null;
|
||||
/**如果省份和城市信息相互矛盾 则用区域推断城市*/
|
||||
if(StringUtils.isNotBlank(address.getProvince()) && !ProvinceData.belongTo(formatCity, address.getProvince())){
|
||||
List<String> possibleCities = speculateCityNameByRegion(address, city);
|
||||
if(isUnique(possibleCities)){
|
||||
formatCity = getFirst(possibleCities);
|
||||
confirmCity = formatCity;
|
||||
}
|
||||
}
|
||||
if(null != formatCity){
|
||||
city = formatCity;
|
||||
if(formatCity == null || !formatCity.equals(possibleCity)){
|
||||
confirmCity = possibleCity;
|
||||
}
|
||||
if(null != confirmCity){
|
||||
city = confirmCity;
|
||||
address.setCity(city);
|
||||
address.setCityStatus(CityStatus.SURE);
|
||||
}
|
||||
@@ -98,7 +103,7 @@ public class CityProcessor extends AbstractAddressProcessor {
|
||||
address.setCity(city);
|
||||
}
|
||||
if(StringUtils.isNotBlank(city) && scoreRegion(city, orgAddress) > 0.4){
|
||||
orgAddress = orgAddress.replaceFirst(".*" + address.getCity() + "[市县区州巿]?" , "");
|
||||
orgAddress = orgAddress.replaceFirst(".*" + address.getCity() + "[市县区州巿]?(?!(路|街|大道|巷|道|段))" , "");
|
||||
address.setAddress(orgAddress);
|
||||
address.setCityStatus(CityStatus.SURE);
|
||||
return RepeatStatus.NEXT;
|
||||
@@ -166,7 +171,7 @@ public class CityProcessor extends AbstractAddressProcessor {
|
||||
String street = getStreet(address);
|
||||
for(String city : allCity){
|
||||
if(street != null){
|
||||
MatchResult matchResult = matchFirst(Pattern.compile(city + "[东南西北中一二三四五六七八九十百千\\d]?(路|街|大道|支路|村)"), street);
|
||||
MatchResult matchResult = matchFirst(Pattern.compile(city + "[东南西北中一二三四五六七八九十百千\\d]?(路|街|大道|大街|支路|村)"), street);
|
||||
if(matchResult !=null){
|
||||
address = address.replace(matchResult.matchContent, "");
|
||||
}
|
||||
@@ -199,6 +204,10 @@ public class CityProcessor extends AbstractAddressProcessor {
|
||||
}
|
||||
Map<String, List<String>> regionMap = RegionData.getAllRegions(city);
|
||||
for(String region : regionMap.keySet()){
|
||||
MatchResult matchResult = matchFirst(Pattern.compile(region + "[东南西北中一二三四五六七八九十百千\\d]?(路|街|大道|大街|支路|村)"), street);
|
||||
if(matchResult !=null){
|
||||
address = address.replace(matchResult.matchContent, "");
|
||||
}
|
||||
if(address.indexOf(region, index) > -1){
|
||||
if(province != null && (orgAddress.contains(province + region) || orgAddress.contains(ProvinceData.getDisplay(province) + region))){
|
||||
weight.score += 2;
|
||||
|
||||
+2
-2
@@ -24,9 +24,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){
|
||||
provinceInfo = getProvince(address.getCity());
|
||||
}
|
||||
}*/
|
||||
if (null != provinceInfo) {
|
||||
String province = provinceInfo[NAME_IDX];
|
||||
if (provinceInfo[FULL_NAME_IDX] != null) {//全称匹配
|
||||
|
||||
+12
-4
@@ -18,6 +18,7 @@ public class RoomNumberProcessor extends AbstractAddressProcessor {
|
||||
static final Pattern NUMBER_END = Pattern.compile("(?<=\\D)\\d{3,4}$");
|
||||
static final Pattern HOUSE_NUMBER = Pattern.compile("\\d{3,4}");
|
||||
static final String HOUSE_UNITS_PATTERN = "(ÊÒ|·¿|ºÅ·¿|ºÅ(?!Ôº)|»§|ÆÌ)+";
|
||||
static final Pattern HOUSE_PATTERN_CASE02 = Pattern.compile("(\\d+(ÊÒ|·¿|ºÅ)?[¡¢]?)+$");
|
||||
|
||||
@Override
|
||||
public RepeatStatus process(Address address) {
|
||||
@@ -27,10 +28,17 @@ public class RoomNumberProcessor extends AbstractAddressProcessor {
|
||||
orgAddress = removeSubstring(orgAddress, matchResult.start, matchResult.end);
|
||||
address.setOrgRoomNumber(matchResult.matchContent);
|
||||
address.setAddress(orgAddress);
|
||||
analyFloorUseRoomNumber(address);
|
||||
// analyFloorUseRoomNumber(address);
|
||||
return RepeatStatus.NEXT;
|
||||
}
|
||||
MatchResult matchResult2 = matchFirst(HOUSE_PATTERN_CASE02, orgAddress);
|
||||
if (matchResult2 != null) {
|
||||
orgAddress = removeSubstring(orgAddress, matchResult2.start, matchResult2.end);
|
||||
address.setOrgRoomNumber(matchResult2.matchContent);
|
||||
address.setAddress(orgAddress);
|
||||
// analyFloorUseRoomNumber(address);
|
||||
return RepeatStatus.NEXT;
|
||||
}
|
||||
|
||||
matchResult = matchFirst(HOUSE_PATTERN, orgAddress);
|
||||
if (matchResult != null) {
|
||||
orgAddress = removeSubstring(orgAddress, matchResult.start, matchResult.end);
|
||||
@@ -39,10 +47,10 @@ public class RoomNumberProcessor extends AbstractAddressProcessor {
|
||||
} else {
|
||||
address.setOrgRoomNumber(matchResult.matchContent + "ÊÒ");
|
||||
}
|
||||
analyFloorUseRoomNumber(address);
|
||||
// analyFloorUseRoomNumber(address);
|
||||
address.setAddress(orgAddress);
|
||||
}
|
||||
analyFloorUseRoomNumber(address);
|
||||
// analyFloorUseRoomNumber(address);
|
||||
removeHouseUnit(address);
|
||||
return RepeatStatus.NEXT;
|
||||
}
|
||||
|
||||
+1
@@ -41,6 +41,7 @@ public class TooltipProcessor extends AbstractAddressProcessor {
|
||||
offset += matchResult.matchContent.length();
|
||||
if(matchFirst(AddressParserPatterns.STREET, tooltip) != null){
|
||||
address.setTooltip(tooltip);
|
||||
address.setStreet(getStreet(tooltip));
|
||||
} else if(containsDistrictName(tooltip)){
|
||||
address.setTooltip(tooltip);
|
||||
} else if(RegionData.isRegion(address.getCity(), tooltip)){
|
||||
|
||||
+10
@@ -1,6 +1,7 @@
|
||||
package com.fangjia.service.address.processor;
|
||||
|
||||
import com.fangjia.service.address.mode.Address;
|
||||
import com.fangjia.service.cnAnalyzer.Token;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -14,6 +15,15 @@ public class VillageNameProcessor extends AbstractAddressProcessor {
|
||||
@Override
|
||||
public AbstractAddressProcessor.RepeatStatus process(Address address) {
|
||||
String orgAddress = address.getAddress();
|
||||
if(address.getTokens()!=null){
|
||||
for(Token token:address.getTokens()){
|
||||
if("district".equals(token.getKeywordTypes())){
|
||||
address.setKeywords(token.getName());
|
||||
address.setAddress(orgAddress.replace(token.getName(),""));
|
||||
return RepeatStatus.NEXT;
|
||||
}
|
||||
}
|
||||
}
|
||||
List<String> names = tokenDistrictNames(orgAddress);
|
||||
List<String> kws = new ArrayList<String>();
|
||||
for(String name : names){
|
||||
|
||||
@@ -68,7 +68,7 @@ public interface AmapPoiService {
|
||||
* @param types
|
||||
* @return
|
||||
*/
|
||||
List<AmapPoi> search(String city, String keywords, Integer limit, String types);
|
||||
List<AmapPoi> search(String city, String keywords, Integer limit, String types, boolean validCity);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
+12
-9
@@ -1,5 +1,6 @@
|
||||
package com.fangjia.service.api;
|
||||
|
||||
import com.fangjia.core.ProvinceData;
|
||||
import com.fangjia.core.RegionData;
|
||||
import com.fangjia.core.util.DataUtil;
|
||||
import com.fangjia.core.util.GeoUtils;
|
||||
@@ -258,14 +259,14 @@ public class AmapPoiServiceImpl implements AmapPoiService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AmapPoi> search(String city, String keywords, Integer limit, String types) {
|
||||
public List<AmapPoi> search(String city, String keywords, Integer limit, String types, boolean validCity) {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
String area = city;
|
||||
params.put("city", area);
|
||||
params.put("output", "json");
|
||||
params.put("keywords", keywords);
|
||||
params.put("key", "4ccfe3c898a9489884bd2bcb1ef6dcde");
|
||||
params.put("citylimit", "true");
|
||||
// params.put("citylimit", "true");
|
||||
params.put("offset", limit == null?"25":String.valueOf(limit));
|
||||
if(types != null){
|
||||
params.put("types", "120301&120302&120201&060101");
|
||||
@@ -351,15 +352,17 @@ public class AmapPoiServiceImpl implements AmapPoiService {
|
||||
cityname = poi.getString("cityname");
|
||||
}
|
||||
cityname = RegionData.formatCity(cityname);
|
||||
if(!city.equals(cityname)){
|
||||
if((city!=null && !city.equals(cityname) && validCity) || cityname == null){
|
||||
continue;
|
||||
}
|
||||
pname = ProvinceData.formatProvince(pname);
|
||||
AmapPoi amapPoi = new AmapPoi();
|
||||
amapPoi.setCity(city);
|
||||
amapPoi.setCity(cityname);
|
||||
amapPoi.setPname(pname);
|
||||
if(poi.containsKey("adname") && poi.get("adname") instanceof String){
|
||||
adname = poi.getString("adname");
|
||||
String region = RegionData.formatRegion(city, adname);
|
||||
if(RegionData.isRegion(city, region)){
|
||||
String region = RegionData.formatRegion(cityname, adname);
|
||||
if(RegionData.isRegion(cityname, region)){
|
||||
amapPoi.setRegion(region);
|
||||
}
|
||||
}
|
||||
@@ -380,8 +383,8 @@ public class AmapPoiServiceImpl implements AmapPoiService {
|
||||
amapPoi.setAlias(alias);
|
||||
}
|
||||
if(poi.containsKey("adname") && poi.get("adname") instanceof String){
|
||||
String region = RegionData.formatRegion(city, poi.getString("adname"));
|
||||
if(RegionData.isRegion(city, region)){
|
||||
String region = RegionData.formatRegion(cityname, poi.getString("adname"));
|
||||
if(RegionData.isRegion(cityname, region)){
|
||||
amapPoi.setRegion(region);
|
||||
}
|
||||
}
|
||||
@@ -391,7 +394,7 @@ public class AmapPoiServiceImpl implements AmapPoiService {
|
||||
.replace(cityname, "").replace(adname, "");
|
||||
amapPoi.setAddress(AddressParserUtil.optimizeAddress(address));
|
||||
}
|
||||
amapPoi.setCity(city);
|
||||
amapPoi.setCity(cityname);
|
||||
if(poi.containsKey("location") && poi.get("location") instanceof String){
|
||||
String[] location = poi.getString("location").split(",");
|
||||
amapPoi.setLng(Double.valueOf(location[0]));
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ public interface AddressRepoService {
|
||||
* @param max
|
||||
* @return
|
||||
*/
|
||||
List<AddressMatchMetaData> findAllByKeyword(String city,BuildingType buildingType , List<String> keywords, Double lng, Double lat, int max);
|
||||
List<AddressMatchMetaData> findAllByKeyword(String city,BuildingType buildingType , List<String> keywords, Double lng, Double lat, int max, boolean validCity);
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
+8
-2
@@ -87,7 +87,7 @@ public class AddressRepoServiceImpl implements AddressRepoService {
|
||||
return addrs;
|
||||
}
|
||||
|
||||
public List<AddressMatchMetaData> findAllByKeyword(String city,BuildingType buildingType , List<String> keywords, Double lng, Double lat, int max){
|
||||
public List<AddressMatchMetaData> findAllByKeyword(String city,BuildingType buildingType , List<String> keywords, Double lng, Double lat, int max, boolean validCity){
|
||||
String types = null;
|
||||
String tag = null;
|
||||
String category = null;
|
||||
@@ -104,7 +104,11 @@ public class AddressRepoServiceImpl implements AddressRepoService {
|
||||
tag = "°Ù»õÉ̳¡";
|
||||
category = "×ÛºÏÉ̳¡";
|
||||
}
|
||||
List<AmapPoi> pois = amapPoiService.search(city, StringUtils.join(keywords, "|"), 20, types);
|
||||
List<AmapPoi> pois = new ArrayList<AmapPoi>();
|
||||
for(String keyword:keywords){
|
||||
List<AmapPoi> poiList = amapPoiService.search(city, keyword, 20, types, validCity);
|
||||
pois.addAll(poiList);
|
||||
}
|
||||
List<AddressMatchMetaData> matchMetaDatas = new ArrayList<AddressMatchMetaData>(pois.size());
|
||||
for(AmapPoi poi: pois){
|
||||
AddressMatchMetaData data = new AddressMatchMetaData();
|
||||
@@ -121,6 +125,8 @@ public class AddressRepoServiceImpl implements AddressRepoService {
|
||||
data.setType(poi.getType());
|
||||
data.setMap("¸ßµÂ");
|
||||
data.setCity(city);
|
||||
data.setMapCity(poi.getCity());
|
||||
data.setMapProvince(poi.getPname());
|
||||
if(poi.getAlias() != null){
|
||||
for(String alia : poi.getAlias()){
|
||||
data.addName(alia, MatchText.ALIAS_PRIORITY);
|
||||
|
||||
Reference in New Issue
Block a user