division.go 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  1. package pretreated
  2. import (
  3. "fmt"
  4. "jy/clear"
  5. "jy/util"
  6. qutil "qfw/util"
  7. "regexp"
  8. "sort"
  9. "strconv"
  10. "strings"
  11. "unicode/utf8"
  12. )
  13. //分块、分段功能
  14. var (
  15. /*regSerialTitles = []string{
  16. "([一二三四五六七八九十]+)[\u3000\u2003\u00a0\\s]*[、..::,](.*)",
  17. "[((]([一二三四五六七八九十]+)[))][\u3000\u2003\u00a0\\s]*[、..::]?(.*)",
  18. "(\\d+)[\u3000\u2003\u00a0\\s]*、(.*)",
  19. "(\\d+)[\u3000\u2003\u00a0\\s]*[..]([^\\d][^\r\n]+)",
  20. "(\\d+)[\u3000\u2003\u00a0\\s]+([^\\d][^\r\n]+)",
  21. "1[..](\\d+)[\u3000\u2003\u00a0\\s]+([^\\d..][^\r\n]+)",
  22. }*/
  23. regSerialTitles_1 = []*regexp.Regexp{
  24. regexp.MustCompile("([\r\n][\u3000\u2003\u00a0\\s]*|^[\u3000\u2003\u00a0\\s]*)([一二三四五六七八九十]+)[\u3000\u2003\u00a0\\s]*[、..::,](.*)"),
  25. regexp.MustCompile("([\r\n][\u3000\u2003\u00a0\\s]*|^[\u3000\u2003\u00a0\\s]*)[((]([一二三四五六七八九十]+)[))][\u3000\u2003\u00a0\\s]*[、..::]?(.*)"),
  26. regexp.MustCompile("([\r\n][\u3000\u2003\u00a0\\s]*|^[\u3000\u2003\u00a0\\s]*)(\\d+)[\u3000\u2003\u00a0\\s]*、(.*)"),
  27. regexp.MustCompile("([\r\n][\u3000\u2003\u00a0\\s]*|^[\u3000\u2003\u00a0\\s]*)(\\d+)[\u3000\u2003\u00a0\\s]*[..]([^\\d][^\r\n]+)"),
  28. regexp.MustCompile("([\r\n][\u3000\u2003\u00a0\\s]*|^[\u3000\u2003\u00a0\\s]*)(\\d+)[\u3000\u2003\u00a0\\s]+([^\\d][^\r\n]+)"),
  29. regexp.MustCompile("([\r\n][\u3000\u2003\u00a0\\s]*|^[\u3000\u2003\u00a0\\s]*)1[..](\\d+)[\u3000\u2003\u00a0\\s]+([^\\d..][^\r\n]+)"),
  30. regexp.MustCompile("([\r\n][\u3000\u2003\u00a0\\s(]*|^[\u3000\u2003\u00a0\\s(]*)(\\d+)[\u3000\u2003\u00a0\\s)]+([^\r\n]+)"),
  31. }
  32. regSerialTitles_2 = []*regexp.Regexp{
  33. regexp.MustCompile("^([一二三四五六七八九十]+)[\u3000\u2003\u00a0\\s]*[、..::,](.*)$"),
  34. regexp.MustCompile("^[((]([一二三四五六七八九十]+)[))][\u3000\u2003\u00a0\\s]*[、..::]?(.*)$"),
  35. regexp.MustCompile("^(\\d+)[\u3000\u2003\u00a0\\s]*、(.*)$"),
  36. regexp.MustCompile("^(\\d+)[\u3000\u2003\u00a0\\s]*[..]([^\\d][^\r\n]+)$"),
  37. regexp.MustCompile("^(\\d+)[\u3000\u2003\u00a0\\s]+([^\\d][^\r\n]+)$"),
  38. regexp.MustCompile("^1[..](\\d+)[\u3000\u2003\u00a0\\s]+([^\\d..][^\r\n]+)$"),
  39. regexp.MustCompile("^[(](\\d+)[\u3000\u2003\u00a0\\s)]+([^\r\n]+)$"),
  40. }
  41. regReplAllTd = regexp.MustCompile("(?smi)<td.*?>.+?</td>")
  42. regIsNumber = regexp.MustCompile("^\\d+$")
  43. regIsChineseNumber = regexp.MustCompile("^[一二三四五六七八九十]+$")
  44. regReplAllSpace = regexp.MustCompile("[\u3000\u2003\u00a0\\s]+")
  45. regTrimSpace = regexp.MustCompile("^[\u3000\u2003\u00a0\\s]+|[\u3000\u2003\u00a0\\s]+$")
  46. regReplWrapSpace = regexp.MustCompile("^[\r\n][\u3000\u2003\u00a0\\s]*|[\r\n][\u3000\u2003\u00a0\\s]*$")
  47. regReplAllSymbol = regexp.MustCompile("[(\\(<《【\\[{{〔)\\)>》】\\]}}〕,,;;::'\"“”。.\\??/+=\\-_——*&……\\^%$¥@#!!`~·]")
  48. regFilterTitle = regexp.MustCompile("[(\\(<《【\\[{{〔].+?[)\\)>》】\\]}}〕]")
  49. regDivision = regexp.MustCompile("[::]")
  50. regSpliteSegment = regexp.MustCompile("[\r\n]")
  51. regFilterNumber = regexp.MustCompile("^[\\d一二三四五六七八九十]+")
  52. regSplit = regexp.MustCompile("或|和|以?及|与|、|或")
  53. regStartWrap = regexp.MustCompile("^[\r\n]")
  54. regEndWrap = regexp.MustCompile("[\r\n]$")
  55. regMoreWrap = regexp.MustCompile("[\r\n]{2,}")
  56. regStrWrap = regexp.MustCompile("分包名称[::]")
  57. regBZJWarap = regexp.MustCompile("(每标段|保证金.*|标示|标[\\d一二三四五六七八九十]+室|型号[::]+[\\d]*包|每包[0-9]*元|包/[袋|箱]|标志|享受一包服务|一包一投|上包|标线|国标|第[\\d一二三四五六七八九十]+标室|[\\d一二三四五六七八九十]包密封|(^一包|商务|资格|价格标(每包内含相应文件正副本))|[未|不]+划分标段)")
  58. regFJWarap = regexp.MustCompile("[a-zA-Z0-9](包|标段).*.(pdf|PDF|docx|doc|DOCX|DOC|swf|SWF)")
  59. regAZWarap = regexp.MustCompile("(标[a-zA-Z]取值|标段划分|标液|分包个数|物资[\\d一二三四五六七八九十]?包|[x]*项目[x]*标段|张\\/包|纸[\\d]*包|\\*[\\d]+包|相机包)")
  60. replSerial = regexp.MustCompile("(\r\n|^)([\\d一二三四五六七八九十][、..::,])+\\d")
  61. moreColonReg = regexp.MustCompile("[::]+")
  62. regFilter = regexp.MustCompile("等$")
  63. pkgFilter = regexp.MustCompile("第[一二三四五六七八九十0-9A-Za-zⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ](子|合同|分|施工|监理)?(标段?|包|合同段|标包)|(子|合同|分|施工|监理)?[标|包]+[段|号]+")
  64. indexTile = regexp.MustCompile(`[0-9.]{2,3}[^包标段][\s\\u4e00-\\u9fa5]{2,8}[::]+`) //小标题
  65. indexTile2 = regexp.MustCompile(`[\s\\u4e00-\\u9fa5]{2,8}[::]\n`)
  66. regReplAllSpace2 = regexp.MustCompile("[\u3000\u2003\u00a0\\s0-9.::、\\(\\)]+")
  67. confusion = map[string]string{
  68. "参与": "canyu",
  69. }
  70. //查找分包之前,先对内容进行预处理
  71. /*
  72. 第一包:采购设备清单
  73. <table></table>
  74. */
  75. regPackageFilter = regexp.MustCompile("([第]?([一二三四五六七八九十0-9A-Za-zⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ]+)((子|合同|分|施工|监理)?(标段?|包|合同段|标包))|((子|合同|分|施工|监理)?(标|包)(段|号)?)[  \u3000\u2003\u00a0]*([一二三四五六七八九十0-9A-Za-zⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ]+)).+[\r\n]?<table>")
  76. filterPkgTitleKey = regexp.MustCompile("结果[::]?$")
  77. xuhao = map[string]bool{
  78. "19968_12289": true,
  79. "19968_46": true,
  80. "20108_12289": true,
  81. "20108_46": true,
  82. "19977_12289": true,
  83. "19977_46": true,
  84. "22235_12289": true,
  85. "22235_46": true,
  86. "20116_12289": true,
  87. "20116_46": true,
  88. "20845_12289": true,
  89. "20845_46": true,
  90. "19971_12289": true,
  91. "19971_46": true,
  92. "20843_12289": true,
  93. "20061_46": true,
  94. }
  95. //非分包中标单位值
  96. unPackageWinnerReg = regexp.MustCompile("(重新招标|方案包)")
  97. conformWinnerKVReg = regexp.MustCompile("^(中标人|中标银行|第一名)[::](.{4,20}(分行|公司))")
  98. conformWinnerKVReg1 = regexp.MustCompile("^[-].{4,15}公司$")
  99. conformWinnerKVReg2 = regexp.MustCompile("(.*)?确定(.*公司)为中标人(.*)?")
  100. conformWinnerTextReg3 = regexp.MustCompile("拟定供应商信息[::\\s]+名称[::](.*)[\\s]+地址")
  101. conformWinnerTextReg4 = regexp.MustCompile("拟定供应商信息[::\\s]+名称[::](.*)[\\s]+地址")
  102. /*
  103. 拟定供应商信息:
  104. 名称:郑州人民广播电台
  105. 地址:郑州市金水区内环路17号A座。
  106. */
  107. //针对处理-替换敏感词
  108. packageReg1 = regexp.MustCompile("(包件[一二三四五1-9][::].*)\n1[、.\\s]+名称[::](.*)\n2[、.\\s]+")
  109. packageReg2 = regexp.MustCompile("标段[((]包[))][\\[][O0]+([1-9一二三四五六七八九])[\\]]")
  110. //标段(包)[001]巴盟神舟30MW:
  111. )
  112. //分块
  113. func DivideBlock(tp, content string, from int, ruleBlock *util.RuleBlock, isSite bool, codeSite string) ([]*util.Block, int) {
  114. defer qutil.Catch()
  115. returnValue := 0
  116. var blocks []*util.Block
  117. if strings.TrimSpace(content) == "" || codeSite == "a_zgyc_ztbxx" {
  118. return blocks, -1
  119. }
  120. //table里面的内容不考虑,先把table清理掉
  121. //contentTemp := regReplAllTd.ReplaceAllString(content, "")
  122. contentTemp := TextAfterRemoveTable(content)
  123. tdIndexs := regReplAllTd.FindAllStringSubmatchIndex(content, -1)
  124. var regContenSerialTitle *regexp.Regexp
  125. var regSerialTitleIndex int
  126. if ruleBlock != nil && len(ruleBlock.BlockRegs) > 0 {
  127. regContenSerialTitle, regSerialTitleIndex = getSerialType(contentTemp, ruleBlock.BlockRegs)
  128. } else {
  129. regContenSerialTitle, regSerialTitleIndex = getSerialType(contentTemp, regSerialTitles_1)
  130. }
  131. //没有分块
  132. if regSerialTitleIndex == -1 {
  133. if len(contentTemp) == len(content) {
  134. //没有分块
  135. return blocks, -1
  136. } else { //有table
  137. return blocks, -2
  138. }
  139. }
  140. //匹配序号和标题
  141. var regSerialTitle *regexp.Regexp
  142. if ruleBlock != nil && len(ruleBlock.TitleRegs) > 0 {
  143. regSerialTitle = ruleBlock.TitleRegs[regSerialTitleIndex]
  144. } else {
  145. regSerialTitle = regSerialTitles_2[regSerialTitleIndex]
  146. }
  147. indexs := regContenSerialTitle.FindAllStringIndex(content, -1)
  148. indexs = filterSerial(content, indexs, tdIndexs)
  149. //头块
  150. var headBlock, endBlock *util.Block
  151. currentIndex := 0
  152. for k, v := range indexs {
  153. start, end := v[0], v[1]
  154. //添加开头部分
  155. if k == 0 {
  156. if headTemp := content[:start]; regReplAllSpace.ReplaceAllString(headTemp, "") != "" {
  157. headBlock = &util.Block{
  158. Index: -1, //序号
  159. Text: headTemp, //内容
  160. Title: "", //标题
  161. Start: 0,
  162. End: start,
  163. }
  164. }
  165. }
  166. //分块
  167. blockSerialTitle := regTrimSpace.ReplaceAllString(content[start:end], "")
  168. serialTitles := regSerialTitle.FindStringSubmatch(blockSerialTitle) //序号和标题
  169. if len(serialTitles) < 3 {
  170. continue
  171. }
  172. indexSting := regReplAllSpace.ReplaceAllString(serialTitles[1], "") //序号
  173. index := 0
  174. //转成数字序号
  175. if regIsNumber.MatchString(indexSting) {
  176. index, _ = strconv.Atoi(indexSting)
  177. } else if regIsChineseNumber.MatchString(indexSting) {
  178. index = util.ChineseNumberToInt(indexSting)
  179. }
  180. //序号开始就是错误的
  181. if k+1 != index {
  182. if k == 0 {
  183. returnValue = 3
  184. break
  185. } else {
  186. if currentIndex+1 != index {
  187. //如果序号不是连续的,不往下走
  188. returnValue = 2
  189. //添加结尾部分
  190. if from != 3 {
  191. endBlock = &util.Block{
  192. Index: -2, //序号
  193. Text: content[start:], //内容
  194. Title: "", //标题
  195. Start: start,
  196. End: len(content),
  197. }
  198. break
  199. }
  200. }
  201. }
  202. currentIndex = index
  203. }
  204. //
  205. title := serialTitles[2] //标题
  206. title = regTrimSpace.ReplaceAllString(title, "") //清除前后空格
  207. //分块后的块文
  208. nextStart := len(content)
  209. if k < len(indexs)-1 {
  210. nextStart = indexs[k+1][0]
  211. }
  212. //获取块中除了序号和标题的内容
  213. blockText := regTrimSpace.ReplaceAllString(content[end:nextStart], "")
  214. if title != "" {
  215. blockTextTemp := regReplAllSpace.ReplaceAllString(blockText, "")
  216. //特殊情况处理
  217. if blockTextTemp == "" {
  218. if regDivision.MatchString(title) {
  219. /*
  220. 一、项目编号:HMEC170223
  221. 二、项目名称:执法记录仪采购
  222. */
  223. blockText = title
  224. divisionIndexs := regDivision.FindStringIndex(title)
  225. title = title[:divisionIndexs[0]]
  226. } else {
  227. /*
  228. 十一、投标代表须持本人身份证原件亲自递交投标文件,代理机构项目经理审核通过后,办理签收手续,否则投标文件被拒收。
  229. 十二、开标时间:2017年3月20日9时30分
  230. */
  231. blockText = title
  232. title = ""
  233. }
  234. } else if blockTextTemp != "" && regDivision.MatchString(title) {
  235. /*
  236. 2、采购单位名称:福建省汀州医院
  237. 采购单位地址: 龙岩市长汀县
  238. 联系人:胡科长
  239. 联系方式:0597-6826353
  240. */
  241. //多个标题
  242. divisionIndexs := regDivision.FindStringIndex(title)
  243. titleBefore := regReplAllSpace.ReplaceAllString(title[:divisionIndexs[0]], "")
  244. titleAfter := regReplAllSpace.ReplaceAllString(title[divisionIndexs[1]:], "")
  245. blockText = title + "\n" + blockText
  246. if titleAfter != "" {
  247. title = ""
  248. } else {
  249. title = titleBefore
  250. }
  251. } else {
  252. blockText = title + "\n" + blockText
  253. }
  254. }
  255. //没有内容的块,不打标签,不分段
  256. if blockText == "" {
  257. continue
  258. }
  259. //过滤
  260. if regexp.MustCompile("投标文件格式|业绩").MatchString(title) &&
  261. !regexp.MustCompile("拟定的唯一供应商名称").MatchString(title){
  262. continue
  263. }
  264. blockText = hasMergeKV(title, blockText)
  265. //
  266. titleIsExists := map[string]bool{} //去重
  267. title = filterTitle(title)
  268. //分割标题 [和及]。。。 参与
  269. splitTitles := ProcTitle(title)
  270. blockText = mergetext(splitTitles, blockText)
  271. block := &util.Block{
  272. Index: index, //序号
  273. Text: blockText, //内容
  274. Title: title, //标题
  275. Titles: splitTitles,
  276. Start: start,
  277. End: nextStart,
  278. }
  279. titles := []string{}
  280. for _, sv := range splitTitles {
  281. if sv == "" || titleIsExists[sv] {
  282. continue
  283. }
  284. titleIsExists[sv] = true
  285. //标题过短过长不打标签
  286. if len([]rune(sv)) >= 2 && len([]rune(sv)) <= 10 {
  287. //打标签
  288. block.Tags = append(block.Tags, util.GetBlockTags(sv))
  289. titles = append(titles, sv)
  290. }
  291. }
  292. block.Title = title
  293. block.Titles = titles
  294. if ruleBlock != nil {
  295. block.Classify, block.NotClassifyTitles = ruleBlock.Classify.GetClassify(tp, titles)
  296. }
  297. tagsToBlocks(blocks, block)
  298. //log.Println(index, sv, splitTitles)
  299. //log.Println(blockText)
  300. blocks = append(blocks, block)
  301. }
  302. var returnBlocks []*util.Block
  303. if len(blocks) > 0 {
  304. //头
  305. if headBlock != nil {
  306. if tp == "招标" {
  307. headBlock.Classify = map[string]bool{"bidcondition": true}
  308. }
  309. returnBlocks = append(returnBlocks, headBlock)
  310. }
  311. //中间块
  312. returnBlocks = append(returnBlocks, blocks...)
  313. //尾
  314. if endBlock != nil {
  315. returnBlocks = append(returnBlocks, endBlock)
  316. }
  317. if returnValue == 0 {
  318. returnValue = 1
  319. }
  320. }
  321. contactFormat := &util.ContactFormat{
  322. IndexMap: map[int]string{},
  323. MatchMap: map[string]map[string]bool{},
  324. }
  325. for _, bl := range returnBlocks {
  326. //解析kv
  327. newText := TextAfterRemoveTable(bl.Text) //取出纯文本
  328. bl.ColonKV = GetKVAll(newText, bl.Title, contactFormat, from, isSite, codeSite)
  329. bl.SpaceKV = SspacekvEntity.Entrance(newText, bl.Title, contactFormat, isSite, codeSite)
  330. //正则抽取的时候有时需要匹配换行或者句号,这里在解析完kv之后,在块结尾添加换行和句号
  331. bl.Text = appendWarpStop(bl.Text)
  332. }
  333. return returnBlocks, returnValue
  334. }
  335. func mergetext(titles []string, text string) string {
  336. if len(titles) == 0 || utf8.RuneCountInString(text) > 150 {
  337. return text
  338. }
  339. splitLenstrs := strings.Split(text, "\n")
  340. if len(splitLenstrs) == 1 || len(titles) != len(splitLenstrs)-1 {
  341. return text
  342. }
  343. tt := ""
  344. for i, v := range splitLenstrs[1:] {
  345. lentexts := regDivision.Split(v, -1)
  346. if len(lentexts) == 2 {
  347. if strings.Contains(titles[i], lentexts[0]) {
  348. tt += titles[i] + ":" + lentexts[1] + "\n"
  349. }else if strings.Contains(titles[i], lentexts[0]) ||strings.Contains(titles[i], lentexts[0]){
  350. tt += titles[i] + ":" + lentexts[1] + "\n"
  351. }
  352. }else {
  353. //特殊处理
  354. if strings.Contains(v,"中标人 ") {
  355. tt +=v+"\n"
  356. }
  357. }
  358. }
  359. if len(tt) == 0 {
  360. return text
  361. } else {
  362. return tt
  363. }
  364. }
  365. //块标题处理
  366. func ProcTitle(title string) []string {
  367. if title == "" {
  368. return []string{}
  369. }
  370. for k, v := range confusion {
  371. title = strings.Replace(title, k, v, -1)
  372. }
  373. direct := 1
  374. prev := ""
  375. ara := regSplit.Split(title, -1)
  376. for kk, vv := range ara {
  377. for kkk, vvv := range confusion {
  378. vv = strings.Replace(vv, vvv, kkk, -1)
  379. }
  380. ara[kk] = vv
  381. if len([]rune(vv)) == 2 {
  382. if kk == 0 {
  383. direct = -1
  384. } else {
  385. start := ""
  386. if len([]rune(prev)) > 3 {
  387. start = string([]rune(prev)[:len([]rune(prev))-2])
  388. }
  389. ara[kk] = start + vv
  390. }
  391. } else if vv == "联系人" || vv == "联系方式" {
  392. if strings.Contains(prev, "代理") {
  393. ara[kk] = "代理机构" + vv
  394. } else if strings.Contains(prev, "中标") {
  395. ara[kk] = "中标单位" + vv
  396. } else if strings.Contains(prev, "采购") {
  397. ara[kk] = "采购单位" + vv
  398. }
  399. }
  400. if len([]rune(vv)) > 3 {
  401. if direct == -1 {
  402. end := string([]rune(vv)[len([]rune(vv))-2:])
  403. for i := 0; i < kk; i++ {
  404. ara[i] = ara[i] + end
  405. }
  406. break
  407. }
  408. prev = vv
  409. }
  410. }
  411. return ara
  412. }
  413. //有合并kv的 例如项目名称及编号
  414. func hasMergeKV(title, text string) string {
  415. title = regDivision.ReplaceAllString(title, "")
  416. titles := regSplit.Split(title, -1)
  417. if len(titles) <= 1 {
  418. return text
  419. }
  420. before := titles[0]
  421. after := titles[1]
  422. if strings.Contains(title, "项目") && len([]rune(after)) == 2 {
  423. after = "项目" + after
  424. } else {
  425. return text
  426. }
  427. if strings.Count(text, "\n") != 1 {
  428. return text
  429. }
  430. texts := strings.Split(text, "\n")
  431. textOneLine := texts[0]
  432. textTwoLine := texts[1]
  433. if regDivision.MatchString(textTwoLine) {
  434. return text
  435. }
  436. if textTwoLine := strings.SplitN(textTwoLine, ",", 2); len(textTwoLine) == 2 {
  437. text = textOneLine + "\n" + before + ":" + textTwoLine[0] + "," + after + ":" + textTwoLine[1]
  438. }
  439. return text
  440. }
  441. //过滤序号,判断序号是不是在td里,如果是的话这个序号作废
  442. func filterSerial(content string, indexs, tdIndexs [][]int) [][]int {
  443. returnIndexs := [][]int{}
  444. for _, v := range indexs {
  445. flag := false
  446. //根据序号的开始位置,判断是不是在td里面
  447. for _, tv := range tdIndexs {
  448. if v[0] > tv[0] && v[0] < tv[1] {
  449. flag = true
  450. continue
  451. }
  452. }
  453. if flag {
  454. continue
  455. }
  456. returnIndexs = append(returnIndexs, []int{v[0], v[1]})
  457. }
  458. return returnIndexs
  459. }
  460. //获取正文所用的序号类型
  461. func getSerialType(content string, blockRegs []*regexp.Regexp) (*regexp.Regexp, int) {
  462. var regContenSerialTitle *regexp.Regexp
  463. //先判断文章最外层使用的是哪种序号
  464. contentStartIndex, regSerialTitleIndex := -1, -1
  465. for k, v := range blockRegs {
  466. indexs := v.FindStringIndex(content)
  467. //只用最外层的序号,里面的过滤掉
  468. if len(indexs) == 2 && !strings.Contains(content,"中标候选人排序") && !regSpliteSegment.MatchString(strings.TrimSpace(content[indexs[0]:indexs[1]])) && (contentStartIndex == -1 || indexs[0] < contentStartIndex) {
  469. regSerialTitleIndex = k
  470. contentStartIndex = indexs[0]
  471. regContenSerialTitle = v
  472. }
  473. }
  474. return regContenSerialTitle, regSerialTitleIndex
  475. }
  476. //添加换行和句号
  477. func appendWarpStop(text string) string {
  478. //清理前后空格
  479. text = regTrimSpace.ReplaceAllString(text, "")
  480. //添加句号
  481. if !strings.HasSuffix(text, "。") {
  482. text += "。"
  483. }
  484. //添加换行
  485. if !regEndWrap.MatchString(text) {
  486. text += "\n"
  487. }
  488. return text
  489. }
  490. //分段
  491. func DivideSegmentHtml(txt string) []*util.Segment {
  492. //先分段
  493. _segs := strings.FieldsFunc(txt, func(r rune) bool {
  494. return r == 10 || r == 13
  495. })
  496. //再去除空行
  497. segs := make([]*util.Segment, 0)
  498. _index := 0
  499. for _, seg := range _segs {
  500. if seg != " " && len(seg) > 1 {
  501. _seg := util.Segment{}
  502. _index = _index + 1
  503. _seg.Index = _index
  504. _seg.Text = seg
  505. segs = append(segs, &_seg)
  506. }
  507. }
  508. return segs
  509. }
  510. //分段
  511. func DivideSegment(txt string) []*util.Segment {
  512. //先分段
  513. tmpstr := ""
  514. _segs := strings.FieldsFunc(txt, func(r rune) bool {
  515. if r == 19968 || r == 20108 || r == 19977 || r == 12289 || r == 46 ||
  516. r == 22235 || r == 20116 || r == 20845 || r == 19971 || r == 20843 || r == 20061 {
  517. if tmpstr == "" {
  518. tmpstr += fmt.Sprint(r)
  519. return false
  520. } else if strings.Contains(tmpstr, "_") {
  521. tmpstr = ""
  522. tmpstr += fmt.Sprint(r)
  523. return false
  524. } else if tmpstr == fmt.Sprint(r) {
  525. if r == 46 || r == 12289 {
  526. tmpstr = ""
  527. }
  528. return false
  529. }
  530. tmpstr += "_" + fmt.Sprint(r)
  531. if xuhao[tmpstr] {
  532. return true
  533. }
  534. }
  535. tmpstr = ""
  536. return r == 10 || r == 13
  537. })
  538. //再去除空行
  539. segs := make([]*util.Segment, 0)
  540. _index := 0
  541. for _, seg := range _segs {
  542. if seg != " " && len(seg) > 1 {
  543. _seg := util.Segment{}
  544. _index = _index + 1
  545. _seg.Index = _index
  546. _seg.Text = seg
  547. segs = append(segs, &_seg)
  548. }
  549. }
  550. return segs
  551. }
  552. /** 给块打标签 **/
  553. func tagsToBlocks(blocks []*util.Block, block *util.Block) {
  554. if len(block.Tags) == 0 {
  555. return
  556. }
  557. tag := map[string]bool{}
  558. tagWeight := map[string]int{}
  559. for _, v := range block.Tags {
  560. for _, ts := range v {
  561. tag[ts.Value] = true
  562. tagWeight[ts.Value] = ts.Weight
  563. }
  564. }
  565. for v, _ := range tag {
  566. for _, block := range blocks {
  567. if block.Tag[v] {
  568. for _, blockTags := range block.Tags {
  569. for _, ts := range blockTags {
  570. if ts.Value == v && ts.Weight < tagWeight[v] {
  571. block.Tag[v] = false
  572. }
  573. }
  574. }
  575. }
  576. }
  577. }
  578. block.Tag = tag
  579. }
  580. func filterTitle(title string) string {
  581. if strings.Contains(title, ",") && strings.Contains(title, "。") {
  582. return ""
  583. }
  584. if len([]rune(title)) > 30 {
  585. return ""
  586. }
  587. //清理空格
  588. title = regReplAllSpace.ReplaceAllString(title, "")
  589. //清理成对出现的符号中的内容
  590. title = regFilterTitle.ReplaceAllString(title, "")
  591. //清理特殊符号
  592. title = regReplAllSymbol.ReplaceAllString(title, "")
  593. //清理序号
  594. title = regFilterNumber.ReplaceAllString(title, "")
  595. title = regFilter.ReplaceAllString(title, "")
  596. return title
  597. }
  598. //从块里面找分包
  599. func FindPackageFromBlocks(blocks *[]*util.Block, isSite bool, codeSite string) (blockPackage map[string]*util.BlockPackage) {
  600. blockPackage = map[string]*util.BlockPackage{}
  601. //块分包
  602. for _, v := range *blocks {
  603. text := regPackageFilter.ReplaceAllString(v.Text, "<table>")
  604. text = TextAfterRemoveTable(text)
  605. if text == "" {
  606. continue
  607. }
  608. //var ok bool
  609. //var surplusText string
  610. //分析分包-金额,中标单位,人电话,包名,中标后选人
  611. divisionPackageChild(&blockPackage, text, v.Title, true, v.Tag["中标单位"], isSite, codeSite)
  612. }
  613. //orderwinner := winnerOrderEntity.Find(content, true, 2, isSite, codeSite)
  614. for k, v := range blockPackage {
  615. findWinnerBugetBidmountByKv(v, blockPackage, k) //根据kv-find字段
  616. }
  617. return
  618. }
  619. func findWinnerBugetBidmountByKv(v *util.BlockPackage, blockPackage map[string]*util.BlockPackage, k string) {
  620. if v.ColonKV != nil && v.ColonKV.KvTags != nil {
  621. for kc, cv := range v.ColonKV.KvTags {
  622. if kc == "预算" && v.Budget <= 0 {
  623. moneys := clear.ObjToMoney([]interface{}{cv[0].Value, ""})
  624. if len(moneys) > 0 {
  625. if vf, ok := moneys[0].(float64); ok {
  626. blockPackage[k].Budget = vf
  627. blockPackage[k].IsTrueBudget = moneys[len(moneys)-1].(bool)
  628. } else if vi, ok := moneys[0].(int); ok {
  629. blockPackage[k].Budget = float64(vi)
  630. blockPackage[k].IsTrueBudget = moneys[len(moneys)-1].(bool)
  631. }
  632. }
  633. } else if (kc == "中标金额"||kc=="各包中标/成交候选供应商及报价") && v.Bidamount <= 0 {
  634. moneys := clear.ObjToMoney([]interface{}{cv[0].Value, ""})
  635. if len(moneys) > 0 {
  636. if vf, ok := moneys[0].(float64); ok {
  637. blockPackage[k].Bidamount = vf
  638. blockPackage[k].IsTrueBidamount = moneys[len(moneys)-1].(bool)
  639. } else if vi, ok := moneys[0].(int); ok {
  640. blockPackage[k].Bidamount = float64(vi)
  641. blockPackage[k].IsTrueBidamount = moneys[len(moneys)-1].(bool)
  642. }
  643. }
  644. } else if (kc == "中标单位"||kc=="第1 名"||kc=="各包中标/成交候选供应商及报价") && v.Winner == "" {
  645. if !unPackageWinnerReg.MatchString(cv[0].Value) {
  646. isW:=false
  647. if len(cv)>1 {
  648. for _,v_cv :=range cv{
  649. if v_cv.Key=="中标单位" && v_cv.Value!="" {
  650. isW = true
  651. blockPackage[k].Winner = v_cv.Value
  652. break
  653. }
  654. }
  655. }
  656. if !isW {
  657. blockPackage[k].Winner = cv[0].Value
  658. }
  659. }
  660. }else { //特殊情况-特殊处理
  661. res := conformWinnerKVReg.FindAllStringSubmatch(cv[0].Value, -1)
  662. if len(res) > 0 {
  663. text := res[0][2]
  664. if text!="" {
  665. blockPackage[k].Winner = text
  666. continue
  667. }
  668. }
  669. if kc=="中标信息" && conformWinnerKVReg1.MatchString(cv[0].Value){
  670. blockPackage[k].Winner = cv[0].Value
  671. continue
  672. }
  673. if conformWinnerKVReg2.MatchString(cv[0].Value) {
  674. blockPackage[k].Winner = conformWinnerKVReg2.ReplaceAllString(cv[0].Value,"${2}")
  675. continue
  676. }
  677. //全文找
  678. res = conformWinnerTextReg3.FindAllStringSubmatch(v.Text, -1)
  679. if len(res) > 0 {
  680. text := res[0][1]
  681. if text!="" {
  682. blockPackage[k].Winner = text
  683. continue
  684. }
  685. }
  686. }
  687. }
  688. }
  689. if v.SpaceKV != nil && v.SpaceKV.KvTags != nil {
  690. for kc, cv := range v.SpaceKV.KvTags {
  691. if kc == "预算" && v.Budget <= 0 {
  692. moneys := clear.ObjToMoney([]interface{}{cv[0].Value, ""})
  693. if len(moneys) > 0 {
  694. if vf, ok := moneys[0].(float64); ok {
  695. blockPackage[k].Budget = vf
  696. blockPackage[k].IsTrueBudget = moneys[len(moneys)-1].(bool)
  697. } else if vi, ok := moneys[0].(int); ok {
  698. blockPackage[k].Budget = float64(vi)
  699. blockPackage[k].IsTrueBudget = moneys[len(moneys)-1].(bool)
  700. }
  701. }
  702. } else if kc == "中标金额" && v.Bidamount <= 0 {
  703. moneys := clear.ObjToMoney([]interface{}{cv[0].Value, ""})
  704. if len(moneys) > 0 {
  705. if vf, ok := moneys[0].(float64); ok {
  706. blockPackage[k].Bidamount = vf
  707. blockPackage[k].IsTrueBidamount = moneys[len(moneys)-1].(bool)
  708. } else if vi, ok := moneys[0].(int); ok {
  709. blockPackage[k].Bidamount = float64(vi)
  710. blockPackage[k].IsTrueBidamount = moneys[len(moneys)-1].(bool)
  711. }
  712. }
  713. } else if kc == "中标单位" && v.Winner == "" {
  714. blockPackage[k].Winner = cv[0].Value
  715. }
  716. }
  717. }
  718. }
  719. //从正文里面找分包
  720. func FindPackageFromText(title string, content string, isSite bool, codeSite string) (blockPackage map[string]*util.BlockPackage) {
  721. blockPackage = map[string]*util.BlockPackage{}
  722. //从正文里面找分包
  723. divisionPackageChild(&blockPackage, content, title, true, false, isSite, codeSite)
  724. for k, v := range blockPackage {
  725. findWinnerBugetBidmountByKv(v, blockPackage, k)
  726. }
  727. //winnerOrderEntity.Find(content, true, 2, isSite, codeSite)
  728. return
  729. }
  730. //分块之后分包
  731. func divisionPackageChild(blockPackage *map[string]*util.BlockPackage, content, title string, isFindWinnerOrder, accuracy bool, isSite bool, codeSite string) (bool, string) {
  732. //查找知否有分包
  733. content = regFJWarap.ReplaceAllString(content, "\n")
  734. content = regAZWarap.ReplaceAllString(content, "\n")
  735. content = regStrWrap.ReplaceAllString(content, "\n")
  736. content = regMoreWrap.ReplaceAllString(content, "\n")
  737. content = regEndWrap.ReplaceAllString(content, "")
  738. content = regBZJWarap.ReplaceAllString(content, "")
  739. //替换敏感词
  740. content = packageReg1.ReplaceAllString(content,"${1}\n中标单位:${2}\n")
  741. content = packageReg2.ReplaceAllString(content,"\n标段${1}:")
  742. con, pkg, flag := CheckMultiPackage(content, title) //找pkg分包包名
  743. if !flag {
  744. return false, ""
  745. }
  746. // util.Debug(con)
  747. // util.Debug(pkg)
  748. //分包前面添加换行
  749. appendWarpIndex := []int{} //分包名,正文下标位置: 1000长 300下标
  750. for _, v := range pkg {
  751. //如果文本内容以识别出来的分包标识结尾,不是分包
  752. if len(pkg) == 1 && strings.HasSuffix(con, v[0]) {
  753. return false, ""
  754. }
  755. is := regexp.MustCompile(v[0]+"[::]*").FindAllStringIndex(con, -1)
  756. for _, sv := range is {
  757. appendWarpIndex = append(appendWarpIndex, sv[0])
  758. }
  759. }
  760. appendWarpIndex = getPkgIndex(appendWarpIndex)
  761. conTemp := ""
  762. for k, v := range appendWarpIndex {
  763. if k == 0 {
  764. conTemp += con[:v] + "\n"
  765. } else {
  766. conTemp += "\n" + con[appendWarpIndex[k-1]:v]
  767. }
  768. if k == len(appendWarpIndex)-1 {
  769. conTemp += "\n" + con[v:]
  770. }
  771. }
  772. con = conTemp
  773. con = replSerial.ReplaceAllString(con, "\n")
  774. con = regMoreWrap.ReplaceAllString(con, "\n")
  775. //根据分包,找索引位置
  776. indexMap := map[int]int{}
  777. indexKeyStringMap := map[int]string{}
  778. indexKeyIntMap := map[int]int{}
  779. indexs := []int{}
  780. startEndMap := map[int]int{}
  781. pkgIndexMap := map[string][]int{}
  782. indexPkgMap := map[int]string{}
  783. //小标题
  784. titleindexs := indexTile.FindAllStringIndex(con, -1)
  785. if len(titleindexs) == 0 {
  786. titleindexs = indexTile2.FindAllStringIndex(con, -1)
  787. }
  788. //遍历分包,把kv在包前面的移动到包后面
  789. for _, v := range pkg {
  790. pgflag := v[0] + "[::]*"
  791. is := regexp.MustCompile(pgflag).FindAllStringIndex(con, -1)
  792. for _, sv := range is {
  793. indexMap[sv[0]] = sv[1]
  794. indexs = append(indexs, sv[0])
  795. pkgIndexMap[v[0]] = append(pkgIndexMap[v[0]], sv[0])
  796. indexPkgMap[sv[0]] = v[0]
  797. }
  798. //key在包前面,并且在一行的开头
  799. keys := regexp.MustCompile("([\r\n]|^)([\u4e00-\u9fa5]{2,30}?([((].{1,8}?[))])?[::\\s\u3000\u2003\u00a0]+.*?)"+pgflag).FindAllStringSubmatchIndex(con, -1)
  800. if len(keys) == 0 {
  801. //key在包前面,并且key以冒号结尾
  802. keys = regexp.MustCompile("()([\u4e00-\u9fa5]{2,30}?([((].{1,8}?[))])?[::]+[\\s\u3000\u2003\u00a0]*[\r\n])"+pgflag).FindAllStringSubmatchIndex(con, -1)
  803. }
  804. if len(keys) == 0 {
  805. keys = regexp.MustCompile("()注[::]([\u4e00-\u9fa5]{2,8}?([((].{1,8}?[))])?[\\s\u3000\u2003\u00a0]*[\r\n])"+pgflag).FindAllStringSubmatchIndex(con, -1)
  806. }
  807. for _, key := range keys {
  808. startEndMap[key[5]] = key[4]
  809. //
  810. headkey := con[key[4]:key[5]]
  811. headkey = regReplAllSpace.ReplaceAllString(headkey, "")
  812. if !regDivision.MatchString(headkey) {
  813. headkey += ":"
  814. }
  815. headkey = moreColonReg.ReplaceAllString(headkey, ":")
  816. colonIndexs := regDivision.FindAllStringIndex(headkey, -1)
  817. if len(colonIndexs) > 1 {
  818. headkey = headkey[colonIndexs[len(colonIndexs)-2][1]:colonIndexs[len(colonIndexs)-1][1]]
  819. }
  820. indexKeyStringMap[key[5]] = headkey
  821. indexKeyIntMap[key[5]] = key[1]
  822. }
  823. }
  824. indexs = getPkgIndex(indexs)
  825. for ik, iv := range indexs {
  826. if indexKeyStringMap[iv] != "" {
  827. continue
  828. }
  829. if indexKeyIntMap[iv] == indexMap[iv] {
  830. continue
  831. }
  832. if ik > 0 {
  833. indexKeyStringMap[iv] = indexKeyStringMap[indexs[ik-1]]
  834. }
  835. }
  836. //获取截取标识
  837. surplusText, maxWarpCount, indexTextMap, indexWarpMap := interceptText(indexs, indexPkgMap, pkgIndexMap, startEndMap, con)
  838. //查找分包内容,分kv
  839. for _, iv := range indexs {
  840. text := indexTextMap[iv]
  841. tmptext := text
  842. //
  843. warpIndex := regSpliteSegment.FindAllStringIndex(text, -1)
  844. if len(indexWarpMap) > 0 {
  845. maxWarpCount = indexWarpMap[iv]
  846. }
  847. if maxWarpCount > 0 && len(warpIndex) >= 5 && len(warpIndex) > maxWarpCount {
  848. textTemp := text
  849. text = textTemp[:warpIndex[maxWarpCount-1][1]]
  850. surplusText += textTemp[warpIndex[maxWarpCount-1][0]:]
  851. }
  852. for bk, bv := range pkg {
  853. //判断分包如果在这段文字里面,该段文字就属于该包的
  854. if !strings.HasPrefix(text, bv[0]) {
  855. continue
  856. }
  857. index := util.PackageNumberConvert(bk)
  858. //去掉前缀,空格必须要加,分kv的时候要用
  859. text = regexp.MustCompile(bv[0]+"[::]*").ReplaceAllString(text, "")
  860. if strings.TrimLeft(tmptext, bv[0]) == text || strings.TrimLeft(tmptext, bv[0]+":") == text || strings.TrimLeft(tmptext, bv[0]+":") == text {
  861. var tagtitle string
  862. for i, v := range titleindexs {
  863. if i == 0 {
  864. continue
  865. }
  866. if v[0] > iv {
  867. tagtitle = con[titleindexs[i-1][0]:titleindexs[i-1][1]]
  868. break
  869. }
  870. }
  871. tagtitle = regReplAllSpace2.ReplaceAllString(tagtitle, "")
  872. if tagtitle == "" {
  873. tagtitle = title
  874. } else if strings.Contains(tagtitle, bv[0]) && title != "" {
  875. tagtitle = title
  876. }
  877. text = tagtitle + ":" + text
  878. }
  879. headKey := ""
  880. if indexKeyStringMap[iv] != "" {
  881. //if !filterPkgTitleKey.MatchString(indexKeyStringMap[iv]) {
  882. headKey = indexKeyStringMap[iv]
  883. //}
  884. for _, pkgIndexMap_v := range pkgIndexMap[bv[0]] {
  885. delete(indexKeyStringMap, pkgIndexMap_v)
  886. break
  887. }
  888. }
  889. //如果一块中有多个相同的包,合并到一个
  890. if (*blockPackage)[index] != nil {
  891. //合并文本
  892. (*blockPackage)[index].Text += "\n" + text
  893. //合并冒号kv
  894. colonJobKv := GetKVAll(strings.TrimLeft(text, headKey), "", nil, 1, isSite, codeSite)
  895. if headKey != "" {
  896. kvAgain := GetKVAll(text, "", nil, 4, isSite, codeSite)
  897. MergeKvTags(colonJobKv.KvTags, kvAgain.KvTags)
  898. }
  899. MergeKvTags((*blockPackage)[index].ColonKV.KvTags, colonJobKv.KvTags)
  900. //合并空格kv
  901. spaceJobKv := SspacekvEntity.Entrance(text, headKey, nil, isSite, codeSite)
  902. MergeKvTags((*blockPackage)[index].SpaceKV.KvTags, spaceJobKv.KvTags)
  903. } else {
  904. newBpkg := &util.BlockPackage{
  905. Origin: bk,
  906. Text: text,
  907. Index: index,
  908. Name: bv[0],
  909. Type: bv[1],
  910. Accuracy: accuracy,
  911. }
  912. //fmt.Println(text)
  913. finalKv := GetKVAll(strings.TrimLeft(text, headKey), "", nil, 4, isSite, codeSite)
  914. if headKey != "" {
  915. kvAgain := GetKVAll(text, "", nil, 4, isSite, codeSite)
  916. MergeKvTags(finalKv.KvTags, kvAgain.KvTags)
  917. }
  918. //kv-字段-
  919. newBpkg.ColonKV = finalKv
  920. newBpkg.SpaceKV = SspacekvEntity.Entrance(text, "", nil, isSite, codeSite)
  921. (*blockPackage)[index] = newBpkg
  922. }
  923. }
  924. }
  925. //中标人排序
  926. //if isFindWinnerOrder && blockPackage != nil && len(*blockPackage) > 0 {
  927. // for _, v := range *blockPackage {
  928. // v.WinnerOrder = winnerOrderEntity.Find(v.Text, true, 2, isSite, codeSite)
  929. // }
  930. //}
  931. return true, surplusText
  932. }
  933. func getPkgIndex(indexs []int) []int {
  934. sort.Ints(indexs)
  935. indexsNew := []int{}
  936. count := 0
  937. for k, v := range indexs {
  938. if k > 0 && v-indexs[k-1] <= 10 {
  939. count++
  940. continue
  941. }
  942. indexsNew = append(indexsNew, v)
  943. }
  944. if count > 0 && count == len(indexs)-1 {
  945. return []int{}
  946. }
  947. return indexsNew
  948. }
  949. //每个包对应的结束位置,都是整行结束
  950. func interceptText(indexs []int, indexPkgMap map[int]string, pkgIndexMap map[string][]int, startEndMap map[int]int, con string) (string, int, map[int]string, map[int]int) {
  951. //util.Debug(con)
  952. surplusText := ""
  953. indexTextMap := map[int]string{}
  954. indexWarpMap := map[int]int{}
  955. maxWarpCount := 0
  956. for ik, iv := range indexs {
  957. text := ""
  958. if ik < len(indexs)-1 {
  959. if startEndMap[indexs[ik+1]] != 0 {
  960. text = con[iv:startEndMap[indexs[ik+1]]]
  961. } else {
  962. text = con[iv:indexs[ik+1]]
  963. }
  964. } else {
  965. text = con[iv:]
  966. }
  967. //fmt.Println(text)
  968. tmptext := text
  969. //if strings.Contains(text, "、") {
  970. // text = strings.Split(text, "、")[0]
  971. //} else
  972. if strings.Contains(text, "\n") {
  973. texts := strings.Split(text, "\n")
  974. text2 := ""
  975. if ik+1 < len(indexs)-1 {
  976. if startEndMap[indexs[ik+1+1]] != 0 {
  977. text2 = con[startEndMap[indexs[ik+1]]:startEndMap[indexs[ik+1+1]]]
  978. } else {
  979. text2 = con[indexs[ik+1]:indexs[ik+1+1]]
  980. }
  981. if texts[len(texts)-1] == text2 {
  982. text = texts[0]
  983. }
  984. }
  985. }
  986. if utf8.RuneCountInString(text) < 5 {
  987. indexTextMap[iv] = tmptext
  988. } else {
  989. indexTextMap[iv] = text
  990. }
  991. warpCount := len(regSpliteSegment.FindAllStringIndex(text, -1))
  992. if warpCount > maxWarpCount {
  993. maxWarpCount = warpCount
  994. }
  995. indexWarpMap[iv] = warpCount
  996. if ik == 0 {
  997. surplusText += con[:iv]
  998. }
  999. }
  1000. pkgLaw := ""
  1001. if len(pkgIndexMap) > 1 {
  1002. //有规律的出现 AB or ABAB
  1003. if pkgLaw == "" {
  1004. prevVal := ""
  1005. notRepeatCount, currentIndex, onceMax, allMax := 0, -1, 0, 0
  1006. indexMaxMap := map[int]int{}
  1007. for ik, iv := range indexs {
  1008. if notRepeatCount == len(pkgIndexMap) {
  1009. notRepeatCount = 0
  1010. }
  1011. if prevVal != indexPkgMap[iv] {
  1012. notRepeatCount++
  1013. } else {
  1014. notRepeatCount = -1
  1015. currentIndex = ik
  1016. break
  1017. }
  1018. prevVal = indexPkgMap[iv]
  1019. if notRepeatCount == len(pkgIndexMap) {
  1020. indexMaxMap[iv] = onceMax
  1021. onceMax = 0
  1022. }
  1023. if indexWarpMap[iv] > onceMax {
  1024. onceMax = indexWarpMap[iv]
  1025. allMax = onceMax
  1026. }
  1027. if ik == len(indexs)-1 && notRepeatCount != len(pkgIndexMap) {
  1028. notRepeatCount = -2
  1029. currentIndex = ik
  1030. }
  1031. }
  1032. //util.Debug(allMax, currentIndex, indexWarpMap, indexMaxMap)
  1033. if len(indexMaxMap) > 0 {
  1034. pkgLaw = "AB"
  1035. thisMax := 0
  1036. for ik := len(indexs) - 1; ik >= 0; ik-- {
  1037. iv := indexs[ik]
  1038. if currentIndex != -1 && ik >= currentIndex {
  1039. indexWarpMap[iv] = allMax
  1040. continue
  1041. }
  1042. if indexMaxMap[iv] > 0 {
  1043. thisMax = indexMaxMap[iv]
  1044. }
  1045. indexWarpMap[iv] = thisMax
  1046. }
  1047. }
  1048. }
  1049. }
  1050. if pkgLaw == "" {
  1051. indexWarpMap = map[int]int{}
  1052. }
  1053. //util.Debug(pkgLaw, maxWarpCount, indexTextMap, indexWarpMap)
  1054. return surplusText, maxWarpCount, indexTextMap, indexWarpMap
  1055. }
  1056. //分块之后的kv
  1057. func kvAfterDivideBlock(tp, text string, from int, ruleBlock *util.RuleBlock, isSite bool, codeSite string) []*util.Kv {
  1058. blocks, _ := DivideBlock(tp, text, from, ruleBlock, isSite, codeSite)
  1059. kvs := []*util.Kv{}
  1060. for _, v := range blocks {
  1061. //util.Debug(v.Text)
  1062. // for _, vvv := range v.ColonKV.Kvs {
  1063. // util.Debug(vvv.Key, vvv.Value, vvv.Title)
  1064. // }
  1065. kvs = append(kvs, v.ColonKV.Kvs...)
  1066. }
  1067. return kvs
  1068. }