|
@@ -3,6 +3,7 @@ package util
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
"log"
|
|
|
+ "regexp"
|
|
|
"strings"
|
|
|
"unicode"
|
|
|
"unicode/utf8"
|
|
@@ -50,9 +51,16 @@ func dealWithNameScoreRules(name string) (string, bool, float64 , []map[string]i
|
|
|
}
|
|
|
}
|
|
|
if len(res) > 0 {
|
|
|
- //分析分数...取最大
|
|
|
+ //针对特殊情况-特殊处理 公司结尾
|
|
|
new_name = ObjToString(res[0]["name"])
|
|
|
new_score = Float64All(res[0]["score"])
|
|
|
+ if endComReg.MatchString(name) {
|
|
|
+ new_name,new_score = dealWithSpecialName(name,res)
|
|
|
+ if new_name=="" {
|
|
|
+ new_name = ObjToString(res[0]["name"])
|
|
|
+ new_score = Float64All(res[0]["score"])
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
if new_name != "" { //分析hit比例
|
|
|
total, hit := dealWithWordsRules(name, new_name)
|
|
@@ -91,6 +99,12 @@ func dealWithNameScoreRules(name string) (string, bool, float64 , []map[string]i
|
|
|
return new_name,isok,new_score,nil
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
func dealWithPreRule(name string , new_name string) bool {
|
|
|
//log.Println("规则时:",name,new_name)
|
|
|
endstr := endWordReg.FindString(new_name)
|
|
@@ -272,3 +286,47 @@ func escapeNew(s string) string {
|
|
|
}
|
|
|
return news
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+//处理特殊情况-分析最终
|
|
|
+func dealWithSpecialName(name string,res []map[string]interface{})(string ,float64) {
|
|
|
+ //log.Println("特殊...")
|
|
|
+ new_name ,new_score,proportion := "",float64(0),float64(0)
|
|
|
+ for k,v:=range res {
|
|
|
+ tmp_name := ObjToString(v["name"])
|
|
|
+ tmp_score := Float64All(v["score"])
|
|
|
+ if k>=20 || tmp_score<3.0 {
|
|
|
+ break
|
|
|
+ }
|
|
|
+
|
|
|
+ if endComReg.MatchString(tmp_name) {
|
|
|
+ if endFComReg.MatchString(name) {
|
|
|
+ if !endFComReg.MatchString(tmp_name) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if endFComReg.MatchString(tmp_name) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ total, hit := dealWithWordsRules(tmp_name, name)
|
|
|
+ tmp_proportion := float64(hit) / float64(total)
|
|
|
+ //log.Println(tmp_proportion,tmp_name,name)
|
|
|
+ if tmp_proportion > proportion {
|
|
|
+ proportion = tmp_proportion
|
|
|
+ new_name = tmp_name
|
|
|
+ new_score = tmp_score
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return new_name,float64(new_score)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+var endComReg *regexp.Regexp = regexp.MustCompile("(公司)$")
|
|
|
+var endFComReg *regexp.Regexp = regexp.MustCompile("(分公司)$")
|