package main import ( "regexp" "strings" ) func comparePNCB(info *Info, compareProject *ProjectInfo) (compareStr string, score int) { retv := 0 if info.ProjectName != "" { pns := []string{} if compareProject.ProjectName != "" { pns = append(pns, compareProject.ProjectName) } if len(compareProject.MPN) > 0 { pns = append(pns, compareProject.MPN...) } ifind := 0 for _, v := range pns { if info.ProjectName == v { ifind = 1 break } else { //if strings.Contains(info.ProjectName, v) || strings.Contains(v, info.ProjectName) || retv = CheckContain(info.ProjectName, v, info.Buyer) //if CheckContain(info.ProjectName, v, info.Buyer) if retv == 3 { ifind = 1 break } else if retv == 1 { ifind = 2 } else if ifind == 0 { ifind = 3 } } } switch ifind { case 0: compareStr = "D" case 1: compareStr = "A" score += 4 if len([]rune(info.ProjectName)) > 19 { score += 2 } case 2: compareStr = "B" score += 2 if len([]rune(info.ProjectName)) > 19 { score += 1 } case 3: compareStr = "C" } } else { compareStr = "D" } PNStr := compareStr for _, pc := range []string{info.ProjectCode, info.PTC} { if pc != "" { pcs := []string{} if compareProject.ProjectCode != "" { pcs = append(pcs, compareProject.ProjectCode) } if len(compareProject.MPC) > 0 { pcs = append(pcs, compareProject.MPC...) } ifind := 0 for _, v := range pcs { if pc == v { ifind = 1 break } else { // math.Abs(float64(len([]rune(pc))-len([]rune(v)))) < 6 //if !_numreg1.MatchString(pc) && !_zimureg1.MatchString(pc) && !_numreg1.MatchString(v) && !_zimureg1.MatchString(v) if (PNStr == "A" || PNStr == "B" || (!_nzreg.MatchString(pc) && !_nzreg.MatchString(v))) && (strings.Contains(pc, v) || strings.Contains(v, pc)) { t1 := pc t2 := v if len(v) > len(pc) { t1 = v t2 = pc } t3 := strings.Replace(t1, t2, "", -1) t3 = _datereg.ReplaceAllString(t3, "") if t3 == "" { ifind = 1 break } else if _hanreg.MatchString(t3) || _numreg1.MatchString(t3) { ifind = 2 } else { ifind = 3 } } else if ifind == 0 { ifind = 3 } } } switch ifind { case 0: compareStr += "D" case 1: compareStr += "A" score += 4 if len([]rune(pc)) > 19 { score += 2 } case 2: if compareStr == "C" && retv == 2 { compareStr += "C" } else { compareStr += "B" score += 2 if len([]rune(pc)) > 19 { score += 1 } } case 3: compareStr += "C" } } else { compareStr += "D" } } return } var _datereg = regexp.MustCompile("20[0-2][0-9][年-][0-9]{1,2}[月-][0-9]{1,2}[日-]([0-9]{1,2}时[0-9]{0,2})?") var _numreg1 = regexp.MustCompile("^[0-9-]{1,8}$") var _zimureg1 = regexp.MustCompile("^[a-zA-Z-]{1,7}$") var _nzreg = regexp.MustCompile("^[0-9a-zA-Z-]+$") var _hanreg = regexp.MustCompile(`^[\p{Han}::【】\\[\\]()()--、]+$`) var replaceStr = regexp.MustCompile("(工程|采购|项目|[?!、【】()]|栏标价|中标候选人|招标代理)") var pStr = regexp.MustCompile("(勘察|监理|施工|设计|验收|标段|分包|子包|[0-9A-Z]包|[一二三四五六七八九十0-9]批)") func CheckContain(b1, b2, infoBuyer string) (res int) { b1 = replaceStr.ReplaceAllString(b1, "") b2 = replaceStr.ReplaceAllString(b2, "") b1 = strings.Replace(b1, infoBuyer, "", 1) b2 = strings.Replace(b2, infoBuyer, "", 1) if b1 == b2 { res = 3 return } bs1 := []rune(b1) bs2 := []rune(b2) tmp := "" for i := 0; i < len(bs1); i++ { for j := 0; j < len(bs2); j++ { if bs1[i] == bs2[j] { tmp += string(bs1[i]) } else if tmp != "" { b1 = strings.Replace(b1, tmp, "", -1) b2 = strings.Replace(b2, tmp, "", -1) tmp = "" } } } if tmp != "" { b1 = strings.Replace(b1, tmp, "", -1) b2 = strings.Replace(b2, tmp, "", -1) } if b1 == b2 { res = 3 } else if (b1 == "" && !pStr.MatchString(b2)) || (b2 == "" && !pStr.MatchString(b1)) { res = 1 } else { res = 2 } return }