comparePNCB.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. package main
  2. import (
  3. "regexp"
  4. "strings"
  5. )
  6. func comparePNCB(info *Info, compareProject *ProjectInfo) (compareStr string, score int) {
  7. retv := 0
  8. if info.ProjectName != "" {
  9. pns := []string{}
  10. if compareProject.ProjectName != "" {
  11. pns = append(pns, compareProject.ProjectName)
  12. }
  13. if len(compareProject.MPN) > 0 {
  14. pns = append(pns, compareProject.MPN...)
  15. }
  16. ifind := 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, info.Buyer)
  24. //if CheckContain(info.ProjectName, v, info.Buyer)
  25. if retv == 3 {
  26. ifind = 1
  27. break
  28. } else if retv == 1 {
  29. ifind = 2
  30. } else if ifind == 0 {
  31. ifind = 3
  32. }
  33. }
  34. }
  35. switch ifind {
  36. case 0:
  37. compareStr = "D"
  38. case 1:
  39. compareStr = "A"
  40. score += 4
  41. if len([]rune(info.ProjectName)) > 19 {
  42. score += 2
  43. }
  44. case 2:
  45. compareStr = "B"
  46. score += 2
  47. if len([]rune(info.ProjectName)) > 19 {
  48. score += 1
  49. }
  50. case 3:
  51. compareStr = "C"
  52. }
  53. } else {
  54. compareStr = "D"
  55. }
  56. PNStr := compareStr
  57. for _, pc := range []string{info.ProjectCode, info.PTC} {
  58. if pc != "" {
  59. pcs := []string{}
  60. if compareProject.ProjectCode != "" {
  61. pcs = append(pcs, compareProject.ProjectCode)
  62. }
  63. if len(compareProject.MPC) > 0 {
  64. pcs = append(pcs, compareProject.MPC...)
  65. }
  66. ifind := 0
  67. for _, v := range pcs {
  68. if pc == v {
  69. ifind = 1
  70. break
  71. } else {
  72. // math.Abs(float64(len([]rune(pc))-len([]rune(v)))) < 6
  73. //if !_numreg1.MatchString(pc) && !_zimureg1.MatchString(pc) && !_numreg1.MatchString(v) && !_zimureg1.MatchString(v)
  74. if (PNStr == "A" || PNStr == "B" || (!_nzreg.MatchString(pc) && !_nzreg.MatchString(v))) && (strings.Contains(pc, v) || strings.Contains(v, pc)) {
  75. t1 := pc
  76. t2 := v
  77. if len(v) > len(pc) {
  78. t1 = v
  79. t2 = pc
  80. }
  81. t3 := strings.Replace(t1, t2, "", -1)
  82. t3 = _datereg.ReplaceAllString(t3, "")
  83. if t3 == "" {
  84. ifind = 1
  85. break
  86. } else if _hanreg.MatchString(t3) || _numreg1.MatchString(t3) {
  87. ifind = 2
  88. } else {
  89. ifind = 3
  90. }
  91. } else if ifind == 0 {
  92. ifind = 3
  93. }
  94. }
  95. }
  96. switch ifind {
  97. case 0:
  98. compareStr += "D"
  99. case 1:
  100. compareStr += "A"
  101. score += 4
  102. if len([]rune(pc)) > 19 {
  103. score += 2
  104. }
  105. case 2:
  106. if compareStr == "C" && retv == 2 {
  107. compareStr += "C"
  108. } else {
  109. compareStr += "B"
  110. score += 2
  111. if len([]rune(pc)) > 19 {
  112. score += 1
  113. }
  114. }
  115. case 3:
  116. compareStr += "C"
  117. }
  118. } else {
  119. compareStr += "D"
  120. }
  121. }
  122. return
  123. }
  124. var _datereg = regexp.MustCompile("20[0-2][0-9][年-][0-9]{1,2}[月-][0-9]{1,2}[日-]([0-9]{1,2}时[0-9]{0,2})?")
  125. var _numreg1 = regexp.MustCompile("^[0-9-]{1,8}$")
  126. var _zimureg1 = regexp.MustCompile("^[a-zA-Z-]{1,7}$")
  127. var _nzreg = regexp.MustCompile("^[0-9a-zA-Z-]+$")
  128. var _hanreg = regexp.MustCompile(`^[\p{Han}::【】\\[\\]()()--、]+$`)
  129. var replaceStr = regexp.MustCompile("(工程|采购|项目|[?!、【】()]|栏标价|中标候选人|招标代理)")
  130. var pStr = regexp.MustCompile("(勘察|监理|施工|设计|验收|标段|分包|子包|[0-9A-Z]包|[一二三四五六七八九十0-9]批)")
  131. func CheckContain(b1, b2, infoBuyer string) (res int) {
  132. b1 = replaceStr.ReplaceAllString(b1, "")
  133. b2 = replaceStr.ReplaceAllString(b2, "")
  134. b1 = strings.Replace(b1, infoBuyer, "", 1)
  135. b2 = strings.Replace(b2, infoBuyer, "", 1)
  136. if b1 == b2 {
  137. res = 3
  138. return
  139. }
  140. bs1 := []rune(b1)
  141. bs2 := []rune(b2)
  142. tmp := ""
  143. for i := 0; i < len(bs1); i++ {
  144. for j := 0; j < len(bs2); j++ {
  145. if bs1[i] == bs2[j] {
  146. tmp += string(bs1[i])
  147. } else if tmp != "" {
  148. b1 = strings.Replace(b1, tmp, "", -1)
  149. b2 = strings.Replace(b2, tmp, "", -1)
  150. tmp = ""
  151. }
  152. }
  153. }
  154. if tmp != "" {
  155. b1 = strings.Replace(b1, tmp, "", -1)
  156. b2 = strings.Replace(b2, tmp, "", -1)
  157. }
  158. if b1 == b2 {
  159. res = 3
  160. } else if (b1 == "" && !pStr.MatchString(b2)) || (b2 == "" && !pStr.MatchString(b1)) {
  161. res = 1
  162. } else {
  163. res = 2
  164. }
  165. return
  166. }