Prechádzať zdrojové kódy

注释-抽取-部分

zhengkun 4 rokov pred
rodič
commit
669e052069

+ 6 - 4
src/jy/extract/extract.go

@@ -131,7 +131,7 @@ func StartExtractTestTask(taskId, startId, num, resultcoll, trackcoll string) bo
 	ext.InitClearFn(false)
 	ext.InitClearFn(true)
 	ext.Lock()
-	//ext.IsExtractCity = false
+	ext.IsExtractCity = false
 	if ext.IsExtractCity { //版本上控制是否开始城市抽取
 		//初始化城市DFA信息
 		ext.InitCityInfo()
@@ -181,10 +181,10 @@ func RunExtractTestTask(ext *ExtractTask, startId, num string) bool {
 			if ext.IsFileField && (v["projectinfo"] != nil || v["attach_text"] != nil) {
 				v["isextFile"] = true
 				j, jf, isSite = ext.PreInfo(v)
-			} else {
+			} else {//无附件
 				j, _, isSite = ext.PreInfo(v)
 			}
-			go ext.ExtractProcess(j, jf, isSite)
+			go ext.ExtractProcess(j, jf, isSite) //抽取-打分-保存
 			ext.TaskInfo.ProcessPool <- true
 		}
 		return true
@@ -325,7 +325,7 @@ func PreInfo(doc map[string]interface{}) (j, jf *ju.Job, isSite bool) {
 
 var clearMoneyReg *regexp.Regexp = regexp.MustCompile("(PPP[\\s]?项目|新城镇建设|国土资源局|基金管理|高速公路|水系生态治理|水生态建设|棚改旧改|棚户区改造|棚改项目|危房改造项目|土地整理|高速公路项目)")
 
-//信息预处理-和版本关联
+//信息预处理-和版本关联-处理表格-附件-kv标签库-中标候选人
 func (e *ExtractTask) PreInfo(doc map[string]interface{}) (j, jf *ju.Job, isSite bool) {
 	defer qu.Catch()
 	//判断是否有附件这个字段
@@ -609,6 +609,7 @@ func (e *ExtractTask) ExtractProcess(j, jf *ju.Job, isSite bool) {
 	<-e.TaskInfo.ProcessPool
 }
 
+//抽取-正文-规则等 detail
 func (e *ExtractTask) ExtractDetail(j *ju.Job, isSite bool, codeSite string) {
 	qu.Try(func() {
 		doc := *j.Data
@@ -618,6 +619,7 @@ func (e *ExtractTask) ExtractDetail(j *ju.Job, isSite bool, codeSite string) {
 		//}
 		tmprules := map[string][]*RuleCore{}
 		lockrule.Lock()
+		//加载分类抽取配置
 		if j.Category == "all" || j.CategorySecond == "all" {
 			if isSite {
 				for k, vc1 := range e.SiteRuleCores["all_all"] {

+ 1 - 0
src/jy/extract/extractInit.go

@@ -1056,6 +1056,7 @@ func (e *ExtractTask) InitCityInfo() {
 	districts_maps := make(map[string]map[string][]map[string]interface{}, 0)
 	towns_maps := make(map[string]map[string]map[string][]map[string]interface{}, 0)
 	jwhs_maps := make(map[string]map[string]map[string]map[string][]map[string]interface{}, 0)
+
 	for _, v := range alldata {
 		codenum := len(v["code"].(string))
 		province := qu.ObjToString(v["province"])

+ 8 - 3
src/jy/pretreated/analystep.go

@@ -25,7 +25,7 @@ func AnalyStart(job *util.Job, isSite bool, codeSite string) {
 	con := job.Content
 	//全文的需要修复表格
 	con = RepairCon(con)
-	//格式化正文
+	//格式化正文 -断点
 	con = formattext3.ReplaceAllString(con,"")
 	con = hisReg.ReplaceAllString(con, "${2}")
 	con = hisReg2.ReplaceAllString(con, "${2}")
@@ -45,7 +45,8 @@ func AnalyStart(job *util.Job, isSite bool, codeSite string) {
 		}
 	}*/
 	job.BlockPackage = map[string]*util.BlockPackage{}
-	blockArrays, _ := DivideBlock(job.CategorySecond, con, 1, job.RuleBlock, isSite, codeSite) //分块
+	//分块+处理每块kv
+	blockArrays, _ := DivideBlock(job.CategorySecond, con, 1, job.RuleBlock, isSite, codeSite)
 	if len(blockArrays) > 0 {                                                                  //有分块
 		//从块里面找分包
 		if !job.IsFile {
@@ -88,6 +89,8 @@ func AnalyStart(job *util.Job, isSite bool, codeSite string) {
 					}
 				}
 				//添加标识:文本中有table
+				//blockTag - 块标签
+				//处理表格
 				tabres := AnalyTableV2(tabs[i], job.Category, blockTag, con, 1, job.SourceMid, job.RuleBlock, isSite, codeSite) //解析表格入口 返回:汇总表格对象
 				processTableResult(tabres, bl, job, isSite, codeSite)
 			}
@@ -103,9 +106,11 @@ func AnalyStart(job *util.Job, isSite bool, codeSite string) {
 				bl.Text = bl.Text[:strings.Index(bl.Text, "业绩")]
 			}
 		}
-		//调用kv解析
+		//调用kv解析库-处理detail
 		bl.Text = formatText(bl.Text, "all")
+		//处理 :
 		bl.ColonKV = GetKVAll(bl.Text, "", nil, 1, isSite, codeSite)
+		//处理空格
 		bl.SpaceKV = SspacekvEntity.Entrance(bl.Text, "", nil, isSite, codeSite)
 		//新加 未分块table中未能解析到中标候选人,从正文中解析
 		if job.Winnerorder == nil || len(job.Winnerorder) == 0 {

+ 2 - 2
src/jy/pretreated/analytable.go

@@ -735,7 +735,7 @@ func (ts *TableResult) Analy(isSite bool, codeSite string) {
 	}
 	//tn.SonTables = append(tn.SonTables, tn)
 	//}
-	//统一合并,考虑统一多表格是多包的情况---新增
+	//统一合并,考虑统一多表格是多包的情况---新增   与子表格合并
 	if len(tabs) > 1 {
 		pns := map[string]string{}
 		pnarr := []string{}
@@ -834,7 +834,7 @@ func (table *Table) Analy(contactFormat *u.ContactFormat, isSite bool, codeSite
 	if ztb >= 9 {
 		return []*Table{}
 	}
-	//遍历节点,初始化table 结构
+	//遍历节点,初始化table 结构  TRs Sorts
 	table.createTabe(trs, isSite, codeSite)
 	if len(table.TRs) == 0 {
 		return []*Table{}

+ 2 - 1
src/jy/pretreated/division.go

@@ -311,7 +311,8 @@ func DivideBlock(tp, content string, from int, ruleBlock *util.RuleBlock, isSite
 	}
 	for _, bl := range returnBlocks {
 		//解析kv
-		newText := TextAfterRemoveTable(bl.Text)
+		newText := TextAfterRemoveTable(bl.Text) //取出纯文本
+
 		bl.ColonKV = GetKVAll(newText, bl.Title, contactFormat, from, isSite, codeSite)
 		bl.SpaceKV = SspacekvEntity.Entrance(newText, bl.Title, contactFormat, isSite, codeSite)
 		//正则抽取的时候有时需要匹配换行或者句号,这里在解析完kv之后,在块结尾添加换行和句号

+ 1 - 0
src/main.go

@@ -70,6 +70,7 @@ func init() {
 }
 
 func main() {
+
 	extract.ExtractUdp() //udp通知抽取
 	//extract.ClearUdp()   //udp通知清理
 	go extract.Export()

+ 1 - 1
udpdataclear/udpSensitiveWords/config.json

@@ -24,7 +24,7 @@
   ],
   "userName": "",
   "passWord": "",
-  "client_es": "http://172.17.4.84:9800",
+  "client_es": "http://ela.spdata.jianyu360.com",
   "es_type": "unique_qy",
   "es_index": "unique_qy"
 }

+ 2 - 0
udpdataclear/udpSensitiveWords/main.go

@@ -8,6 +8,8 @@ func init() {
 	util.InitC()
 }
 func main() {
+
+
 	go util.AddTaskSensitiveWordsData() //增量
 	// 主函数中添加
 	util.ExtractUdp() //udp通知抽取

+ 14 - 0
udpdataclear/udpSensitiveWords/util/hisdata.go

@@ -120,3 +120,17 @@ func HistoryReadyData() {
 
 }
 
+
+
+
+
+
+//测试方法
+func TestData() {
+	//北京建雄建筑集团有限公司 江苏贝尔照明电气有限公司 甘肃三杰软件有限公司 云南和合泰商贸有限公司
+	//甘肃泓文建筑设计有限公司 天津市静海县龙盛水泥制品厂 中国联通网络通信有限公司张家口市分公司
+	//广联达软件有限公司河南分公司  上海熊猫机械(集团)有限公司昆明分公司
+	name:="上海熊猫机械(集团)有限公司昆明分公司"
+	rname, isok, _ ,datas := dealWithNameScoreRules(name)
+	log.Println(rname,isok,len(datas))
+}

+ 3 - 2
udpdataclear/udpSensitiveWords/util/udpdata.go

@@ -53,7 +53,7 @@ func QuerySensitiveWords(sid, eid string) {
 			"$lte": objEid,
 		},
 	}).Select(Fields).Iter()
-	c := make(chan struct{}, 3)
+	c := make(chan struct{}, 1)
 	for tmp := map[string]interface{}{}; iter.Next(&tmp); tmp = map[string]interface{}{} {
 		c <- struct{}{}
 		syc.Add(1)
@@ -99,7 +99,7 @@ func handletmp(tmp map[string]interface{}, unum *int, c <-chan struct{}) {
 		*unum++
 		tmp["log"] = up
 		id := tmp["_id"].(primitive.ObjectID).Hex()
-		log.Println(tmp)
+		//log.Println(tmp)
 		QfwMgo85.UpdateById(Collection, id, map[string]interface{}{"$set": tmp})
 	}
 }
@@ -389,3 +389,4 @@ var startWordReg_3 *regexp.Regexp = regexp.MustCompile("^(北京市|天津市|
 
 
 var endWordReg *regexp.Regexp = regexp.MustCompile("(有限公司|有限责任公司)$")
+

+ 59 - 1
udpdataclear/udpSensitiveWords/util/words.go

@@ -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("(分公司)$")