extract.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package extract
  2. import (
  3. "data_ai/clean"
  4. "data_ai/prompt"
  5. "data_ai/ul"
  6. log "github.com/donnie4w/go-logger/logger"
  7. qu "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  8. "sync"
  9. "unicode/utf8"
  10. )
  11. // 抽取结构字段
  12. func ExtractFieldInfo(sid string, eid string, name string) {
  13. q := map[string]interface{}{
  14. "_id": map[string]interface{}{
  15. "$gt": ul.StringTOBsonId(sid),
  16. "$lte": ul.StringTOBsonId(eid),
  17. },
  18. }
  19. pool_mgo := make(chan bool, 50)
  20. wg_mgo := &sync.WaitGroup{}
  21. dataArr, _ := ul.SourceMgo.Find(name, q, nil, nil)
  22. for k, v := range dataArr {
  23. if k%100 == 0 {
  24. log.Debug(k, "~", ul.BsonTOStringId(v["_id"]))
  25. }
  26. infoformat := qu.IntAll(v["infoformat"])
  27. if infoformat != 1 {
  28. continue
  29. }
  30. pool_mgo <- true
  31. wg_mgo.Add(1)
  32. go func(v map[string]interface{}) {
  33. defer func() {
  34. <-pool_mgo
  35. wg_mgo.Done()
  36. }()
  37. tmpid := ul.BsonTOStringId(v["_id"])
  38. data := ResolveInfo(v)
  39. if data == nil || tmpid == "" {
  40. }
  41. }(v)
  42. }
  43. wg_mgo.Wait()
  44. }
  45. // 获取处理数据...
  46. func ResolveInfo(v map[string]interface{}) map[string]interface{} {
  47. detail := qu.ObjToString(v["detail"])
  48. title := qu.ObjToString(v["title"])
  49. if utf8.RuneCountInString(detail) < 100 {
  50. return map[string]interface{}{}
  51. }
  52. //分包判断,获取信息
  53. ispkg, pkg := false, map[string]interface{}{}
  54. if ispkg = prompt.AcquireIsPackageInfo(detail); ispkg {
  55. pkg = prompt.AcquireMultiplePackageInfo(detail)
  56. }
  57. //获取外围字段数据
  58. f_info := prompt.AcquireExtractFieldInfo(detail)
  59. //外围字段清洗
  60. f_data := clean.CleanFieldInfo(f_info, pkg)
  61. //获取分类字段数据
  62. s_toptype, s_subtype := "", ""
  63. if qu.ObjToString(v["toptype"]) == "拟建" {
  64. s_toptype, s_subtype = "拟建", "拟建"
  65. } else {
  66. s_toptype, s_subtype = prompt.AcquireClassInfo(detail, title)
  67. }
  68. if s_toptype != "" {
  69. f_data["s_toptype"] = s_toptype
  70. f_data["s_subtype"] = s_subtype
  71. }
  72. //此次最终校验
  73. f_data = clean.CleanFinallyInfo(f_data)
  74. return f_data
  75. }
  76. // 暂时不启用...无限重试
  77. func RunResetUpdateFieldInfo(arr []string, name string, s_name string) {
  78. //log.Debug("开始重置更新...", len(arr))
  79. //reset := []string{}
  80. //for k, v := range arr {
  81. // log.Debug("...", k, "...", v)
  82. // data := ul.SourceMgo.FindById(name, v)
  83. // content := PromptFieldText(qu.ObjToString(data["detail"]))
  84. // zp, ok := map[string]interface{}{}, 0
  85. // for {
  86. // ok++
  87. // if zp = ai.PostZhiPuAI(content); len(zp) > 0 {
  88. // break
  89. // }
  90. // if ok >= 5 {
  91. // log.Debug("请求数据失败...", v)
  92. // reset = append(reset, v)
  93. // break
  94. // }
  95. // }
  96. // ul.SourceMgo.UpdateById(s_name, v, map[string]interface{}{
  97. // "$set": map[string]interface{}{
  98. // "zhipu": zp,
  99. // },
  100. // })
  101. //}
  102. //if len(reset) > 0 { //无限尝试
  103. // RunResetUpdateFieldInfo(reset, name, s_name)
  104. //}
  105. //log.Debug("本轮重置更新结束......")
  106. }