浏览代码

子块不抽取分包

wcj 6 年之前
父节点
当前提交
5e03f2a0ae
共有 2 个文件被更改,包括 64 次插入18 次删除
  1. 56 14
      src/jy/extract/extract.go
  2. 8 4
      src/jy/pretreated/analystep.go

+ 56 - 14
src/jy/extract/extract.go

@@ -580,26 +580,68 @@ func ExtRuleCore(doc map[string]interface{}, e *ExtractTask, vc *RuleCore, j *ju
 			ExtRuleCoreByReg(vc.ExtFrom, doc, j, v, e)
 		}
 	}
-	for k, v := range kvMap {
-		if j.Result[k] == nil {
-			j.Result[k] = [](*ju.ExtField){}
+	//如果只有一个分包,预算没有抽取到,把分包中的预算保存到外面
+	if vc.Field == "budget" && len(kvMap) == 0 {
+		if len(j.BlockPackage) == 1 {
+			for _, bp := range j.BlockPackage {
+				for fieldname, field := range vc.LFields {
+					if field != vc.Field {
+						continue
+					}
+					tp := ""
+					for k, v := range []*ju.JobKv{bp.ColonKV, bp.SpaceKV, bp.TableKV} {
+						if k == 0 {
+							tp = "colon"
+						} else if k == 1 {
+							tp = "space"
+						} else if k == 2 {
+							tp = "table"
+						}
+						if v == nil || v.KvTags == nil {
+							continue
+						}
+						for _, vv := range v.KvTags[fieldname] {
+							text := ju.TrimLRSpace(vv.Value, "")
+							if text != "" {
+								j.Result[vc.Field] = append(j.Result[vc.Field], &ju.ExtField{
+									Field:       vc.Field,
+									Code:        "CL_分包",
+									Type:        tp,
+									MatchType:   "package",
+									RuleText:    bp.Text,
+									SourceValue: vv.Key,
+									Value:       text,
+								})
+							}
+						}
+					}
+				}
+				break
+			}
 		}
-		for _, tmp := range v {
-			field := &ju.ExtField{Weight: qu.IntAll(tmp["weight"]), Field: k, Code: qu.ObjToString(tmp["code"]), Type: qu.ObjToString(tmp["type"]), MatchType: qu.ObjToString(tmp["matchtype"]), RuleText: qu.ObjToString(tmp["ruletext"]), SourceValue: tmp["sourcevalue"], Value: tmp["value"]}
-			if tmp["blocktag"] != nil {
-				btag := make(map[string]string)
-				for k := range tmp["blocktag"].(map[string]bool) {
-					blocktag.Lock()
-					if TagConfigDesc[k] != "" {
-						btag[k] = TagConfigDesc[k]
+	} else {
+		for k, v := range kvMap {
+			if j.Result[k] == nil {
+				j.Result[k] = [](*ju.ExtField){}
+			}
+			for _, tmp := range v {
+				field := &ju.ExtField{Weight: qu.IntAll(tmp["weight"]), Field: k, Code: qu.ObjToString(tmp["code"]), Type: qu.ObjToString(tmp["type"]), MatchType: qu.ObjToString(tmp["matchtype"]), RuleText: qu.ObjToString(tmp["ruletext"]), SourceValue: tmp["sourcevalue"], Value: tmp["value"]}
+				if tmp["blocktag"] != nil {
+					btag := make(map[string]string)
+					for k := range tmp["blocktag"].(map[string]bool) {
+						blocktag.Lock()
+						if TagConfigDesc[k] != "" {
+							btag[k] = TagConfigDesc[k]
+						}
+						blocktag.Unlock()
 					}
-					blocktag.Unlock()
+					field.BlockTag = btag
 				}
-				field.BlockTag = btag
+				j.Result[k] = append(j.Result[k], field)
 			}
-			j.Result[k] = append(j.Result[k], field)
 		}
 	}
+
 }
 
 //抽取-规则-kv

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

@@ -38,11 +38,11 @@ func AnalyStart(job *util.Job) {
 			if len([]rune(bl.Text)) > 80 {
 				bl.Block, _ = DivideBlock(job.CategorySecond, bl.Text, 1, job.RuleBlock)
 				for _, bl_bl := range bl.Block {
-					processTableInBlock(bl_bl, job)
+					processTableInBlock(bl_bl, job, false)
 				}
 			}
 			FindProjectCode(bl.Text, job) //匹配项目编号
-			processTableInBlock(bl, job)
+			processTableInBlock(bl, job, true)
 			//新加 未分块table中未能解析到中标候选人,从正文中解析
 			if job.Winnerorder == nil || len(job.Winnerorder) == 0 {
 				bl.Winnerorder = winnerOrderEntity.Find(bl.Text, true, 1)
@@ -86,14 +86,18 @@ func AnalyStart(job *util.Job) {
 	}
 }
 
-func processTableInBlock(bl *util.Block, job *util.Job) {
+func processTableInBlock(bl *util.Block, job *util.Job, packageFlag bool) {
 	//块中再查找表格(块,处理完把值赋到块)
 	tabs, _ := ComputeConRatio(bl.Text, 2)
 	for _, tab := range tabs {
 		job.HasTable = 1
 		//添加标识:文本中有table
 		tabres := AnalyTableV2(tab, job.Category, bl.Title, tab.Text(), 2, job.SourceMid, job.RuleBlock) //解析表格入口 返回:汇总表格对象
-		processTableResult(tabres, bl, job)                                                              //分析table解析结果
+		if packageFlag {
+			tabres.PackageMap = nil
+			tabres.IsMultiPackage = false
+		}
+		processTableResult(tabres, bl, job) //分析table解析结果
 		if bl.Title == "" && tabres.BlockTag != "" {
 			bl.Title = tabres.BlockTag
 		}