feature(地址拆分):地址清洗开发

1. 常规地址
2. 连号(结尾、中间)
3. 多号
4. 包含小区名称和路名
This commit is contained in:
purple 2020-08-06 17:29:00 +08:00
parent de0a56880c
commit 0bdfcc8c75
21 changed files with 5349 additions and 1100 deletions

View File

@ -6,12 +6,16 @@ package com.ruoyi.project.tool.address;
* @author lihe * @author lihe
*/ */
public enum AddressNodeType { public enum AddressNodeType {
DISTRICT("区域"), DISTRICT(""),
REGION(""), REGION(""),
BLOCK("板块"), BLOCK(""),
NONG(""),
NOT_FIND("没有节点"),
ROAD(""), ROAD(""),
CNAME("小区"),
NONG(""),
HAO(""), HAO(""),
LIAN_HAO("连号"),
MULTI_HAO("多号"), MULTI_HAO("多号"),
ZHUANG(""), ZHUANG(""),
ZUO(""), ZUO(""),

View File

@ -1,8 +1,73 @@
package com.ruoyi.project.tool.address; package com.ruoyi.project.tool.address;
import com.ruoyi.project.tool.address.model.AdrNode;
import java.util.LinkedList;
import java.util.List;
/**
* 地址结果
*
* @author lihe
*/
public class AddressResult { public class AddressResult {
private ParseContext context;
private String district; private String district;
private String region; private String region;
private Boolean multi; private String block;
private List<String> cleanAddress;
public AddressResult(ParseContext context) {
this.context = context;
}
public String getDistrict() {
return context.getDistrict();
}
public String getRegion() {
return context.getRegion();
}
public String getBlock() {
return context.getBlock();
}
public List<String> getCleanAddress() {
List<AdrNode> nodeList = context.getNodeList();
if (0 == nodeList.size()) {
return null;
}
cleanAddress = new LinkedList<>();
for (int i = 0; i < nodeList.size(); i++) {
}
nodeList.forEach(rootNode -> {
StringBuilder sb = new StringBuilder();
loop(sb, rootNode);
});
return cleanAddress;
}
private void loop(StringBuilder sb, AdrNode rootNode) {
sb.append(rootNode.getContent());
if (null == rootNode.getChildren()) {
cleanAddress.add(sb.toString());
return;
}
if (rootNode.getChildren().size() > 1) {
for (int i = 0; i < rootNode.getChildren().size(); i++) {
StringBuilder newSb = new StringBuilder(sb);
loop(newSb, rootNode.getChildren().get(i));
}
} else {
loop(sb, rootNode.getChildren().get(0));
}
}
} }

View File

@ -0,0 +1,24 @@
package com.ruoyi.project.tool.address;
import com.ruoyi.project.tool.address.parse.XParse;
/**
* 地址清洗工具类
*
* @author lihe
*/
public class AddressUtil {
/**
* 清洗
*
* @param text
* @return
*/
public static AddressResult clear(String text) {
ParseContext context = new ParseContext(text);
XParse xParse = new XParse(context);
xParse.parse();
AddressResult result = new AddressResult(context);
return result;
}
}

View File

@ -0,0 +1,82 @@
package com.ruoyi.project.tool.address;
import com.ruoyi.project.tool.address.model.AdrNode;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
/**
* context
*
* @author lihe
*/
public class ParseContext {
private String district;
private String region;
private String block;
private Integer startIndex = 0;
private final StringBuilder sb;
private List<String> features = new LinkedList<>();
private List<AdrNode> nodeList = new ArrayList<>(20);
public ParseContext(String text) {
this.sb = new StringBuilder(text);
}
public String getDistrict() {
return district;
}
public void setDistrict(String district) {
this.district = district;
this.startIndex = this.sb.indexOf(district);
}
public String getRegion() {
return region;
}
public void addRegion(String region, Integer startIndex) {
this.region = region;
this.startIndex = startIndex;
}
public String getBlock() {
return block;
}
public void addBlock(String block, Integer startIndex) {
this.block = block;
this.startIndex = startIndex;
}
public void setStartIndex(Integer startIndex) {
this.startIndex = startIndex;
}
public Integer getStartIndex() {
return startIndex;
}
public void addNode(AdrNode node) {
this.nodeList.add(node);
this.startIndex = node.getEndIndex();
}
public StringBuilder getContent() {
return this.sb;
}
public List<AdrNode> getNodeList() {
return nodeList;
}
public void addFeature(String feature) {
this.features.add(feature);
}
public int getIndexOf(String text) {
return this.getContent().indexOf(text, this.getStartIndex());
}
}

View File

@ -0,0 +1,64 @@
package com.ruoyi.project.tool.address.model;
import com.ruoyi.project.tool.address.AddressNodeType;
import java.util.LinkedList;
import java.util.List;
/**
* node
*
* @author lihe
*/
public abstract class AdrNode {
protected AddressNodeType nodeType;
private Integer startIndex;
private Integer endIndex;
private final String content;
protected List<AdrNode> children;
public AdrNode(String content, Integer startIndex) {
this.content = content;
this.startIndex = startIndex;
}
public AdrNode(String content, Integer startIndex, Integer endIndex) {
this.content = content;
this.startIndex = startIndex;
this.endIndex = endIndex;
}
public AddressNodeType getNodeType() {
return nodeType;
}
public String getContent() {
return content;
}
public Integer getEndIndex() {
return endIndex;
}
public void setEndIndex(Integer endIndex) {
this.endIndex = endIndex;
}
public List<AdrNode> getChildren() {
return children;
}
/**
* 添加节点
*
* @param node 节点
*/
public void addNode(AdrNode node) {
if (null == this.children) {
this.children = new LinkedList<>();
}
this.children.add(node);
}
}

View File

@ -0,0 +1,15 @@
package com.ruoyi.project.tool.address.model;
import com.ruoyi.project.tool.address.AddressNodeType;
/**
*
*
* @author lihe
*/
public class CengNode extends AdrNode {
public CengNode(String content, Integer startIndex, Integer endIndex) {
super(content, startIndex, endIndex);
this.nodeType = AddressNodeType.CENG;
}
}

View File

@ -0,0 +1,28 @@
package com.ruoyi.project.tool.address.model;
import com.ruoyi.project.tool.address.AddressNodeType;
import java.util.LinkedList;
import java.util.List;
/**
*
*
* @author lihe
*/
public class HaoNode extends AdrNode {
private List<String> shiList = new LinkedList<>();
public HaoNode(String content, Integer startIndex, Integer endIndex) {
super(content, startIndex, endIndex);
this.nodeType = AddressNodeType.HAO;
}
/**
* 交叉路
*
* @param shi
*/
public void addShi(String shi) {
shiList.add(shi);
}
}

View File

@ -0,0 +1,24 @@
package com.ruoyi.project.tool.address.model;
import com.ruoyi.project.tool.address.AddressNodeType;
import java.util.LinkedList;
import java.util.List;
/**
*
*
* @author lihe
*/
public class LianHaoNode extends AdrNode {
private List<String> shiList = new LinkedList<>();
public LianHaoNode(String content, Integer startIndex, Integer endIndex) {
super(content, startIndex, endIndex);
this.nodeType = AddressNodeType.LIAN_HAO;
}
public void addShi(String shi) {
shiList.add(shi);
}
}

View File

@ -0,0 +1,30 @@
package com.ruoyi.project.tool.address.model;
import com.ruoyi.project.tool.address.AddressNodeType;
import java.util.LinkedList;
import java.util.List;
/**
*
*
* @author lihe
*/
public class NongNode extends AdrNode {
private List<String> haoList = new LinkedList<>();
public NongNode(String content, Integer startIndex, Integer endIndex) {
super(content, startIndex, endIndex);
this.nodeType = AddressNodeType.NONG;
}
/**
* 交叉路
*
* @param road
*/
public void addHao(String road) {
haoList.add(road);
}
}

View File

@ -0,0 +1,34 @@
package com.ruoyi.project.tool.address.model;
import com.ruoyi.project.tool.address.AddressNodeType;
import java.util.LinkedList;
import java.util.List;
/**
* 路名或者小区名称
*
* @author lihe
*/
public class RoadNode extends AdrNode {
private List<String> roadList = new LinkedList<>();
public RoadNode(String content, Integer startIndex) {
super(content, startIndex);
this.nodeType = AddressNodeType.ROAD;
}
public RoadNode(String content, Integer startIndex, Integer endIndex) {
super(content, startIndex, endIndex);
this.nodeType = AddressNodeType.ROAD;
}
/**
* 交叉路
*
* @param road
*/
public void addRoad(String road) {
roadList.add(road);
}
}

View File

@ -0,0 +1,15 @@
package com.ruoyi.project.tool.address.model;
import com.ruoyi.project.tool.address.AddressNodeType;
/**
*
*
* @author lihe
*/
public class ShiNode extends AdrNode {
public ShiNode(String content, Integer startIndex, Integer endIndex) {
super(content, startIndex, endIndex);
this.nodeType = AddressNodeType.SHI;
}
}

View File

@ -0,0 +1,170 @@
package com.ruoyi.project.tool.address.parse;
import com.ruoyi.common.utils.LoadUtil;
import com.ruoyi.project.tool.address.ParseContext;
import com.ruoyi.project.tool.address.model.RoadNode;
import java.util.List;
import java.util.Map;
/**
* X解析
*
* @author lihe
*/
public class XParse {
private static final int DISTRICT_LENGTH = 8;
private static final String SHANGHAI_SHI = "上海市";
private static final String SHANGHAI = "上海";
private static final String SHANG_SHANG = "上上";
private static final String SHANG = "";
private Map<String, String> districtMap = LoadUtil.loadDict("address-dict/district.dict");
private List<String> regionList = LoadUtil.loadList("address-dict/region.dict");
private List<String> blockList = LoadUtil.loadList("address-dict/block.dict");
private List<String> roadList = LoadUtil.loadList("address-dict/road.dict");
private List<String> communityNameList = LoadUtil.loadList("address-dict/community.dict");
private ParseContext context;
public XParse(ParseContext context) {
this.context = context;
}
/**
* 区域板块
* 小区
*/
public void parse() {
parseDistrict();
parseRegion();
parseBlock();
parseRoad();
parseCommunityName();
}
/**
* 小区名称
*/
private void parseCommunityName() {
RoadNode communityNameNode = null;
for (int i = 0; i < communityNameList.size(); i++) {
int index = this.context.getContent().indexOf(communityNameList.get(i), this.context.getStartIndex());
if (-1 != index) {
communityNameNode = new RoadNode(communityNameList.get(i), index,
index + communityNameList.get(i).length());
break;
}
}
if (null != communityNameNode) {
this.context.addNode(communityNameNode);
YParse yParse = new YParse(communityNameNode, context);
yParse.parse();
return;
}
}
/**
* 路名
*/
private void parseRoad() {
int startIndex = this.context.getStartIndex();
int endIndex = 0;
RoadNode firstNode = null;
for (int i = 0; i < roadList.size(); i++) {
int index = this.context.getContent().indexOf(roadList.get(i), startIndex);
if (-1 != index) {
RoadNode roadNode = new RoadNode(roadList.get(i), index);
if (null == firstNode) {
firstNode = roadNode;
} else {
// 连路
if (endIndex + 1 == index) {
firstNode.addRoad(firstNode.getContent());
firstNode.addRoad(roadList.get(i));
} else {
// 新旧地址
}
}
startIndex = index;
endIndex = index + roadList.get(i).length();
}
}
// 单点
if (null != firstNode) {
firstNode.setEndIndex(endIndex);
this.context.addNode(firstNode);
YParse yParse = new YParse(firstNode, context);
yParse.parse();
return;
}
for (int i = 0; i < roadList.size(); i++) {
// 砍掉
// XX街加上
String noRoad = roadList.get(i);
if (noRoad.endsWith("")) {
noRoad = noRoad.substring(0, noRoad.length() - 1);
}
int index = this.context.getContent().indexOf(noRoad, startIndex);
if (-1 != index) {
RoadNode roadNode = new RoadNode(noRoad, index);
if (null == firstNode) {
firstNode = roadNode;
} else {
// 连路
if (endIndex + 1 == index) {
firstNode.addRoad(firstNode.getContent());
firstNode.addRoad(roadList.get(i));
} else {
// 新旧地址
}
}
startIndex = index;
endIndex = index + roadList.get(i).length();
}
}
}
private void parseDistrict() {
String shanghaiAndDistrict = null;
if (this.context.getContent().length() >= DISTRICT_LENGTH) {
shanghaiAndDistrict = (SHANG + this.context.getContent().substring(0, 7)).replace(SHANG_SHANG, SHANG);
} else {
shanghaiAndDistrict = (SHANG + this.context.getContent()).replace(SHANG_SHANG, SHANG);
}
if (!shanghaiAndDistrict.startsWith(SHANGHAI_SHI) && !shanghaiAndDistrict.startsWith(SHANGHAI) && shanghaiAndDistrict.startsWith(SHANG)) {
shanghaiAndDistrict = shanghaiAndDistrict.substring(1, shanghaiAndDistrict.length() - 1);
}
for (Map.Entry<String, String> district : districtMap.entrySet()) {
if (shanghaiAndDistrict.startsWith(district.getKey())) {
this.context.setDistrict(district.getValue());
}
}
}
private void parseRegion() {
for (int i = 0; i < regionList.size(); i++) {
int index = this.context.getContent().indexOf(regionList.get(i), this.context.getStartIndex());
if (-1 != index) {
this.context.addRegion(regionList.get(i), index);
}
}
}
private void parseBlock() {
for (int i = 0; i < blockList.size(); i++) {
int index = this.context.getContent().indexOf(blockList.get(i), this.context.getStartIndex());
if (-1 != 1) {
this.context.addBlock(blockList.get(i), index);
}
}
}
}

View File

@ -0,0 +1,148 @@
package com.ruoyi.project.tool.address.parse;
import com.ruoyi.project.tool.address.ParseContext;
import com.ruoyi.project.tool.address.model.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Y解析
* ABC弄(DEF支弄)
* ABC号DEF号()
* ABCDEFGHI号ABC号DEF号GHI号
*
* @author lihe
*/
public class YParse {
private static final String HAO = "";
private static final String DEFAULT_NONG_PATTERN = "[\\d一二三四五六七八九十]+弄([\\d一二三四五六七八九十]+支弄)?";
private static final String DEFAULT_HAO_PATTERN = "([\\dA-Za-z]+)号";
// 连号结束=
private static final String LIAN_HAO_PATTERN = "\\d+号\\d+号";
// 多号
private static final String MULTI_HAO_PATTERN = "(\\d+(号)?[、\\.\\-\\_]?)+号";
private static final String NUMBER_PATTERN = "\\d+";
private ParseContext context;
private AdrNode rootNode;
public YParse(AdrNode adrNode, ParseContext context) {
this.context = context;
this.rootNode = adrNode;
}
public void parse() {
parseNong();
parseHao();
parseZuo();
}
private void parseZuo() {
}
/**
* 连号
*
* @param text
* @param matchText
*/
private void parseLianHao(String text, String matchText) {
if (text.endsWith(matchText)) {
// ${1}号${2}修改最后一个字符
this.context.getContent().replace(this.context.getContent().length() - 1,
this.context.getContent().length() - 1, "");
// 找到${1}
Matcher haoMatch = Pattern.compile(DEFAULT_HAO_PATTERN).matcher(matchText);
if (haoMatch.find()) {
String hao = haoMatch.group();
int index = this.context.getIndexOf(hao);
HaoNode haoNode = new HaoNode(hao, index, index + hao.length());
this.rootNode.addNode(haoNode);
this.context.setStartIndex(haoNode.getEndIndex());
ZParse zParse = new ZParse(haoNode, this.context, haoNode.getEndIndex());
zParse.parse();
}
} else {
// 中间连号
int index = this.context.getIndexOf(matchText);
LianHaoNode haoNode = new LianHaoNode(matchText, index, index + matchText.length());
this.rootNode.addNode(haoNode);
this.context.setStartIndex(haoNode.getEndIndex());
ZParse zParse = new ZParse(haoNode, this.context, haoNode.getEndIndex());
zParse.parse();
}
}
/**
* 并列号
*/
private void parseMultiHao(String matchText) {
Pattern numberPattern = Pattern.compile(NUMBER_PATTERN);
Matcher matcher = numberPattern.matcher(matchText);
while (matcher.find()) {
int index = this.context.getIndexOf(matcher.group());
if (-1 == index) {
continue;
}
LianHaoNode haoNode = new LianHaoNode(matcher.group() + "", index, index + matcher.group().length());
this.rootNode.addNode(haoNode);
this.context.setStartIndex(haoNode.getEndIndex());
ZParse zParse = new ZParse(haoNode, this.context, haoNode.getEndIndex());
zParse.parse();
}
}
private void parseHao() {
// 连号
String text = this.context.getContent().substring(this.context.getStartIndex());
Pattern lianHaoPattern = Pattern.compile(LIAN_HAO_PATTERN);
Matcher matcher = lianHaoPattern.matcher(text);
if (matcher.find()) {
parseLianHao(text, matcher.group());
return;
}
// 并列号
Pattern multiHaoPattern = Pattern.compile(MULTI_HAO_PATTERN);
matcher = multiHaoPattern.matcher(text);
if (matcher.find()) {
parseMultiHao(matcher.group());
return;
}
// 默认的号
Pattern haoPattern = Pattern.compile(DEFAULT_HAO_PATTERN);
matcher = haoPattern.matcher(text);
if (matcher.find()) {
int index = this.context.getIndexOf(matcher.group());
HaoNode haoNode = new HaoNode(matcher.group(), index, index + matcher.group(0).length());
this.rootNode.addNode(haoNode);
this.context.setStartIndex(haoNode.getEndIndex());
ZParse zParse = new ZParse(haoNode, this.context, haoNode.getEndIndex());
zParse.parse();
return;
}
}
private void parseNong() {
Pattern nongPattern = Pattern.compile(DEFAULT_NONG_PATTERN);
Matcher matcher = nongPattern.matcher(this.context.getContent());
if (matcher.find()) {
int index = this.context.getIndexOf(matcher.group(0));
NongNode nongNode = new NongNode(matcher.group(0), index, index + matcher.group(0).length());
this.rootNode.addNode(nongNode);
this.rootNode = nongNode;
this.context.setStartIndex(nongNode.getEndIndex());
}
}
}

View File

@ -0,0 +1,150 @@
package com.ruoyi.project.tool.address.parse;
import com.ruoyi.project.tool.address.ParseContext;
import com.ruoyi.project.tool.address.model.AdrNode;
import com.ruoyi.project.tool.address.model.CengNode;
import com.ruoyi.project.tool.address.model.HaoNode;
import com.ruoyi.project.tool.address.model.ShiNode;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Z解析
* <p>
* 102.3室
* 102103室
* 1-3层1_3层
*
* @author lihe
*/
public class ZParse {
private static final String FU_SHI = "复式";
private static final String NUMBER_PATTERN = "\\d+";
private static final String DEFAULT_SHI_PATTERN1 = "([\\dA-Za-z\\_\\-\\.\\——\\、,]+)(室?)$";
private static final String DEFAULT_SHI_PATTERN = "([\\dA-Za-z\\-\\_\\.]+)室";
private static final String CHINESE_FLOOR_PATTERN = "([一二三四五六七八九十]+)层";
private static final String DEFAULT_FLOOR_PATTERN = "地下?([\\d一二三四五六七八九十])层";
private static final String TAIL_FLOOR_PATTERN = "(\\d[\\-\\_\\——\\—]?\\d)(层)?$";
private static final String DEFAULT_ZHUANG_PATTERN = "(\\d+)幢";
private ParseContext context;
private AdrNode rootNode;
private String floor;
private Integer startIndex;
public ZParse(AdrNode adrNode, ParseContext context, Integer index) {
this.context = context;
this.rootNode = adrNode;
this.startIndex = index;
}
public void parse() {
parseCeng();
parseZhuang();
parseShi();
tag();
}
private void parseZhuang() {
Pattern haoPattern = Pattern.compile(DEFAULT_ZHUANG_PATTERN);
Matcher matcher = haoPattern.matcher(this.context.getContent());
if (matcher.find()) {
int index = this.context.getContent().indexOf(matcher.group(0), this.startIndex);
HaoNode haoNode = new HaoNode(matcher.group(0), index, index + matcher.group(0).length());
this.rootNode.addNode(haoNode);
startIndex = haoNode.getEndIndex();
}
}
private void parseShi() {
// 复式
if (-1 != this.context.getContent().indexOf(FU_SHI)) {
String content = this.context.getContent().substring(this.startIndex);
Pattern shiPattern = Pattern.compile(NUMBER_PATTERN);
Matcher matcher = shiPattern.matcher(content);
if (matcher.find()) {
int index = this.context.getContent().indexOf(matcher.group(0), this.startIndex);
ShiNode shiNode = new ShiNode(matcher.group(0) + "", index, index + matcher.group(0).length());
this.rootNode.addNode(shiNode);
startIndex = shiNode.getEndIndex();
}
} else {
Pattern shiPattern = Pattern.compile(DEFAULT_SHI_PATTERN);
Matcher matcher = shiPattern.matcher(this.context.getContent());
if (matcher.find()) {
int index = this.context.getContent().indexOf(matcher.group(0), this.startIndex);
ShiNode shiNode = new ShiNode(matcher.group(0), index, index + matcher.group(0).length());
this.rootNode.addNode(shiNode);
startIndex = shiNode.getEndIndex();
}
}
}
private void tag() {
// 车位车库地块
if (-1 != this.context.getContent().indexOf("车位") || -1 != this.context.getContent().indexOf("车库")
|| -1 != this.context.getContent().indexOf("停车")) {
this.context.addFeature("车位");
}
if (-1 != this.context.getContent().indexOf("地块")) {
this.context.addFeature("地块");
}
}
private Boolean invalidCeng(int floorIndex) {
// 判断这个层是否可取
Pattern shiPattern = Pattern.compile(DEFAULT_SHI_PATTERN);
Matcher shiMatcher = shiPattern.matcher(this.context.getContent());
if (shiMatcher.find()) {
int shiIndex = this.context.getContent().indexOf(shiMatcher.group(0), this.startIndex);
return floorIndex > shiIndex;
}
return true;
}
private void parseCeng() {
Pattern floorPattern = Pattern.compile(CHINESE_FLOOR_PATTERN);
Matcher matcher = floorPattern.matcher(this.context.getContent());
if (matcher.find()) {
int index = this.context.getContent().indexOf(matcher.group(0), this.startIndex);
if (invalidCeng(index)) {
return;
}
CengNode cengNode = new CengNode(matcher.group(0), index, index + matcher.group(0).length());
this.rootNode.addNode(cengNode);
rootNode.addNode(cengNode);
return;
}
// 层结尾
floorPattern = Pattern.compile(TAIL_FLOOR_PATTERN);
matcher = floorPattern.matcher(this.context.getContent());
if (matcher.find()) {
return;
}
// 地下层
floorPattern = Pattern.compile(DEFAULT_FLOOR_PATTERN);
matcher = floorPattern.matcher(this.context.getContent());
if (matcher.find()) {
String num = matcher.group(1)
.replace("", "1")
.replace("", "2")
.replace("", "3")
.replace("", "4")
.replace("", "5");
int index = this.context.getContent().indexOf(matcher.group(0), this.startIndex);
if (invalidCeng(index)) {
return;
}
CengNode cengNode = new CengNode("-" + num, index, index + matcher.group(0).length());
this.rootNode.addNode(cengNode);
rootNode.addNode(cengNode);
return;
}
}
}

View File

@ -24,9 +24,10 @@ public abstract class BaseAddressBuilder implements AddressBuilder {
private static final int DISTRICT_LENGTH = 8; private static final int DISTRICT_LENGTH = 8;
private static final String SHANGHAI_SHI = "上海市"; private static final String SHANGHAI_SHI = "上海市";
private static final String SHANGHAI = "上海"; private static final String SHANGHAI = "上海";
private static final String SHANG_SHANG = "上上";
private static final String SHANG = ""; private static final String SHANG = "";
private static final String HAO = ""; private static final String HAO = "";
private static final String SHANG_SHANG = "上上";
private static final String CHINESE_FLOOR_PATTERN = "([一二三四五六七八九十]+)层"; private static final String CHINESE_FLOOR_PATTERN = "([一二三四五六七八九十]+)层";
private static final String NUMBER_FLOOR_PATTERN = "(\\d+)层"; private static final String NUMBER_FLOOR_PATTERN = "(\\d+)层";
private static final String DEFAULT_HAO_PATTERN = "([\\dA-Za-z]+)号"; private static final String DEFAULT_HAO_PATTERN = "([\\dA-Za-z]+)号";

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,10 @@
package com.ruoyi; package com.ruoyi;
import com.ruoyi.common.utils.LoadUtil; import com.ruoyi.common.utils.LoadUtil;
import com.ruoyi.project.tool.address.AddressContent; import com.ruoyi.project.tool.address.*;
import com.ruoyi.project.tool.address.CleanUtil;
import com.ruoyi.project.tool.address.StandardAddress;
import com.ruoyi.project.tool.address.model.CleanAddress; import com.ruoyi.project.tool.address.model.CleanAddress;
import com.ruoyi.project.tool.address.model.LianHaoNode;
import com.ruoyi.project.tool.address.parse.ZParse;
import com.ruoyi.project.tool.address.utils.DefaultAddressBuilder; import com.ruoyi.project.tool.address.utils.DefaultAddressBuilder;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -15,11 +15,34 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.Base64; import java.util.Base64;
import java.util.List; import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CleanUtilTests { public class CleanUtilTests {
@Test @Test
public void testSortDistrict() { public void printStreet() {
List<String> textList = LoadUtil.loadList("jie.dict");
textList.forEach(item -> {
if (!item.contains("") && item.contains("") && !item.contains("街坊")) {
System.out.println(item);
}
});
}
@Test
public void printNoRoad() {
List<String> textList = LoadUtil.loadList("icbc.dict");
textList.forEach(item -> {
if (!item.contains("")) {
System.out.println(item);
}
});
}
@Test
public void testSort() {
List<String> textList = LoadUtil.loadList("temp.dict"); List<String> textList = LoadUtil.loadList("temp.dict");
textList.sort((x, y) -> y.length() - x.length()); textList.sort((x, y) -> y.length() - x.length());
textList.forEach(item -> { textList.forEach(item -> {
@ -27,6 +50,91 @@ public class CleanUtilTests {
}); });
} }
@Test
public void testClear3() {
List<String> textList = LoadUtil.loadList("test.dict");
textList.forEach(item -> {
AddressResult addressResult = AddressUtil.clear(item);
if (null == addressResult.getCleanAddress()) {
return;
}
addressResult.getCleanAddress().forEach(adr -> {
System.out.println(String.format("%s\t%s\t", addressResult.getDistrict(), adr));
});
});
}
/**
* 中间连号
*/
@Test
public void testLianHaoInMiddle() {
AddressResult addressResult = AddressUtil.clear("上海市浦东新区拱北路278号22号702室");
if (null == addressResult.getCleanAddress()) {
return;
}
Assert.assertEquals(addressResult.getCleanAddress().get(0), "拱北路278号22号702室");
Assert.assertEquals(addressResult.getDistrict(), "浦东");
}
/**
* 尾部连号
*/
@Test
public void testLianHaoInEnd() {
AddressResult addressResult = AddressUtil.clear("上海市浦东新区拱北路278弄22号702号");
if (null == addressResult.getCleanAddress()) {
return;
}
Assert.assertEquals(addressResult.getCleanAddress().get(0), "拱北路278弄22号702室");
Assert.assertEquals(addressResult.getDistrict(), "浦东");
}
/**
* 多个号
*/
@Test
public void testMultiHao() {
AddressResult addressResult = AddressUtil.clear("上海市松江区泗泾镇德悦路375弄24、25号704室");
if (null == addressResult.getCleanAddress()) {
return;
}
Assert.assertEquals("德悦路375弄24号704室", addressResult.getCleanAddress().get(0));
Assert.assertEquals("德悦路375弄25号704室", addressResult.getCleanAddress().get(1));
Assert.assertEquals(addressResult.getDistrict(), "松江");
}
@Test
public void testWhileMatch() {
Pattern numberPattern = Pattern.compile("\\d+");
Matcher matcher = numberPattern.matcher("24、25号");
while (matcher.find()) {
System.out.println(matcher.group());
}
}
/**
* 地下
*/
@Test
public void testShiAndDiXiaShi() {
AddressResult addressResult = AddressUtil.clear("闵行区北华路168弄35号1002室及30号地下1层车位665室");
if (null == addressResult.getCleanAddress()) {
return;
}
addressResult.getCleanAddress().forEach(adr -> {
System.out.println(String.format("%s\t%s\t", addressResult.getDistrict(), adr));
});
}
@Test @Test
public void testClear2() { public void testClear2() {
// //

View File

@ -0,0 +1,677 @@
梅园三村,
钱仓路
其昌栈大街
钱仓路
其昌栈大街
花木西街
龙王庙镇西街
东三街
东三街
东三街
东三街
塘南路
塘南路
塘南路
东三街
北蔡大街
北蔡大街
北蔡大街
后长街
后长街
灵岩南路
杨思南街
杨思路
振兴中路
杨思路
思浦路
思浦路
思浦路
思浦路
灵岩南路
杨思南街
杨思路
灵岩南路
玉泉街
玉泉街
玉泉街
玉泉街
玉泉街
玉泉街
振兴东路
后长街
振兴东路
后长街
振兴东路
后长街
金桥横街
万安街
万安路
万安街
万安街
慈善街
大同路
大同路
石家街
石家街
石家街
石家街
石家街
石家街
学前街
学前街
学前街
王桥街
塘东街
塘东街
塘东街
南市街
南市街
南市街
南市街
南市街
三灶浜路
操场街
西市街
西市街
益民路
益民路
益民路
西市街
西市街
北市街
迎春街
普庆路
景园街
普园路
川六公路
南八灶街
南八灶街
西大街
西大街
西大街
西大街
西大街
西大街
西大街
西大街
中大街
中大街
关岳西路
南八灶街
南八灶街
顾家宅
东大街
宫宵公寓,
祝桥镇祝振街
南塘街
南塘街
下沙镇下沙新街
下沙镇下沙新街银信楼
东后老街
东后老街
北门大街
北门大街
北门大街
东门大街
东门大街
南门大街
西门大街
沿河泾南路
东门大街
南门大街
南门大街
南门大街
卫星东路
三角街
三角街
三角街
三角街
东门大街
十字街大楼
文师街
文友街
文益街
西门大街
书院镇船山街
书院镇石潭街
书院镇石潭街
书院镇首善街
书院镇首善街
申港街道竹柏路
申港街道竹柏路
申港街道竹柏路
申港街道竹柏路
申港街道雪绒花路
菊泉街
菊泉街
菊泉街
菊泉街
菊泉街
菊泉街
菊泉街
菊泉街
菊泉街
菊泉新村,
菊泉街
菊泉街
菊泉街
菊泉街
菊泉街
菊盛路
菊泉街
菊太路
菊泉街
菊太路
布长街
东西巷街
市二路
市二路
塘东街
塘东街
塘东街
塘东街
市河街
市河街
市河街
市河街
塘西街
塘西街
陈行街
宝钢五村,
宝钢五村西门街,
宝钢五村后河沿,
团结路
堡镇堡镇南路
堡镇中路
正大街
正大街
向阳路
城桥镇中街山路
川心街
川心街
川心街
川心街
新崇南路
人民路
新崇中路
八一路
富民街
花园弄
兴贤街
中街山路
西引路
东街供销四村
东街新村
东街新村二村
奉城镇南街
洪庙镇唐城街
鹏贸南街
平安镇堂前街
四团镇四新街
四新街
四新街
四新南街
塘外镇文化街
青村镇西街
新街二村
新街三村
新街一村
蟠龙街
池沟路
池沟路
公安街
公安街
保宁路
文迁路
公安街
虹镇老街
虹镇老街
虹镇老街
虹镇老街
虹镇老街
光启路
光启路
光启路
光启路
光启路
县左街
县左街
县左街
学院路
柳江街
柳江街
南仓街
南仓街
先棉祠街
先棉祠街
先棉祠街
先棉祠街
学前街
学前街
学院路
东街
巡道街
永泰街
悦来街
中华路
中华路
老太平街
庄家街
大林路
江阴街
江阴街
江阴街
江阴街
沙家街
大林路
制造局后街
黄渡镇劳动街
黄渡镇劳动街
黄渡镇劳动街
北大街
北大街
北大街
北大街
北大街
城中街
东大街
东大街
东大街
东大街
嘉定镇北大街
嘉定镇北大街
嘉定镇东大街
金沙路
嘉定镇南大街
嘉定镇南大街
嘉定镇南大街
嘉定镇南大街
嘉定镇西大街
嘉定镇张马路
嘉定镇中下塘街
马陆街
马陆街
马陆街
马陆街
马陆街
马陆街
马陆街
马陆街
马陆街
马陆街
马陆塘街
马陆塘街
双单路
双单路
马陆塘街
马陆塘街
南大街
南大街
南大街
南大街
南大街
南大街
清河路
梅园路
人民街
人民街
人民街
沙霞路
沙霞路
南大街
塔城路
塔城路
南大街
南大街
南大街
温宿路
北大街
北大街
项泾西街
新成路街道仓场路
新成路街道仓场路
新成路街道迎园中路
育英街
育英南街
中下塘街
中下塘街
中下塘街
和平街
和平街
解放街
南翔镇解放街
南翔镇解放街
解放街
解放街
解放街
解放街
解放街
解放街
解放街
解放街
解放街
解放街
劳动街
民主东街
民主东街
民主东街
民主东街
民主东街
民主东街
民主东街
民主东街
民主东街
民主街
民主街
民主街
民主街
民主街
民主街
民主街
民主街
解放街
解放街
解放街
南翔镇民主东街
南翔镇民主东街
南翔镇民主街
南翔镇民主街
南翔镇民主街
南翔镇红翔新村
漕泾镇中心街
中心街
枫泾镇南大街
枫泾镇新街
海汇街
海汇街
金山卫镇东街
金山卫镇钱圩东街
龙临街
山阳镇海汇街
山阳镇海汇街
干巷镇干溪街
廊下镇廊下大街
廊下镇廊下大街
廊下镇廊下大街
廊下镇下大街
吕巷镇璜溪东街
璜溪东街
吕巷镇璜溪东街
璜溪东街
吕巷镇建新大街
吕巷镇新东街
吕巷镇新东街
亭林镇开乐大街
亭林镇松隐大街
亭林镇松隐大街
亭林镇新建北街
亭林镇新建西街
朱行镇开乐大街
朱行镇开乐大街
朱行镇开乐大街
朱行镇开乐大街
朱行镇兴乐街
珠港街
城中路
新安街
临仓街
临源街
临源街
临源街
秀州街
秀州街
秀州街
秀州街
众安街
朱泾镇东林东街
朱泾镇东林街
朱泾镇东林街
朱泾镇东林街
朱泾镇东林街
朱泾镇金南街
朱泾镇金南街
朱泾镇金南街
朱泾镇临仓街
朱泾镇临仓街
朱泾镇临仓街
朱泾镇临源街
朱泾镇万安街
朱泾镇万安街
朱泾镇万安街
朱泾镇万安街
朱泾镇万安街
朱泾镇西林街
朱泾镇新汇街
朱泾镇秀州街
朱泾镇秀州街
朱泾镇秀州街
朱泾镇众安街
朱泾镇众安街
朱泾镇众安街
朱泾镇众安街
朱泾镇众安街
朱泾镇众安街
朱泾镇众安街
朱泾镇众安街
万春街
万春街
万春街
万春街
万春街
万春街
万春街
万春街
升平街
升平街
汝南街
汝南街
汝南街
汝南街
汝南街
汝南街
汝南街
南华街
南华街
中心街
南北大街
南北大街
新西街
东新街
富岩路
东街
马桥新村,
中街
新街
马桥镇东新街
马桥镇西街
马桥镇中街
中街
中街
中街
中街
南中街
西新路
马桥西街
马桥西街
马桥西街
富强街
富强街
七莘路
富强街
富强街
富强街
宝隆新村
南街
南街
莘浜路
莘庄镇西街
莘浜路
小西街
颛桥镇后东街
南大街
南大街
郁家弄,
南大街
南大街
兰溪路
南大街
白鹤镇南街
白鹤镇南街
华新镇华富街
华新镇华富街
华新镇华富街
华新镇华富街
华新镇华强街
华新镇华强街
华新镇华强街
华新镇华强街
华新镇华强街
华新镇华强街
华新镇华新街
华新镇华新街
华新镇华新街
重固镇大街
重固镇大街
重固镇大街
广场街
香花桥街道崧雅路
赵巷镇崧雅路
盈浦街道盈清路
盈清路
赵屯镇久远路
赵屯镇久远路
白鹤镇友爱东路
赵屯镇久远路
赵屯镇久远路
香花桥街道香大路
久业路
练塘镇前进街
九亭大街
九亭大街
九亭大街
九亭大街
涞亭南路
九亭大街
九亭大街
九亭大街
九亭大街
九亭大街
九亭大街
九亭大街
九亭镇九亭大街
九亭镇九亭大街
九亭镇九亭大街
九亭镇九亭大街
虬泾路
九亭大街
淡家浜街
淡家浜街
长水街
平原街
平原街
平原街
平原街
平原街
平原街
平原街
秦安街
秦安街
平原街
东外街
沪松路
北门街
北门街
阔街
李塔街
通波新村,
乐都路
乐都路
荣乐中路
下塘街
小塔前
长桥街
中山二路
潭东街
谷阳北路
新北街
新北街
新北街
新北街
新北街
新北街
新北街
新北街
新北街
新北街
新北街
新北街
新北街
新南街
新南街
新南街
新南街
新南街
新南街
新南街
新桥镇新南街
新镇街
新镇街
新镇街
新镇街
新镇街
新镇街
新镇街
新镇街
新镇街
新镇街
新中街
新中街
新中街
百花街
丁香园
桂林东街
桂林东街
桂林东街
桂林东街
桂林东街
桂林西街
桂林西街
桂林西街
桂林西街
桂林西街
桂林西街
桂林西街
桂林西街
桂林西街
桂林西街
桂林西街
桂林西街
桂林西街
桂林西街
桂林西街
钦州南路
钦州南路
钦州南路
桂林东街
小闸镇街
怀安街
紫阳路
紫阳路
汇站街
南丹路汇站街
汇站街
纪念路
学府路
学府街
北大街
蒲松北路
和顺街
菊泉街
环城东路
城中南路
学前街
中街小区,
中新路
中新路
中新路
菊泉街

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,12 @@
上海市普陀区长风一村40号601-2室
上海市松江区泗泾镇佘月路18弄28号9层901室
上海市浦东新区晨晖路825弄49号103复式
宝山区美艾路177弄167号1_3层
奉贤区南桥镇江海新村(B)89幢578号402室
上海市嘉定区百安公路2699弄505号1层1-3层室
上海市松江区泗泾镇泗宝路298弄7号10层1004室
奉贤区南桥镇江海新村C6幢218号502室
上海市闸北区洛川东路310号503504室
上海市松江区泗泾镇德悦路375弄24、25号704室
闵行区北华路168弄35号1002室及30号地下1层车位665室
上海市浦东新区拱北路278号22号702室