123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- package extract
- import (
- "data_ai/clean"
- "data_ai/prompt"
- "data_ai/ul"
- log "github.com/donnie4w/go-logger/logger"
- qu "jygit.jydev.jianyu360.cn/data_processing/common_utils"
- "sync"
- "unicode/utf8"
- )
- // 识别结构化字段
- func ExtractFieldInfo(sid string, eid string, name string) {
- q := map[string]interface{}{
- "_id": map[string]interface{}{
- "$gt": ul.StringTOBsonId(sid),
- "$lte": ul.StringTOBsonId(eid),
- },
- }
- pool_mgo := make(chan bool, 50)
- wg_mgo := &sync.WaitGroup{}
- dataArr, _ := ul.SourceMgo.Find(name, q, nil, nil)
- for k, v := range dataArr {
- if k%100 == 0 {
- log.Debug(k, "~", ul.BsonTOStringId(v["_id"]))
- }
- infoformat := qu.IntAll(v["infoformat"])
- if infoformat != 1 {
- continue
- }
- pool_mgo <- true
- wg_mgo.Add(1)
- go func(v map[string]interface{}) {
- defer func() {
- <-pool_mgo
- wg_mgo.Done()
- }()
- tmpid := ul.BsonTOStringId(v["_id"])
- data := ResolveInfo(v)
- if len(data) > 0 || tmpid == "" {
- ul.SourceMgo.UpdateById(name, tmpid, map[string]interface{}{
- "$set": map[string]interface{}{"ai_zhipu": data},
- })
- }
- }(v)
- }
- wg_mgo.Wait()
- log.Debug("is over ...", sid, "~", eid)
- }
- // 获取处理数据...
- func ResolveInfo(v map[string]interface{}) map[string]interface{} {
- detail := qu.ObjToString(v["detail"])
- title := qu.ObjToString(v["title"])
- f_data := map[string]interface{}{}
- if utf8.RuneCountInString(detail) < 100 {
- return f_data
- }
- //获取外围字段数据
- f_info := prompt.AcquireExtractFieldInfo(detail)
- //分包判断-获取信息
- ispkg, pkg := false, map[string]interface{}{}
- if ispkg = prompt.AcquireIsPackageInfo(detail); ispkg {
- f_info["ispkg"] = ispkg
- if pkg = prompt.AcquireMultiplePackageInfo(detail); len(pkg) > 0 {
- f_info["s_pkg"] = pkg
- }
- }
- //获取分类字段数据
- s_toptype, s_subtype := "", ""
- if qu.ObjToString(v["toptype"]) == "拟建" {
- s_toptype, s_subtype = "拟建", "拟建"
- } else {
- s_toptype, s_subtype = prompt.AcquireClassInfo(detail, title)
- }
- f_info["s_toptype"] = s_toptype
- f_info["s_subtype"] = s_subtype
- //字段清洗
- f_data = clean.CleanFieldInfo(f_info)
- return f_data
- }
- // 暂时不启用...无限重试
- func RunResetUpdateFieldInfo(arr []string, name string, s_name string) {
- //log.Debug("开始重置更新...", len(arr))
- //reset := []string{}
- //for k, v := range arr {
- // log.Debug("...", k, "...", v)
- // data := ul.SourceMgo.FindById(name, v)
- // content := PromptFieldText(qu.ObjToString(data["detail"]))
- // zp, ok := map[string]interface{}{}, 0
- // for {
- // ok++
- // if zp = ai.PostZhiPuAI(content); len(zp) > 0 {
- // break
- // }
- // if ok >= 5 {
- // log.Debug("请求数据失败...", v)
- // reset = append(reset, v)
- // break
- // }
- // }
- // ul.SourceMgo.UpdateById(s_name, v, map[string]interface{}{
- // "$set": map[string]interface{}{
- // "zhipu": zp,
- // },
- // })
- //}
- //if len(reset) > 0 { //无限尝试
- // RunResetUpdateFieldInfo(reset, name, s_name)
- //}
- //log.Debug("本轮重置更新结束......")
- }
|