prompt.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. package prompt
  2. import (
  3. "data_ai/ai"
  4. "data_ai/clean"
  5. "data_ai/ul"
  6. qu "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  7. "strings"
  8. )
  9. // 获取分类信息...
  10. func AcquireClassInfo(detail string, title string) (string, string) {
  11. top_content := PromptToptypeFieldText(detail, title)
  12. top_zp, ok := PostZhiPuClassInfo(top_content)
  13. if !ok {
  14. return "", ""
  15. }
  16. //根据一级分类识别,获取toptype和subtype
  17. var toptype, subtype string //标准化的一级、二级分类
  18. toptype_ai, _ := top_zp["信息分类"].(string)
  19. tpInfo := ul.ToptypeDict[toptype_ai]
  20. if tpInfo != nil {
  21. toptype = tpInfo.Topetype
  22. subtype = tpInfo.Subtype
  23. } else { //匹配结果为非正规toptype,如:询价公告(66993a9d66cf0db42a5597af)
  24. for top, reg := range ul.ToptypeRegs {
  25. if reg.MatchString(toptype_ai) {
  26. if tpInfo = ul.ToptypeDict[top]; tpInfo != nil { //ToptypeRegs中预告公告、验收公告、合同公告直接获取subtype
  27. toptype = tpInfo.Topetype
  28. subtype = tpInfo.Subtype
  29. break
  30. }
  31. }
  32. }
  33. }
  34. if toptype == "" || tpInfo == nil {
  35. return "", ""
  36. }
  37. //获取二级分类
  38. sub_zp := map[string]interface{}{}
  39. if subtype == "" {
  40. sub_content := PromptSubtypeFieldText(detail, title, toptype, tpInfo)
  41. sub_zp, ok = PostZhiPuClassInfo(sub_content)
  42. if !ok {
  43. return "", ""
  44. }
  45. subtype_ai, _ := sub_zp["信息分类"].(string)
  46. subtype = tpInfo.SubtypeDict[subtype_ai]
  47. if subtype == "" && tpInfo.SubtypeRegs != nil { //二级分类校正
  48. for sub, reg := range tpInfo.SubtypeRegs {
  49. if reg.MatchString(subtype_ai) {
  50. subtype = sub
  51. break
  52. }
  53. }
  54. }
  55. }
  56. //subtype到此还可能为空,给默认值
  57. if subtype == "" {
  58. subtype = "其它"
  59. }
  60. return toptype, subtype
  61. }
  62. // 根据抽取字段校正分类结果
  63. func CheckClassByOtherFileds(toptype_ai, subtype_ai string, data map[string]interface{}) (string, string) {
  64. toptype_rule := qu.ObjToString(data["toptype"])
  65. subtype_rule := qu.ObjToString(data["subtype"])
  66. //1、结果类 中标和成交错误校正
  67. s_winner := qu.ObjToString(data["s_winner"])
  68. winnerorder, _ := data["winnerorder"].([]interface{})
  69. if toptype_ai == "结果" && toptype_rule == "结果" {
  70. if (subtype_ai == "中标" && subtype_rule == "成交") || (subtype_ai == "成交" && subtype_rule == "中标") {
  71. if len(winnerorder) > 0 { //有中标候选人->中标
  72. return toptype_ai, "中标"
  73. }
  74. if s_winner != "" || data["bidamount"] != nil {
  75. return toptype_ai, "成交"
  76. }
  77. }
  78. }
  79. //2、招标、结果错误校正
  80. if toptype_ai != "结果" && toptype_rule == "结果" {
  81. //return toptype_rule,subtype_rule//默认规则为准
  82. if len(winnerorder) > 0 { //有中标候选人->中标
  83. //return toptype_rule, "中标"//这里subtype是否返回"中标"?
  84. return toptype_rule, subtype_rule //默认规则是正确的
  85. } else if s_winner != "" || data["bidamount"] != nil {
  86. return toptype_rule, subtype_rule
  87. } else {
  88. return toptype_ai, subtype_ai
  89. }
  90. } else if toptype_ai == "结果" && toptype_rule != "结果" {
  91. //return toptype_rule,subtype_rule//默认规则为准
  92. if len(winnerorder) > 0 { //有中标候选人->中标
  93. return toptype_ai, "中标" //这里subtype返回"中标",避免ai识别错误
  94. } else if s_winner != "" || data["bidamount"] != nil {
  95. return toptype_ai, "成交" //这里subtype返回"成交",避免ai识别错误
  96. } else {
  97. return toptype_ai, subtype_ai
  98. }
  99. }
  100. return toptype_ai, subtype_ai
  101. }
  102. // 获取外围抽取字段
  103. func AcquireExtractFieldInfo(detail string) map[string]interface{} {
  104. content := PromptFieldText(detail)
  105. zp := PostZhiPuInfo(content)
  106. return zp
  107. }
  108. // 获取是否为分包信息
  109. func AcquireIsPackageInfo(detail string) bool {
  110. content := PromptIsPackageText(detail)
  111. zp := PostZhiPuInfo(content)
  112. if qu.ObjToString(zp["分包"]) == "是" {
  113. return true
  114. }
  115. return false
  116. }
  117. // 获取标讯多包信息
  118. func AcquireMultiplePackageInfo(detail string) map[string]interface{} {
  119. content := PromptMultiplePackageText(detail)
  120. zp := PostZhiPuInfo(content)
  121. //后续在转格式...暂时先输出两个值
  122. pkg := map[string]interface{}{}
  123. s_winner, s_bidamount := "", 0.0
  124. win_arr, win_temp := []string{}, map[string]string{}
  125. if score := qu.Float64All(zp["分包信息score"]); score >= 90.0 {
  126. pkginfo := ul.IsMarkInterfaceMap(zp["分包信息"])
  127. for _, v := range pkginfo {
  128. winner := clean.CleanWinner(qu.ObjToString(v["中标单位"]))
  129. bidamount := clean.CleanMoney((v["中标金额"]))
  130. s_bidamount += bidamount
  131. if win_temp[winner] == "" && winner != "" {
  132. win_arr = append(win_arr, winner)
  133. win_temp[winner] = winner
  134. }
  135. }
  136. s_winner = strings.Join(win_arr, ",")
  137. pkg["s_winner"] = s_winner
  138. pkg["s_bidamount"] = s_bidamount
  139. }
  140. return pkg
  141. }
  142. // 请求质谱数据外围字段...
  143. func PostZhiPuInfo(content string) map[string]interface{} {
  144. zp, ok := map[string]interface{}{}, 0
  145. for {
  146. ok++
  147. if zp = ai.PostZhiPuAI(content); len(zp) > 0 {
  148. break
  149. }
  150. if ok >= 5 {
  151. break
  152. }
  153. }
  154. return zp
  155. }
  156. // 请求质谱数据-分类字段
  157. func PostZhiPuClassInfo(content string) (map[string]interface{}, bool) {
  158. zp := map[string]interface{}{}
  159. times := 0
  160. ok := false
  161. for {
  162. times++
  163. zp = ai.PostClassZhiPuAI(content)
  164. if len(zp) > 0 {
  165. ok = true
  166. break
  167. }
  168. if times >= 5 {
  169. break
  170. }
  171. }
  172. return zp, ok
  173. }