JAvaバックグラウンドアドレス(省、市、区)、氏名、携帯電話番号アルゴリズム知能認識
5851 ワード
最近のプロジェクトでは、フロントで認識する必要がある情報に基づいてバックグラウンド処理を行い、住所に基づいて名前、携帯電話番号、住所情報をフロントエンドに返す必要があります.私はアルゴリズムを借りました:このアルゴリズムはandroi開発の時に使って、私のドアjavaが使う時に中の部分の内容を修正する必要があります.使用する场合はアイテムにもパッケージ化された省、市、区(県情报をkeyとし、valueは省市区コードに対応してmapパッケージを使用することができる.何千もの地域をネットで検索したほうがいい...
悪くないと思います.どこでもログを打って見ることができます.
private void DiscernAddressInfo(String addressInfo) {
//
String provinceInfo ="", cityInfo = "", countyInfo = "",areaInfo="", phoneInfo ="", nameInfo = "";
//
int provinceIndex=-1,cityIndex=-1,areaIndex=-1,phoneIndex=-1,nameIndex=-1;
/* */
Pattern pattern = Pattern.compile("([1][3-9][\\d]{9})|(0\\d{2,4}-\\d{7,8})");
Matcher matcher = pattern.matcher(addressInfo);
StringBuffer bf = new StringBuffer(64);
while (matcher.find()) {
bf.append(matcher.group()).append(",");
}
if (!StringUtil.isEmpty(phoneInfo)) {
phoneIndex=addressInfo.indexOf(phoneInfo);
addressInfo = addressInfo.replace(phoneInfo, "");// ,
}
/* */
List proList = itemNameList(file.getSampleProvinceList()); //
for (String province : proList) {
String tem;
if (province.contains(" ")) {
tem = province.replace(" ","");
} else if (province.contains(" ")) {
tem = province.replace(" ","");
} else {
tem = province;
}
if (addressInfo.contains(tem)) {
provinceInfo = province;
provinceIndex = addressInfo.indexOf(tem);
//
this.province=province;
break;
}
}
if (!StringUtil.isEmpty(provinceInfo)) { //
//
String provinceCode = file.getProvinceCode(provinceInfo);
//
this.provinceCode=provinceCode; //
//
List cityList = itemNameList(file.getSampleCityList(provinceCode));
for (String city : cityList) {
String temCity = null;
if (city.contains(" ")) {
temCity = city.replace(" ","");
} else {
temCity = city.replace(" ","");
}
if (addressInfo.contains(temCity)) {
cityInfo = city;
//
this.city=city;
break;
}
}
}
if (!StringUtil.isEmpty(cityInfo)) {//
// 、
String cityCode = file.getCityCode(cityInfo, file.getProvinceCode(provinceInfo));
//
this.cityCode=cityCode;
List areaList = itemNameList(file.getSampleCountyList(cityCode));
for (String county : areaList) {
String countyTem = null;
if (county.contains(" ")) {
countyTem = county.replace(" ","");
}
countyTem = county.substring(0, county.length() - 1);
if (addressInfo.contains(countyTem)) {
countyInfo = county;
/* */
areaIndex = addressInfo.indexOf(countyTem)+countyTem.length();
if(areaIndex<=addressInfo.length())
{
areaInfo=addressInfo.substring(areaIndex,addressInfo.length());
}
//
this.county=county;
this.countyCode=file.getCountyCode(cityCode,county);
break;
}
}
}else{
if(addressInfo.indexOf(" ")>0){
String cityTem=addressInfo.substring(addressInfo.indexOf(" ")-2,addressInfo.indexOf(" ")+1);
if(!TextUtils.isEmpty(file.getCountyCode(cityTem))){
this.countyCode=file.getCountyCode(cityTem);
if(!TextUtils.isEmpty(file.getCountyName(countyCode))){
this.county=file.getCountyName(countyCode);
this.cityCode=countyCode.substring(0,countyCode.length()-4);
this.city=file.getCityName(cityCode);
cityInfo=this.city;
countyInfo=this.county;
}
}
}
}
String areaTem = provinceInfo + cityInfo + countyInfo; //
if (!StringUtil.isEmpty(countyInfo)&&addressInfo.contains(countyInfo)) {
areaIndex = addressInfo.indexOf(countyInfo)+countyInfo.length();
if(areaIndex<=addressInfo.length())
{
areaInfo=addressInfo.substring(areaIndex,addressInfo.length());
}
}
int cutNote = addressInfo.indexOf(" ");
/* 。。*/
if (!StringUtil.isEmpty(provinceInfo)&&addressInfo.contains(provinceInfo)) {
provinceIndex = addressInfo.indexOf(provinceInfo);
}
if (provinceIndex > 0 && phoneIndex > 0) {
nameIndex = provinceIndex < phoneIndex ? provinceIndex : phoneIndex;
} else {
nameIndex = provinceIndex > phoneIndex ? provinceIndex : phoneIndex;
}
if (nameIndex > 0) {
String nameTem = addressInfo.substring(0, nameIndex);
if (nameTem.contains(" ")) {
String[] nameTem1 = nameTem.split(" ");
nameInfo = nameTem1[nameTem1.length - 1];
}
if (nameTem.contains("name")) {
String[] nameTem1 = nameTem.split("name");
nameInfo = nameTem1[nameTem1.length - 1];
}
if (StringUtil.isEmpty(nameInfo)) {
nameInfo = nameTem;
}
}
}
悪くないと思います.どこでもログを打って見ることができます.