package main import ( "strings" ) //对比项目名称、项目编号 func comparePNC(info *Info, compareProject *Project) (compareStr string, score int) { if info.ProjectName != "" { pns := []string{} if compareProject.ProjectName != "" { pns = append(pns, compareProject.ProjectName) } ifind := 0 templen := 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) if retv == 1 { ifind = 1 break } else { //v1 := CosineSimilar(pn, v) if retv == 2 { templen = len([]rune(v)) ifind = 2 break } //else if ifind == 0 { // ifind = 3 //} } } } switch ifind { case 0: compareStr = "D" case 1: compareStr = "A" score += 4 if len([]rune(info.ProjectName)) > 18 { score += 2 } case 2: compareStr = "B" score += 2 if templen > info.LenPN { templen = info.LenPN } if templen > 12 { score += 1 } case 3: compareStr = "C" } } else { compareStr = "D" } /* 项目编号 - -()() 要注意 init_text = ["号","(重)","(第二次)","(重)"] all_clean_mark = ["[","(","【","(","〖","]",")","】",")","〗","-","〔","〕","《","[","]","{","}","{","—"," ","-","﹝","﹞","–"] */ for index, pc := range []string{info.ProjectCode, ""} { if pc != "" { pcs := []string{} if compareProject.ProjectCode != "" { pcs = append(pcs, compareProject.ProjectCode) } ifind := 0 templen := 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 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 { ifind = 2 templen = len([]rune(v)) } } else if ifind == 0 { ifind = 3 } } } switch ifind { case 0: compareStr += "D" case 1: compareStr += "A" score += 4 if len([]rune(pc)) > 18 { score += 2 } case 2: compareStr += "B" score += 2 if index == 0 { if templen > info.LenPC { templen = info.LenPC } if templen > 12 { score += 1 } } else { if templen > info.LenPTC { templen = info.LenPTC } if templen > 12 { score += 1 } } case 3: compareStr += "C" } } else { compareStr += "D" } } return } func CheckContain(b1, b2 string) (res int) { b1 = replaceStr.ReplaceAllString(b1, "") b2 = replaceStr.ReplaceAllString(b2, "") if b1 == b2 { res = 1 //相等 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 = 1 //相等 } else if b1 == "" || b2 == "" { res = 2 //包含 } else { res = 3 //不相等 } return }