|
@@ -12,6 +12,8 @@ var AsyReg, AllReg, MesReg *regexp.Regexp
|
|
|
var SymField map[string]interface{} //对称符号过滤字段
|
|
|
var AsyField map[string]interface{} //特殊符号过滤字段
|
|
|
var MesField map[string]interface{} //乱码过滤字段
|
|
|
+var SymInterCon []string //对称符号中间内容处理
|
|
|
+
|
|
|
func init() {
|
|
|
qu.ReadConfig("./specialsymbols.json", &SpecialSymbols)
|
|
|
//对称符号
|
|
@@ -53,10 +55,13 @@ func init() {
|
|
|
messycodeStr = "[" + messycodeStr + "]"
|
|
|
}
|
|
|
MesReg = regexp.MustCompile(messycodeStr)
|
|
|
+
|
|
|
+ //
|
|
|
+ SymInterCon = qu.ObjArrToStringArr(SpecialSymbols["symintercon"].([]interface{}))
|
|
|
}
|
|
|
|
|
|
//去除首尾空格、换行、回车
|
|
|
-func RemoveHeadAndEndSpace(text string) string {
|
|
|
+func RemoveHESpace(text string) string {
|
|
|
defer qu.Catch()
|
|
|
if len(text) > 0 {
|
|
|
tmp := cutSpace.ReplaceAllString(strings.Replace(text, " ", " ", -1), "")
|
|
@@ -65,7 +70,7 @@ func RemoveHeadAndEndSpace(text string) string {
|
|
|
return text
|
|
|
}
|
|
|
|
|
|
-func RemoveHeadAndEndSymmetricCode(val string) string {
|
|
|
+func RemoveHESymCode(val string) string {
|
|
|
defer qu.Catch()
|
|
|
text := []rune(val)
|
|
|
if len(text) > 0 {
|
|
@@ -194,7 +199,7 @@ func RemoveMessycode(text string) string {
|
|
|
}
|
|
|
|
|
|
//特殊符号
|
|
|
-func RemoveAsymmetric(text string) string {
|
|
|
+func RemoveAsy(text string) string {
|
|
|
defer qu.Catch()
|
|
|
if len(text) > 0 {
|
|
|
textRune := []rune(text)
|
|
@@ -212,28 +217,29 @@ func RemoveAsymmetric(text string) string {
|
|
|
}
|
|
|
|
|
|
func OtherClean(field, text string) string {
|
|
|
- text = RemoveHeadAndEndSpace(text) //去除首尾空格
|
|
|
+ text = RemoveHESpace(text) //去除首尾空格
|
|
|
if AsyField[field] != nil {
|
|
|
- text = RemoveAsymmetric(text) //特殊符号
|
|
|
+ text = RemoveAsy(text) //特殊符号
|
|
|
}
|
|
|
if SymField[field] != nil { //对称符号
|
|
|
- text = RemoveHeadAndEndSymmetricCode(text)
|
|
|
+ text = RemoveHESymCode(text)
|
|
|
}
|
|
|
if MesField[field] != nil { //乱码
|
|
|
text = RemoveMessycode(text)
|
|
|
}
|
|
|
- text = RemoveHeadAndEndSpace(text) //去除首尾空格
|
|
|
+ text = RemoveHESpace(text) //去除首尾空格
|
|
|
return text
|
|
|
}
|
|
|
|
|
|
func AnotherRemoveStart(text []rune) []rune {
|
|
|
defer qu.Catch()
|
|
|
if len(text) > 0 {
|
|
|
- pairedIndex := make(map[int]int)
|
|
|
+ pairedIndex := make(map[int]int) //对称符号索引位置
|
|
|
symbolIndex := make(map[string][]int) //记录符号和当前索引位置
|
|
|
surplusMax := -1 //记录多余的反符号最大值
|
|
|
positiveMax := -1 //记录多余的正符号最大值
|
|
|
removeLength := 0
|
|
|
+ tmpLength := 0 //记录对称符号间内容的长度
|
|
|
nb := 0
|
|
|
length := len(text)
|
|
|
for index, t := range text {
|
|
@@ -270,6 +276,7 @@ func AnotherRemoveStart(text []rune) []rune {
|
|
|
pairedIndex[index] = nowIndex
|
|
|
}
|
|
|
pairedIndex[nowIndex] = index
|
|
|
+ tmpLength = tmpLength + len(text[nowIndex:index+1])
|
|
|
}
|
|
|
} else { //正向符号,加入symbolIndex记录索引
|
|
|
tmpArr := []int{}
|
|
@@ -284,6 +291,26 @@ func AnotherRemoveStart(text []rune) []rune {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ //处理文本整个被对称符号包括的情况 例:(乐平镇范湖纵二路){道路建设工程}
|
|
|
+ if length == tmpLength {
|
|
|
+ text = DelContext(pairedIndex, text)
|
|
|
+ return text
|
|
|
+ }
|
|
|
+ //例:“教育部高等教育教学评估中心数据中心升级改造”项目 -> 教育部高等教育教学评估中心数据中心升级改造项目
|
|
|
+ if surplusMax == -1 && positiveMax == -1 {
|
|
|
+ i := pairedIndex[0]
|
|
|
+ if i > 0 {
|
|
|
+ end := text[i+1:]
|
|
|
+ for _, r := range SymInterCon {
|
|
|
+ if r == string(end) {
|
|
|
+ tmptext := text[1:i]
|
|
|
+ tmptext = append(tmptext, end...)
|
|
|
+ return []rune(tmptext)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
if len(symbolIndex) != 0 { //多余的正符号索引位置
|
|
|
for _, arr := range symbolIndex {
|
|
|
for j, l := range arr {
|
|
@@ -328,3 +355,24 @@ func AnotherRemoveStart(text []rune) []rune {
|
|
|
}
|
|
|
return text
|
|
|
}
|
|
|
+
|
|
|
+func DelContext(pairedIndex map[int]int, text []rune) []rune {
|
|
|
+ length := 0
|
|
|
+ var result []rune
|
|
|
+ for s, e := range pairedIndex {
|
|
|
+ if s < e {
|
|
|
+ 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 {
|
|
|
+ result = tmp
|
|
|
+ length = len(tmp)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result
|
|
|
+}
|