merge_comparepnc.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. package main
  2. import (
  3. "strings"
  4. )
  5. //对比项目名称、项目编号
  6. func comparePNC(info *Info, compareProject *ProjectInfo) (compareStr string, score int) {
  7. if info.ProjectName != "" {
  8. pns := []string{}
  9. if compareProject.ProjectName != "" {
  10. pns = append(pns, compareProject.ProjectName)
  11. }
  12. if len(compareProject.MPN) > 0 {
  13. pns = append(pns, compareProject.MPN...)
  14. }
  15. ifind := 0
  16. templen := 0
  17. for _, v := range pns {
  18. if info.ProjectName == v {
  19. ifind = 1
  20. break
  21. } else {
  22. //if strings.Contains(info.ProjectName, v) || strings.Contains(v, info.ProjectName) ||
  23. retv := CheckContain(info.ProjectName, v)
  24. if retv == 1 {
  25. ifind = 1
  26. break
  27. } else {
  28. v1 := CosineSimilar(info.ProjectName, v)
  29. if retv == 2 || v1 > 0.81 {
  30. templen = len([]rune(v))
  31. ifind = 2
  32. } else if ifind == 0 {
  33. ifind = 3
  34. }
  35. }
  36. }
  37. }
  38. switch ifind {
  39. case 0:
  40. compareStr = "D"
  41. case 1:
  42. compareStr = "A"
  43. score += 4
  44. if len([]rune(info.ProjectName)) > 18 {
  45. score += 2
  46. }
  47. case 2:
  48. compareStr = "B"
  49. score += 2
  50. if templen > info.LenPN {
  51. templen = info.LenPN
  52. }
  53. info.PNBH = templen
  54. if templen > 12 {
  55. score += 1
  56. }
  57. case 3:
  58. compareStr = "C"
  59. }
  60. } else {
  61. compareStr = "D"
  62. }
  63. /*
  64. 项目编号 - -()() 要注意
  65. init_text = ["号","(重)","(第二次)","(重)"]
  66. all_clean_mark = ["[","(","【","(","〖","]",")","】",")","〗","-","〔","〕","《","[","]","{","}","{","—"," ","-","﹝","﹞","–"]
  67. */
  68. for index, pc := range []string{info.ProjectCode, info.PTC} {
  69. if pc != "" {
  70. pcs := []string{}
  71. if compareProject.ProjectCode != "" {
  72. pcs = append(pcs, compareProject.ProjectCode)
  73. }
  74. if len(compareProject.MPC) > 0 {
  75. pcs = append(pcs, compareProject.MPC...)
  76. }
  77. ifind := 0
  78. templen := 0
  79. for _, v := range pcs {
  80. if pc == v {
  81. ifind = 1
  82. break
  83. } else {
  84. // math.Abs(float64(len([]rune(pc))-len([]rune(v)))) < 6
  85. //if !_numreg1.MatchString(pc) && !_zimureg1.MatchString(pc) && !_numreg1.MatchString(v) && !_zimureg1.MatchString(v)
  86. if strings.Contains(pc, v) || strings.Contains(v, pc) {
  87. t1 := pc
  88. t2 := v
  89. if len(v) > len(pc) {
  90. t1 = v
  91. t2 = pc
  92. }
  93. t3 := strings.Replace(t1, t2, "", -1)
  94. t3 = _datereg.ReplaceAllString(t3, "")
  95. if t3 == "" {
  96. ifind = 1
  97. break
  98. } else {
  99. ifind = 2
  100. templen = len([]rune(v))
  101. }
  102. } else if ifind == 0 {
  103. ifind = 3
  104. }
  105. }
  106. }
  107. switch ifind {
  108. case 0:
  109. compareStr += "D"
  110. case 1:
  111. compareStr += "A"
  112. score += 4
  113. if len([]rune(pc)) > 18 {
  114. score += 2
  115. }
  116. case 2:
  117. compareStr += "B"
  118. score += 2
  119. if index == 0 {
  120. if templen > info.LenPC {
  121. templen = info.LenPC
  122. }
  123. info.PCBH = templen
  124. if templen > 12 {
  125. score += 1
  126. }
  127. } else {
  128. if templen > info.LenPTC {
  129. templen = info.LenPTC
  130. }
  131. info.PTCBH = templen
  132. if templen > 12 {
  133. score += 1
  134. }
  135. }
  136. case 3:
  137. compareStr += "C"
  138. }
  139. } else {
  140. compareStr += "D"
  141. }
  142. }
  143. return
  144. }
  145. func CheckContain(b1, b2 string) (res int) {
  146. b1 = replaceStr.ReplaceAllString(b1, "")
  147. b2 = replaceStr.ReplaceAllString(b2, "")
  148. if b1 == b2 {
  149. res = 1 //相等
  150. return
  151. }
  152. bs1 := []rune(b1)
  153. bs2 := []rune(b2)
  154. tmp := ""
  155. for i := 0; i < len(bs1); i++ {
  156. for j := 0; j < len(bs2); j++ {
  157. if bs1[i] == bs2[j] {
  158. tmp += string(bs1[i])
  159. } else if tmp != "" {
  160. b1 = strings.Replace(b1, tmp, "", -1)
  161. b2 = strings.Replace(b2, tmp, "", -1)
  162. tmp = ""
  163. }
  164. }
  165. }
  166. if tmp != "" {
  167. b1 = strings.Replace(b1, tmp, "", -1)
  168. b2 = strings.Replace(b2, tmp, "", -1)
  169. }
  170. if b1 == b2 {
  171. res = 1 //相等
  172. } else if b1 == "" || b2 == "" {
  173. res = 2 //包含
  174. } else {
  175. res = 3 //不相等
  176. }
  177. return
  178. }