merge_comparepnc.go 4.0 KB

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