Merge branch 'feature_master_xh_standard' into 'master'
地址标准化优化 See merge request !2
This commit is contained in:
+14
-1
@@ -1740,6 +1740,10 @@ public class AddressController {
|
||||
matchParams.setAddressParserGoal(AddressParserGoal.Match);
|
||||
matchParams.setPreciseLevel(PreciseLevel.STRICT);
|
||||
matchParams.setProvince(model.getProvince());
|
||||
|
||||
// matchParams.setUseMap(true);
|
||||
matchParams.setUseAliyunApi(true);
|
||||
matchParams.setExportLatAndLng(true);
|
||||
Building building = addressParserService.standard(matchParams);
|
||||
Address address = building.getSearchAddress();
|
||||
UniversalDto dto = UniversalDto.newDto();
|
||||
@@ -1768,7 +1772,12 @@ public class AddressController {
|
||||
if(street != null){
|
||||
dto.append("street", street);
|
||||
if(addr.length() != street.length()){
|
||||
dto.append("streetNumber", addr.replaceFirst(street, ""));
|
||||
dto.append("streetNumber", AddressParserUtil.match(AddressParserUtil.STREET_NUMBER_CONNECTOR_PATTERN, addr));
|
||||
}
|
||||
}else if(StringUtils.isNotBlank(building.getStreet())){
|
||||
dto.append("street", building.getStreet());
|
||||
if(StringUtils.isNotBlank(building.getStreetno())){
|
||||
dto.append("streetNumber", building.getStreetno());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1776,6 +1785,10 @@ public class AddressController {
|
||||
dto.append("unitNumber", address.getUnitNumber());
|
||||
dto.append("roomNumber", address.getRoomNumber());
|
||||
dto.append("formattedAddress", address.getFormattedAddress());
|
||||
if(matchParams.isExportLatAndLng()){
|
||||
dto.append("lat", building.getLat());
|
||||
dto.append("lng", building.getLng());
|
||||
}
|
||||
mav.setModel(BasicModel.buildOKModel().setResult(dto));
|
||||
return mav;
|
||||
}
|
||||
|
||||
@@ -214,5 +214,15 @@
|
||||
<artifactId>jieba-analysis</artifactId>
|
||||
<version>1.0.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>aliyun-java-sdk-address-purification</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>aliyun-java-sdk-core</artifactId>
|
||||
<version>4.5.19</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
+64
-5
@@ -14,6 +14,8 @@ import com.fangjia.dal.seaweed.model.Seaweed;
|
||||
import com.fangjia.service.address.mode.*;
|
||||
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.datastore.DistrictService;
|
||||
import com.fangjia.service.mongo.addrepo.AddressRepoService;
|
||||
import com.fangjia.service.mongo.bkoff.HouseLoudongService;
|
||||
@@ -41,6 +43,7 @@ public class AddressParserServiceImpl implements AddressParserService {
|
||||
private HouseLoudongService houseLoudongService;
|
||||
private LoudongService loudongService;
|
||||
private SeaweedDao seaweedDao;
|
||||
private AliyunService aliyunService;
|
||||
private final String[] MATCH_PROPERTY_FIELDS = new String[]{"id", "city", "region", "name", "address", "category", "block", "alias", "addrAlias", "estateType2", "lat2", "lng2", "streetCommunity"};
|
||||
private static final Logger logger = Logger.getLogger(AddressParserServiceImpl.class);
|
||||
|
||||
@@ -159,6 +162,15 @@ public class AddressParserServiceImpl implements AddressParserService {
|
||||
return building;
|
||||
}
|
||||
Building matchedBuilding;
|
||||
//keywords使用aliyun接口返回的poi
|
||||
AliyunBo aliyunBo = null;
|
||||
if(params.isUseAliyunApi()){
|
||||
aliyunBo = aliyunService.addressStand(params.getAddress(), params.getCity());
|
||||
if(aliyunBo != null){
|
||||
String poi = (aliyunBo.getPoi() == null ? "":aliyunBo.getPoi()) + (aliyunBo.getSubpoi() == null ? "":aliyunBo.getSubpoi());
|
||||
addr.setKeywords(poi);
|
||||
}
|
||||
}
|
||||
if(params.isUseMap()){
|
||||
matchedBuilding = findMatchedBuilding(addr, params.getBuildingType(), MetaDataType.MAP);
|
||||
}else{
|
||||
@@ -168,9 +180,56 @@ public class AddressParserServiceImpl implements AddressParserService {
|
||||
matchedBuilding.setSearchAddress(addr);
|
||||
matchedBuilding.setSuggestName(getSuggestName(matchedBuilding));
|
||||
matchedBuilding.setSuggestAddress(getSuggestAddress(matchedBuilding));
|
||||
if(params.isUseAliyunApi() && aliyunBo != null){
|
||||
completBuildingField(matchedBuilding, aliyunBo, params);
|
||||
}
|
||||
return matchedBuilding;
|
||||
}
|
||||
|
||||
/**
|
||||
* 信息不全时使用阿里接口补全数据
|
||||
* @param matchedBuilding
|
||||
* @param aliyunBo
|
||||
* @return
|
||||
*/
|
||||
void completBuildingField(Building matchedBuilding, AliyunBo aliyunBo, MatchParams params){
|
||||
String poi = (aliyunBo.getPoi() == null ? "":aliyunBo.getPoi()) + (aliyunBo.getSubpoi() == null ? "":aliyunBo.getSubpoi());
|
||||
if(matchedBuilding.getSuggestName()!=null && StringUtils.isNotBlank(poi) && params.getAddress().contains(poi)){
|
||||
if(!params.getAddress().contains(matchedBuilding.getSuggestName()) || poi.contains(matchedBuilding.getSuggestName())){
|
||||
matchedBuilding.setSuggestName(poi);
|
||||
}
|
||||
}
|
||||
if(StringUtils.isBlank(matchedBuilding.getProvince())){
|
||||
matchedBuilding.setProvince(aliyunBo.getProv());
|
||||
}
|
||||
if(StringUtils.isBlank(matchedBuilding.getCity())){
|
||||
matchedBuilding.setCity(aliyunBo.getCity());
|
||||
}
|
||||
matchedBuilding.setStreet(aliyunBo.getRoad());
|
||||
matchedBuilding.setStreetno(aliyunBo.getRoadno());
|
||||
|
||||
Address addr = matchedBuilding.getSearchAddress();
|
||||
if(StringUtils.isBlank(addr.getDevelopmentZone())){
|
||||
addr.setDevelopmentZone(aliyunBo.getDevzone());
|
||||
}
|
||||
if(StringUtils.isBlank(addr.getDistrict())){
|
||||
addr.setDistrict(aliyunBo.getDistrict());
|
||||
}
|
||||
if(StringUtils.isBlank(addr.getTownship())){
|
||||
addr.setTownship(aliyunBo.getTown());
|
||||
}
|
||||
if(StringUtils.isBlank(addr.getBuildingNumber())){
|
||||
addr.setBuildingNumber(aliyunBo.getHouseno());
|
||||
}
|
||||
if(StringUtils.isBlank(addr.getUnitNumber())){
|
||||
addr.setUnitNumber(aliyunBo.getCellno());
|
||||
}
|
||||
if(StringUtils.isBlank(addr.getRoomNumber())){
|
||||
addr.setRoomNumber(aliyunBo.getRoomno());
|
||||
}
|
||||
matchedBuilding.setSearchAddress(addr);
|
||||
}
|
||||
|
||||
Building findMatchedBuilding(Address addr,BuildingType buildingType, MetaDataType metaDataType){
|
||||
|
||||
AddressScoreResult scoreResult = findMatchedMetaData(addr, buildingType, metaDataType);
|
||||
@@ -830,11 +889,7 @@ public class AddressParserServiceImpl implements AddressParserService {
|
||||
}
|
||||
}
|
||||
String cityDisplay = CityData.getCityDisplay(address.getCity());
|
||||
if(cityDisplay != null){
|
||||
formattedAddressBuilder.append(cityDisplay);
|
||||
}else{
|
||||
formattedAddressBuilder.append(address.getCity() + "市");
|
||||
}
|
||||
formattedAddressBuilder.append(cityDisplay != null ? cityDisplay : (StringUtils.isNotBlank(address.getCity())?(address.getCity()+ "市"):""));
|
||||
if(StringUtils.isNotBlank(address.getDistrict())){
|
||||
String orgDistrict = RegionData.getOrgName(address.getCity(), address.getDistrict());
|
||||
if(StringUtils.isNotBlank(orgDistrict) && formattedAddressBuilder.indexOf(orgDistrict) == -1){
|
||||
@@ -997,4 +1052,8 @@ public class AddressParserServiceImpl implements AddressParserService {
|
||||
public void setSeaweedDao(SeaweedDao seaweedDao) {
|
||||
this.seaweedDao = seaweedDao;
|
||||
}
|
||||
|
||||
public void setAliyunService(AliyunService aliyunService) {
|
||||
this.aliyunService = aliyunService;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.fangjia.service.address.mode;
|
||||
|
||||
import com.fangjia.service.address.AddressParserUtil;
|
||||
import com.fangjia.service.bo.AliyunBo;
|
||||
import com.fangjia.service.cnAnalyzer.Token;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@@ -74,6 +75,15 @@ public class Address {
|
||||
/**调试时断点小区名*/
|
||||
private String debugName;
|
||||
|
||||
private AliyunBo aliyunBo;
|
||||
|
||||
public AliyunBo getAliyunBo() {
|
||||
return aliyunBo;
|
||||
}
|
||||
|
||||
public void setAliyunBo(AliyunBo aliyunBo) {
|
||||
this.aliyunBo = aliyunBo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,6 +32,25 @@ public class Building {
|
||||
private String suggestAddress;
|
||||
private String map;
|
||||
|
||||
public String getStreet() {
|
||||
return street;
|
||||
}
|
||||
|
||||
public void setStreet(String street) {
|
||||
this.street = street;
|
||||
}
|
||||
|
||||
public String getStreetno() {
|
||||
return streetno;
|
||||
}
|
||||
|
||||
public void setStreetno(String streetno) {
|
||||
this.streetno = streetno;
|
||||
}
|
||||
|
||||
private String street;
|
||||
private String streetno;
|
||||
|
||||
public Building(District d){
|
||||
this.city = d.getCity();
|
||||
this.district = d.getRegion();
|
||||
|
||||
+22
@@ -23,8 +23,14 @@ public class MatchParams {
|
||||
private PreciseLevel preciseLevel;
|
||||
/**是否使用地图库*/
|
||||
private boolean useMap;
|
||||
/**是否使用阿里云接口*/
|
||||
private boolean useAliyunApi;
|
||||
/**是否输出经纬度*/
|
||||
private boolean exportLatAndLng;
|
||||
/**地址解析目的*/
|
||||
private AddressParserGoal addressParserGoal;
|
||||
|
||||
|
||||
public String getProvince() {
|
||||
return province;
|
||||
}
|
||||
@@ -81,6 +87,22 @@ public class MatchParams {
|
||||
this.useMap = useMap;
|
||||
}
|
||||
|
||||
public boolean isUseAliyunApi() {
|
||||
return useAliyunApi;
|
||||
}
|
||||
|
||||
public void setUseAliyunApi(boolean useAliyunApi) {
|
||||
this.useAliyunApi = useAliyunApi;
|
||||
}
|
||||
|
||||
public boolean isExportLatAndLng() {
|
||||
return exportLatAndLng;
|
||||
}
|
||||
|
||||
public void setExportLatAndLng(boolean exportLatAndLng) {
|
||||
this.exportLatAndLng = exportLatAndLng;
|
||||
}
|
||||
|
||||
public AddressParserGoal getAddressParserGoal() {
|
||||
return addressParserGoal;
|
||||
}
|
||||
|
||||
+9
-2
@@ -163,7 +163,14 @@ public class CityProcessor extends AbstractAddressProcessor {
|
||||
}else{
|
||||
allCity = RegionData.getAllCity();
|
||||
}
|
||||
String street = getStreet(address);
|
||||
for(String city : allCity){
|
||||
if(street != null){
|
||||
MatchResult matchResult = matchFirst(Pattern.compile(city + "[东南西北中一二三四五六七八九十百千\\d]?(路|街|大道|支路|村)"), street);
|
||||
if(matchResult !=null){
|
||||
address = address.replace(matchResult.matchContent, "");
|
||||
}
|
||||
}
|
||||
int index = 0;
|
||||
FragmentWeight weight = weightMap.get(city);
|
||||
if(weight == null){
|
||||
@@ -221,7 +228,7 @@ public class CityProcessor extends AbstractAddressProcessor {
|
||||
}
|
||||
List<FragmentWeight> weights = new ArrayList<FragmentWeight>(weightMap.values());
|
||||
if(weights.size() > 0){
|
||||
String street = getStreet(address);
|
||||
/*String street = getStreet(address);
|
||||
if(street != null){
|
||||
Iterator<FragmentWeight> iterator = weights.iterator();
|
||||
while(iterator.hasNext()){
|
||||
@@ -230,7 +237,7 @@ public class CityProcessor extends AbstractAddressProcessor {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
Collections.sort(weights);
|
||||
}
|
||||
if(weights.size() > 0){
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.fangjia.service.api;
|
||||
|
||||
import com.fangjia.service.bo.AliyunBo;
|
||||
|
||||
public interface AliyunService {
|
||||
AliyunBo addressStand(String address, String city);
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
package com.fangjia.service.api;
|
||||
|
||||
import com.aliyuncs.address_purification.model.v20191118.StructureAddressRequest;
|
||||
import com.aliyuncs.address_purification.model.v20191118.StructureAddressResponse;
|
||||
import com.fangjia.core.util.JsonUtils;
|
||||
import com.fangjia.core.util.LoggerFactory;
|
||||
import com.fangjia.service.bo.AliyunBo;
|
||||
import com.aliyuncs.DefaultAcsClient;
|
||||
import com.aliyuncs.IAcsClient;
|
||||
import com.aliyuncs.exceptions.ClientException;
|
||||
import com.aliyuncs.profile.DefaultProfile;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class AliyunServiceImpl implements AliyunService {
|
||||
|
||||
protected final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
|
||||
public static String REGIONID = "cn-hangzhou";
|
||||
public static String ACCESSKEYID = "LTAIdaj4eSO79gzz";
|
||||
public static String SECRET = "xw6EsvqydZ9HC6zAvIB3ruQqVHynxf";
|
||||
public static String APPKEY = "68czunztrb1o";
|
||||
|
||||
@Override
|
||||
public AliyunBo addressStand(String address, String city) {
|
||||
DefaultProfile profile = DefaultProfile.getProfile(
|
||||
REGIONID,
|
||||
ACCESSKEYID,
|
||||
SECRET);
|
||||
IAcsClient client = new DefaultAcsClient(profile);
|
||||
StructureAddressRequest request = new StructureAddressRequest();
|
||||
request.setServiceCode("addrp");
|
||||
request.setAppKey(APPKEY);
|
||||
request.setText(address);
|
||||
if(StringUtils.isNotBlank(city)){
|
||||
request.setDefaultCity(city);
|
||||
}
|
||||
try{
|
||||
StructureAddressResponse response = client.getAcsResponse(request);
|
||||
JSONObject responseJson = JSONObject.fromObject(response.getData());
|
||||
String value = (String) responseJson.get("structure");
|
||||
AliyunBo aliyunBo = new AliyunBo();
|
||||
for (String key:value.split("\t")){
|
||||
String[] arry = key.split("=");
|
||||
wrapField(arry[0],arry[1], aliyunBo);
|
||||
}
|
||||
return aliyunBo;
|
||||
}catch(Exception e){
|
||||
LOGGER.error("", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void wrapField(String field,String value, AliyunBo aliyunBo){
|
||||
if("city".equals(field)){
|
||||
aliyunBo.setCity(value);
|
||||
}else if("prov".equals(field)){
|
||||
aliyunBo.setProv(value);
|
||||
}else if("district".equals(field)){
|
||||
aliyunBo.setDistrict(value);
|
||||
}else if("poi".equals(field)){
|
||||
aliyunBo.setPoi(value);
|
||||
}else if("subpoi".equals(field)){
|
||||
aliyunBo.setSubpoi(value);
|
||||
}else if("houseno".equals(field)){
|
||||
aliyunBo.setHouseno(value);
|
||||
}else if("cellno".equals(field)){
|
||||
aliyunBo.setCellno(value);
|
||||
}else if("roomno".equals(field)){
|
||||
aliyunBo.setRoomno(value);
|
||||
}else if("road".equals(field)){
|
||||
aliyunBo.setRoad(value);
|
||||
}else if("roadno".equals(field)){
|
||||
aliyunBo.setRoadno(value);
|
||||
}else if("floorno".equals(field)){
|
||||
aliyunBo.setFloorno(value);
|
||||
}else if("town".equals(field)){
|
||||
aliyunBo.setTown(value);
|
||||
}else if("devzone".equals(field)){
|
||||
aliyunBo.setDevzone(value);
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) throws ClientException {
|
||||
DefaultProfile profile = DefaultProfile.getProfile(
|
||||
REGIONID,
|
||||
ACCESSKEYID,
|
||||
SECRET);
|
||||
IAcsClient client = new DefaultAcsClient(profile);
|
||||
StructureAddressRequest request = new StructureAddressRequest();
|
||||
request.setServiceCode("addrp");
|
||||
request.setAppKey(APPKEY);
|
||||
request.setText("杭州市文一西路969号");
|
||||
request.setDefaultProvince("浙江省");
|
||||
request.setDefaultCity("杭州市");
|
||||
request.setDefaultDistrict("余杭区");
|
||||
StructureAddressResponse response = client.getAcsResponse(request);
|
||||
JSONObject responseJson = JSONObject.fromObject(response.getData());
|
||||
String value = (String) responseJson.get("structure");
|
||||
JSONObject json = new JSONObject();
|
||||
for (String key:value.split("\t")){
|
||||
String[] arry = key.split("=");
|
||||
json.put(arry[0],arry[1]);
|
||||
}
|
||||
System.out.println(JsonUtils.convertJsonToJavaObj(json, AliyunBo.class));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
package com.fangjia.service.bo;
|
||||
|
||||
public class AliyunBo {
|
||||
private String city;
|
||||
private String prov;
|
||||
private String district;
|
||||
private String poi;
|
||||
private String houseno;
|
||||
private String cellno;
|
||||
private String roomno;
|
||||
private String status;
|
||||
private String road;
|
||||
private String roadno;
|
||||
private String subroad;
|
||||
private String floorno;
|
||||
private String town;
|
||||
private String subpoi;
|
||||
private String community;
|
||||
private String devzone;
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getProv() {
|
||||
return prov;
|
||||
}
|
||||
|
||||
public void setProv(String prov) {
|
||||
this.prov = prov;
|
||||
}
|
||||
|
||||
public String getDistrict() {
|
||||
return district;
|
||||
}
|
||||
|
||||
public void setDistrict(String district) {
|
||||
this.district = district;
|
||||
}
|
||||
|
||||
public String getPoi() {
|
||||
return poi;
|
||||
}
|
||||
|
||||
public void setPoi(String poi) {
|
||||
this.poi = poi;
|
||||
}
|
||||
|
||||
public String getHouseno() {
|
||||
return houseno;
|
||||
}
|
||||
|
||||
public void setHouseno(String houseno) {
|
||||
this.houseno = houseno;
|
||||
}
|
||||
|
||||
public String getCellno() {
|
||||
return cellno;
|
||||
}
|
||||
|
||||
public void setCellno(String cellno) {
|
||||
this.cellno = cellno;
|
||||
}
|
||||
|
||||
public String getRoomno() {
|
||||
return roomno;
|
||||
}
|
||||
|
||||
public void setRoomno(String roomno) {
|
||||
this.roomno = roomno;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getRoad() {
|
||||
return road;
|
||||
}
|
||||
|
||||
public void setRoad(String road) {
|
||||
this.road = road;
|
||||
}
|
||||
|
||||
public String getRoadno() {
|
||||
return roadno;
|
||||
}
|
||||
|
||||
public void setRoadno(String roadno) {
|
||||
this.roadno = roadno;
|
||||
}
|
||||
|
||||
public String getSubroad() {
|
||||
return subroad;
|
||||
}
|
||||
|
||||
public void setSubroad(String subroad) {
|
||||
this.subroad = subroad;
|
||||
}
|
||||
|
||||
public String getFloorno() {
|
||||
return floorno;
|
||||
}
|
||||
|
||||
public void setFloorno(String floorno) {
|
||||
this.floorno = floorno;
|
||||
}
|
||||
|
||||
public String getTown() {
|
||||
return town;
|
||||
}
|
||||
|
||||
public void setTown(String town) {
|
||||
this.town = town;
|
||||
}
|
||||
|
||||
public String getSubpoi() {
|
||||
return subpoi;
|
||||
}
|
||||
|
||||
public void setSubpoi(String subpoi) {
|
||||
this.subpoi = subpoi;
|
||||
}
|
||||
|
||||
public String getCommunity() {
|
||||
return community;
|
||||
}
|
||||
|
||||
public void setCommunity(String community) {
|
||||
this.community = community;
|
||||
}
|
||||
|
||||
public String getDevzone() {
|
||||
return devzone;
|
||||
}
|
||||
|
||||
public void setDevzone(String devzone) {
|
||||
this.devzone = devzone;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -128,7 +128,7 @@ public class AddressRepoServiceImpl implements AddressRepoService {
|
||||
}
|
||||
matchMetaDatas.add(data);
|
||||
}
|
||||
for(String keyword : keywords){
|
||||
/*for(String keyword : keywords){
|
||||
HttpRequest request = new HttpRequest();
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("query", keyword);
|
||||
@@ -221,7 +221,7 @@ public class AddressRepoServiceImpl implements AddressRepoService {
|
||||
} catch (HttpRequestException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
Iterator<AddressMatchMetaData> it = matchMetaDatas.iterator();
|
||||
while(it.hasNext()){
|
||||
AddressMatchMetaData data = it.next();
|
||||
|
||||
Reference in New Issue
Block a user