merge_comparepnc.go 3.5 KB

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