|
@@ -0,0 +1,91 @@
|
|
|
+package com.winhc.bigdata.utils;
|
|
|
+
|
|
|
+import cn.hutool.core.util.NumberUtil;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: XuJiakai
|
|
|
+ * 2021/6/8 13:36
|
|
|
+ */
|
|
|
+public class CaseConnectUtils {
|
|
|
+ private static final Pattern vagueWordPat = Pattern.compile("[某**xⅹxX×]");
|
|
|
+
|
|
|
+ public static Boolean isConnect(Set<String> currentCasePartyList, Set<String> connectCasePartyList
|
|
|
+ , String currentCaseNo, String connectCaseNo
|
|
|
+ , String currentCourtName, String connectCourtName) {
|
|
|
+
|
|
|
+ Map<String, Set<String>> currentCasePartyMap = currentCasePartyList.stream().filter(StringUtils::isNotBlank)
|
|
|
+ .map(s -> vagueWordPat.matcher(s).replaceAll("\002"))
|
|
|
+ .collect(Collectors.groupingBy(s -> s.substring(0, 1), Collectors.toSet()));
|
|
|
+
|
|
|
+ Map<String, Set<String>> connectCasePartyMap = connectCasePartyList.stream().filter(StringUtils::isNotBlank)
|
|
|
+ .map(s -> vagueWordPat.matcher(s).replaceAll("\002"))
|
|
|
+ .collect(Collectors.groupingBy(s -> s.substring(0, 1), Collectors.toSet()));
|
|
|
+
|
|
|
+ double matchNum = 0;
|
|
|
+
|
|
|
+ for (String surname : currentCasePartyMap.keySet()) {
|
|
|
+ matchNum += nameEqu(surname, currentCasePartyMap.getOrDefault(surname, new HashSet<String>()), connectCasePartyMap.getOrDefault(surname, new HashSet<>()));
|
|
|
+ }
|
|
|
+ Set<String> collect1 = currentCasePartyMap.entrySet().stream().flatMap(r -> r.getValue().stream()).collect(Collectors.toSet());
|
|
|
+ Set<String> collect2 = connectCasePartyMap.entrySet().stream().flatMap(r -> r.getValue().stream()).collect(Collectors.toSet());
|
|
|
+ int min = Math.min(collect1.size(), collect2.size());
|
|
|
+
|
|
|
+ if (matchNum == min && min != 0) {
|
|
|
+ return true;
|
|
|
+ } else if (NumberUtil.compare(matchNum, NumberUtil.div(min, 2)) >= 0) {
|
|
|
+ return caseNoMatch(currentCaseNo, connectCaseNo) || courtNameMatch(currentCourtName, connectCourtName);
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static double nameEqu(String surname, Set<String> nameSet1, Set<String> nameSet2) {
|
|
|
+ if (nameSet1.isEmpty() || nameSet2.isEmpty()) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ boolean nameSet1Match = nameSet1.stream().anyMatch(s -> s.contains("\002"));
|
|
|
+ boolean nameSet2Match = nameSet2.stream().anyMatch(s -> s.contains("\002"));
|
|
|
+ if (nameSet1Match || nameSet2Match) {
|
|
|
+ return Math.min(nameSet1.size(), nameSet2.size());
|
|
|
+ } else {
|
|
|
+ return CollectionUtils.intersection(nameSet1, nameSet2).size();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Boolean caseNoMatch(String currentCaseNo, String connectCaseNo) {
|
|
|
+ return currentCaseNo.equals(connectCaseNo);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Boolean courtNameMatch(String currentCourtName, String connectCourtName) {
|
|
|
+ return currentCourtName.equals(connectCourtName);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ Set<String> currentCasePartyList = new HashSet<String>() {
|
|
|
+ {
|
|
|
+ add("广西南宁伟联行置业有限公司");
|
|
|
+ add("广西美满园房地产开发有限公司");
|
|
|
+ add("李桂香");
|
|
|
+ }
|
|
|
+ };
|
|
|
+ Set<String> connectCasePartyList = new HashSet<String>() {
|
|
|
+ {
|
|
|
+ add("广西南宁伟联行置业有限公司");
|
|
|
+ add("广西美满园房地产开发有限公司");
|
|
|
+ add("陈世赞");
|
|
|
+ }
|
|
|
+ };
|
|
|
+ String currentCaseNo = "(2021)浙02执22号";
|
|
|
+ String connectCaseNo = "(2021)浙02执22号";
|
|
|
+ String currentCourtName = "浙江省宁波市中级人民法院";
|
|
|
+ String connectCourtName = "浙江省宁波市中级人民法院";
|
|
|
+
|
|
|
+ System.out.println(isConnect(currentCasePartyList, connectCasePartyList, currentCaseNo, connectCaseNo, currentCourtName, connectCourtName));
|
|
|
+ }
|
|
|
+}
|