Browse Source

处理对称符号中内容

unknown 6 years ago
parent
commit
d07902a72f
1 changed files with 16 additions and 12 deletions
  1. 16 12
      src/jy/clear/specialsymbols.go

+ 16 - 12
src/jy/clear/specialsymbols.go

@@ -55,11 +55,13 @@ func init() {
 		messycodeStr = "[" + messycodeStr + "]"
 	}
 	MesReg = regexp.MustCompile(messycodeStr)
-
-	//
 	SymInterCon = qu.ObjArrToStringArr(SpecialSymbols["symintercon"].([]interface{}))
 
-	//log.Println(string(DealSinAndDouQuotes([]rune("安顺市西\"秀区园林局\"环卫设备\"项目"))))
+	//	text := []rune("(阳江市海陵岛经济开发试验区环境卫生管理所)(阳江市海陵岛经济开发试验区环境卫生管理所果皮箱、垃圾桶采购项目)(GX2015YJ1010GK125)的综合评分法中标公告广东")
+	//	for i := 1; i <= 2; i++ {
+	//		text = AnotherRemoveStart(text)
+	//		qu.Debug(string(text))
+	//	}
 }
 
 //去除首尾空格、换行、回车
@@ -243,7 +245,7 @@ func AnotherRemoveStart(text []rune) []rune {
 		surplusMax := -1                      //记录多余的反符号最大值
 		positiveMax := -1                     //记录多余的正符号最大值
 		removeLength := 0
-		tmpLength := 0 //记录对称符号间内容的长度
+		//tmpLength := 0 //记录对称符号间内容的长度
 		nb := 0
 		length := len(text)
 		for index, t := range text {
@@ -280,7 +282,7 @@ func AnotherRemoveStart(text []rune) []rune {
 								pairedIndex[index] = nowIndex
 							}
 							pairedIndex[nowIndex] = index
-							tmpLength = tmpLength + len(text[nowIndex:index+1])
+							//tmpLength = tmpLength + len(text[nowIndex:index+1])
 						}
 					} else { //正向符号,加入symbolIndex记录索引
 						tmpArr := []int{}
@@ -295,10 +297,10 @@ func AnotherRemoveStart(text []rune) []rune {
 				}
 			}
 		}
-		//处理文本整个被对称符号包括的情况 例:(乐平镇范湖纵二路){道路建设工程}
-		if length == tmpLength {
-			text = DelContext(pairedIndex, text)
-			return text
+		//处理文本中有对称符号的情况
+		tmptext, ismatch := DelContext(pairedIndex, text)
+		if ismatch {
+			return tmptext
 		}
 		//例:“教育部高等教育教学评估中心数据中心升级改造”项目 -> 教育部高等教育教学评估中心数据中心升级改造项目
 		if surplusMax == -1 && positiveMax == -1 {
@@ -359,9 +361,10 @@ func AnotherRemoveStart(text []rune) []rune {
 	return text
 }
 
-func DelContext(pairedIndex map[int]int, text []rune) []rune {
+func DelContext(pairedIndex map[int]int, text []rune) ([]rune, bool) {
 	length := 0
 	var result []rune
+	ismatch := false
 	for s, e := range pairedIndex {
 		if s < e {
 			var tmp []rune
@@ -369,15 +372,16 @@ func DelContext(pairedIndex map[int]int, text []rune) []rune {
 			if len(tmp) > 2 { //排除对称符号中只有["工程","项目","采购","服务","监理","施工","设计"]
 				for _, r := range SymInterCon {
 					if strings.HasSuffix(string(tmp), r) && len(tmp) > length {
+						ismatch = true
 						result = tmp
 						length = len(tmp)
 					}
 				}
 			}
-
 		}
 	}
-	return result
+
+	return result, ismatch
 }
 
 func DealSinAndDouQuotes(text []rune) []rune {