maxiaoshan пре 6 година
родитељ
комит
7b96cbdd58
2 измењених фајлова са 100 додато и 46 уклоњено
  1. 37 10
      src/jy/clear/specialsymbols.go
  2. 63 36
      src/specialsymbols.json

+ 37 - 10
src/jy/clear/specialsymbols.go

@@ -13,9 +13,13 @@ var SymField map[string]interface{} //对称符号过滤字段
 var AsyField map[string]interface{} //特殊符号过滤字段
 var MesField map[string]interface{} //乱码过滤字段
 var SymInterCon []string            //对称符号中间内容处理
+var SymmetricDelete map[string]bool //对称符号之间的内容是否删除
 
 func init() {
 	qu.ReadConfig("./specialsymbols.json", &SpecialSymbols)
+	if SymmetricDelete == nil {
+		SymmetricDelete = map[string]bool{}
+	}
 	//对称符号
 	tmp1 := SpecialSymbols["symmetric"].(map[string]interface{})
 	SymField = tmp1["field"].(map[string]interface{})
@@ -23,9 +27,13 @@ func init() {
 	SymmetricMap = make(map[string]string)
 	allSymbol := ""
 	for _, val := range symmetricArr { //SymmetricMap
-		tmpArr := qu.ObjArrToStringArr(val.([]interface{}))
+		symap := val.(map[string]interface{})
+		tmpArr := qu.ObjArrToStringArr(symap["text"].([]interface{}))
+		isdelete, _ := symap["symdelete"].(bool) //对称符号之间的内容是否删除
 		s1 := strings.Replace(tmpArr[0], "\\", "", -1)
 		s2 := strings.Replace(tmpArr[1], "\\", "", -1)
+		SymmetricDelete[s1] = isdelete
+		SymmetricDelete[s2] = isdelete
 		allSymbol = tmpArr[0] + tmpArr[1] + allSymbol
 		SymmetricMap[s2] = s1
 	}
@@ -57,7 +65,7 @@ func init() {
 	MesReg = regexp.MustCompile(messycodeStr)
 	SymInterCon = qu.ObjArrToStringArr(SpecialSymbols["symintercon"].([]interface{}))
 
-	//	text := []rune("2019年大兴新城地区公共厕所及附属设施项目(改造-施工)")
+	//	text := []rune("中煤张家口煤矿机械有限责任公司铸造槽帮(可含热处理工序、机加工工序或全工序)外协合格")
 	//	for i := 1; i <= 2; i++ {
 	//		text = AnotherRemoveStart(text)
 	//		qu.Debug(string(text))
@@ -240,6 +248,7 @@ func OtherClean(field, text string) string {
 func AnotherRemoveStart(text []rune) []rune {
 	defer qu.Catch()
 	if len(text) > 0 {
+		delstrarr := []string{}
 		pairedIndex := make(map[int]int)      //对称符号索引位置
 		symbolIndex := make(map[string][]int) //记录符号和当前索引位置
 		surplusMax := -1                      //记录多余的反符号最大值
@@ -298,10 +307,15 @@ func AnotherRemoveStart(text []rune) []rune {
 			}
 		}
 		//处理文本中有对称符号的情况
-		tmptext, ismatch := DelContext(pairedIndex, text)
+		tmptext, ismatch, delindex := DelContext(pairedIndex, text)
 		if ismatch {
 			return tmptext
 		}
+		if len(delindex) > 0 {
+			for s, e := range delindex {
+				delstrarr = append(delstrarr, string(text[s:e+1]))
+			}
+		}
 		//例:“教育部高等教育教学评估中心数据中心升级改造”项目 -> 教育部高等教育教学评估中心数据中心升级改造项目
 		if surplusMax == -1 && positiveMax == -1 {
 			i := pairedIndex[0]
@@ -330,14 +344,14 @@ func AnotherRemoveStart(text []rune) []rune {
 				}
 			}
 		}
-		firstOpposite := pairedIndex[0]
-		if firstOpposite != 0 { //第一个正符号对应反符号的位置
+		firstOpposite := pairedIndex[0]                             //第一个正符号对应反符号的位置
+		if firstOpposite != 0 && SymmetricDelete[string(text[0])] { //删除开头由对称符号包括的内容:(2019年大兴)新城地(区公共厕)所及附属(改造发斯蒂芬)-->新城地(区公共厕)所及附属(改造发斯蒂芬)
 			text = text[firstOpposite+1:]
 			removeLength = firstOpposite + 1
 			nb = nb + removeLength
 		}
-		lastOpposite := pairedIndex[length-1] //最后一个符号
-		if lastOpposite > 0 {                 //有对称的正向符号,删除其中间内容
+		lastOpposite := pairedIndex[length-1]                            //最后一个符号
+		if lastOpposite > 0 && SymmetricDelete[string(text[length-1])] { //删除结尾由对称符号包括的内容:新城地(区公共厕)所及附属(改造发斯蒂芬)-->新城地(区公共厕)所及附属
 			//na = length - lastOpposite
 			text = text[:lastOpposite-removeLength]
 		} else if surplusMax == length-1 { //没有对称,只删除最后一个反符号
@@ -357,21 +371,34 @@ func AnotherRemoveStart(text []rune) []rune {
 				text = text[:positiveMax-nb]
 			}
 		}
+		if len(delstrarr) > 0 {
+			for _, rep := range delstrarr {
+				if strings.HasPrefix(rep, string(text[0])) || strings.HasSuffix(rep, string(text[len(text)-1])) { //要清理的内容是开头和结尾部分,清理
+					text = []rune(strings.Replace(string(text), rep, "", -1))
+				}
+			}
+		}
 	}
 	return text
 }
 
-func DelContext(pairedIndex map[int]int, text []rune) ([]rune, bool) {
+func DelContext(pairedIndex map[int]int, text []rune) ([]rune, bool, map[int]int) {
 	length := 0
 	var result []rune
 	ismatch := false
+	delindex := map[int]int{}
 	for s, e := range pairedIndex {
 		if s < e {
+			nowsym := string(text[s])
+			if SymmetricDelete[nowsym] { //删除该对称中的内容
+				delindex[s] = e
+				continue
+			}
 			var tmp []rune
 			tmp = text[s+1 : e]
 			if len(tmp) > 2 { //排除对称符号中只有["工程","项目","采购","服务","监理","施工","设计"]
 				for _, r := range SymInterCon {
-					if strings.HasSuffix(string(tmp), r) && len(tmp) > length && len([]rune(strings.Replace(string(tmp), r, "", -1))) > 4 {
+					if strings.HasSuffix(string(tmp), r) && len(tmp) > length && len([]rune(strings.Replace(string(tmp), r, "", -1))) > 6 {
 						ismatch = true
 						result = tmp
 						length = len(tmp)
@@ -381,7 +408,7 @@ func DelContext(pairedIndex map[int]int, text []rune) ([]rune, bool) {
 		}
 	}
 
-	return result, ismatch
+	return result, ismatch, delindex
 }
 
 func DealSinAndDouQuotes(text []rune) []rune {

+ 63 - 36
src/specialsymbols.json

@@ -7,42 +7,69 @@
             "agency": true
         },
         "symbol": [
-            [
-                "(",
-                ")"
-            ],
-            [
-                "\\[",
-                "\\]"
-            ],
-            [
-                "{",
-                "}"
-            ],
-            [
-                "{",
-                "}"
-            ],
-            [
-                "‘",
-                "’"
-            ],
-            [
-                "“",
-                "”"
-            ],
-            [
-                "【",
-                "】"
-            ],
-            [
-                "(",
-                ")"
-            ],
-            [
-                "<",
-                ">"
-            ]
+			{
+				"symdelete":false,
+				"text":[
+                		"(",
+                		")"
+           		 	]				
+			},
+			{
+				"symdelete":false,
+				"text":[
+	                "(",
+	                ")"
+	            ]
+			},
+			{
+				"symdelete":true,
+				"text":[
+		                "\\[",
+		                "\\]"
+		            ]			
+			},
+			{
+				"symdelete":true,
+				"text":[
+		                "{",
+		                "}"
+		            ]			
+			},
+			{
+				"symdelete":true,
+				"text":[
+		                "{",
+		                "}"
+		            ]			
+			},
+            {
+				"symdelete":true,
+				"text":[
+		                "‘",
+		                "’"
+		            ]		
+			},
+			{
+				"symdelete":true,
+				"text":[
+		                "“",
+		                "”"
+		            ]	
+			},
+			{
+				"symdelete":true,
+				"text":[
+	                "【",
+	                "】"
+	            ]		
+			},
+			{
+				"symdelete":true,
+				"text":[
+	                "<",
+	                ">"
+	            ]
+			}
         ]
     },
     "asymmetric": {