merge_comparepnc.go 3.8 KB

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