merge_comparepncb.go 3.7 KB

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