tasks.py 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016
  1. import time
  2. from tihuan import tihuan
  3. from tihuan_az import tihuan_az
  4. from buchong import buchong
  5. from fuzhu_util import fuzhu_util
  6. from f_youqi import f_youqi
  7. import re
  8. from config import simplemodel
  9. from template import expression
  10. from fallback import fallback
  11. from dianceng import dianceng
  12. from mianceng import mianceng
  13. from lingji import lingji
  14. from jieheceng import jieheceng
  15. from celery_app import celery_app
  16. from postprocess import postprocess
  17. from extra import extra, need_extra
  18. from huansuan import callzaihuansuan
  19. import json
  20. import dedata
  21. import chromadb
  22. from feiyong import feiyong_chaogao
  23. from pymongo import MongoClient
  24. from anzhuangjsj import anzhuangjsj
  25. uri="mongodb://owner:Pheecian1@47.101.198.30:27017/baojia"
  26. mongoclient=MongoClient(uri)
  27. db = mongoclient['baojia']
  28. dbcollection=db['qdxm']
  29. print("chroma")
  30. client = chromadb.HttpClient(host='47.101.198.30',port=8000)
  31. collection = client.get_or_create_collection(name="tj_de_bge", metadata={'hnsw:search_ef':15})
  32. azcollection = client.get_or_create_collection(name="az_de_bge", metadata={'hnsw:search_ef':15})
  33. cuoshi_collection = client.get_or_create_collection(name="tj_cuoshi_bge")
  34. menchuang_collection = client.get_or_create_collection(name="tj_menchuang_bge")
  35. qita_collection = client.get_or_create_collection(name="tj_qita_bge")
  36. from FlagEmbedding import FlagModel
  37. print("model")
  38. azmodel = FlagModel('/mnt/d/Develop/az/az_encoder_only_base_bge-large-zh-v1.5')
  39. model = FlagModel('/mnt/d/Develop/bge/test2_encoder_only_base_bge-large-zh-v1.5')
  40. cuoshi_model = FlagModel('cuoshi_encoder_only_base_bge-large-zh-v1.5/cuoshi_encoder_only_base_bge-large-zh-v1.5')
  41. from sentence_transformers import CrossEncoder
  42. azce = CrossEncoder('/mnt/d/Develop/az/models/reranker-chinese-macbert-large-gooaq-bce-4/final')
  43. ce = CrossEncoder('/mnt/d/Develop/celery/final/final')
  44. cuoshi_ce = CrossEncoder('cuoshi_reranker/cuoshi_reranker/final')
  45. with open("hunningtu_rule", "r") as f:
  46. content = f.read()
  47. obj = json.loads(content)
  48. with open("nantong_rule", "r") as f:
  49. content = f.read()
  50. obj2 = json.loads(content)
  51. with open("basic_rule", "r") as f:
  52. content = f.read()
  53. basic = json.loads(content)
  54. with open("menchuang_rule", "r") as f:
  55. content = f.read()
  56. menchuang = json.loads(content)
  57. with open("incremental_rule", "r") as f:
  58. content = f.read()
  59. incremental = json.loads(content)
  60. with open("label_name", "r") as f:
  61. content = f.read()
  62. label_name = json.loads(content)
  63. with open("name_label", "r") as f:
  64. content = f.read()
  65. name_label = json.loads(content)
  66. with open("name_dw", "r") as f:
  67. content = f.read()
  68. name_dw = json.loads(content)
  69. with open("label_dw", "r") as f:
  70. content = f.read()
  71. label_dw = json.loads(content)
  72. with open("fuzhu_candidate", "r") as f:
  73. content = f.read()
  74. fuzhu_candidate = json.loads(content)
  75. with open("az_fuzhu_candidate", "r") as f:
  76. content = f.read()
  77. az_fuzhu_candidate = json.loads(content)
  78. THRESHOLD=0.8####adjust it
  79. print("client")
  80. import os
  81. from openai import OpenAI
  82. import requests
  83. aiclient = OpenAI(
  84. #api_key=os.getenv("DASHSCOPE_API_KEY"),
  85. api_key=os.getenv("ZAI_API_KEY"),
  86. #base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
  87. base_url="https://open.bigmodel.cn/api/paas/v4/",
  88. timeout=60
  89. )
  90. qwclient = OpenAI(
  91. # 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx",
  92. #api_key=os.getenv("DASHSCOPE_API_KEY"),
  93. api_key=os.getenv("MS_API_KEY"),
  94. #base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
  95. base_url="https://api-inference.modelscope.cn/v1/",
  96. timeout=60
  97. )
  98. dsclient = OpenAI(
  99. # 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx",
  100. #api_key=os.getenv("DASHSCOPE_API_KEY"),
  101. api_key=os.getenv("DS_API_KEY"),
  102. #base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
  103. base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
  104. timeout=60
  105. )
  106. ssclient = OpenAI(
  107. api_key=os.getenv("SS_API_KEY"), # 此处传token,不带Bearer
  108. base_url="https://chat.intern-ai.org.cn/api/v1/",
  109. timeout=60
  110. )
  111. simpleclient = ssclient
  112. def has_chinese(text):
  113. pattern = re.compile(r'[\u4e00-\u9fff]+')
  114. result = pattern.search(text)
  115. return True if result else False
  116. def analyze(json_string):
  117. obj = json.loads(json_string)
  118. bz = None
  119. if 'bz_selected' in obj:
  120. bz = obj['bz_selected']
  121. bh = bz['BZBH']
  122. bh_list = []
  123. for entry in bh:
  124. bh_list.append([entry, bh[entry], bz['SM'][entry]])
  125. print(bh_list)
  126. return bh_list,obj['bz_selected2']
  127. def select_fuzhu_az(input, label, aiclient, qwclient, client):
  128. if label_name[input[0]] in az_fuzhu_candidate:
  129. print(input[0])
  130. print(input[1][0])
  131. print(input[1][1])
  132. return fuzhu_util(input[0], [x[2] for x in input[1][0]], label, aiclient, qwclient, client),input[1][1],input[1][0]
  133. return [],{},[]
  134. def select_fuzhu(input, label, aiclient, qwclient, client):
  135. if label_name[input[0]] in fuzhu_candidate:
  136. print(input[0])
  137. print(input[1][0])
  138. print(input[1][1])
  139. return fuzhu_util(input[0], [x[2] for x in input[1][0]], label, aiclient, qwclient, client),input[1][1],input[1][0]
  140. return [],{},[]
  141. def callzailonggu_0113(data):
  142. time.sleep(1)
  143. completion = aiclient.chat.completions.create(
  144. # 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
  145. model="glm-4.5-flash",
  146. #model="ZhipuAI/GLM-4.5",
  147. #model="qwen3-4b",
  148. messages=[
  149. {"role": "system", "content": "You are a helpful assistant."},
  150. {"role": "user", "content": " 天棚工程有多种做法,包括单纯抹灰,单纯天棚面层,也可以制作龙骨并在龙骨上安装面层等。龙骨包括方木龙骨,轻钢龙骨,铝合金龙骨等。 现在给定一工作内容如下: " + data['label'] + " " + data['mc'] + " " + data['tz'] + ", 计量单位为" + data['dw'] + ", 请问该工作内容中包括了龙骨吗?"},
  151. ],
  152. # Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
  153. # 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
  154. #extra_body={"enable_thinking": False},
  155. extra_body={"thinking": {"type": "disabled"}},
  156. )
  157. json_string = completion.choices[0].message.content
  158. print(json_string)
  159. time.sleep(1)
  160. completion = simpleclient.chat.completions.create(
  161. # 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
  162. model=simplemodel(),
  163. messages=[
  164. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  165. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了关于是否包括龙骨的判断,请将该判断输出。 例如:"+'''
  166. {
  167. '判断':'不包括'
  168. }
  169. '''},
  170. ],
  171. # Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
  172. # 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
  173. #extra_body={"enable_thinking": False},
  174. extra_body={"thinking": {"type": "disabled"}},
  175. )
  176. json_string = completion.choices[0].message.content
  177. print(json_string)
  178. return json_string
  179. def callzaikuailiao_0112(data):
  180. time.sleep(1)
  181. completion = aiclient.chat.completions.create(
  182. # 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
  183. model="glm-4.5-air",
  184. #model="ZhipuAI/GLM-4.5",
  185. #model="qwen3-4b",
  186. messages=[
  187. {"role": "system", "content": "You are a helpful assistant."},
  188. {"role": "user", "content": " 墙柱面有多种做法,包括单纯抹灰,镶贴块料面层,使用墙板等。块料面层常见的有石材块料面板,瓷砖,面砖,假麻石块等。 现在给定一工作内容如下: " + data['label'] + " " + data['mc'] + " " + data['tz'] + ", 计量单位为" + data['dw'] + ", 请问该工作内容中包括了块料面层施工吗?"},
  189. ],
  190. # Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
  191. # 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
  192. #extra_body={"enable_thinking": False},
  193. extra_body={"thinking": {"type": "disabled"}},
  194. )
  195. json_string = completion.choices[0].message.content
  196. print(json_string)
  197. time.sleep(1)
  198. completion = simpleclient.chat.completions.create(
  199. # 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
  200. model=simplemodel(),
  201. messages=[
  202. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  203. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了关于是否包括块料面层施工的判断,请将该判断输出。 例如:"+'''
  204. {
  205. '判断':'不包括'
  206. }
  207. '''},
  208. ],
  209. # Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
  210. # 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
  211. #extra_body={"enable_thinking": False},
  212. extra_body={"thinking": {"type": "disabled"}},
  213. )
  214. json_string = completion.choices[0].message.content
  215. print(json_string)
  216. return json_string
  217. def callzaikuailiao(data):
  218. time.sleep(1)
  219. completion = aiclient.chat.completions.create(
  220. # 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
  221. model="glm-4.5-flash",
  222. #model="ZhipuAI/GLM-4.5",
  223. #model="qwen3-4b",
  224. messages=[
  225. {"role": "system", "content": "You are a helpful assistant."},
  226. {"role": "user", "content": " 楼地面有多种做法,包括整体面层,块料面层,木地板等。块料面层常见的有石材块料面板,缸砖,马赛克,假麻石块,地砖,橡胶塑料板等。 现在给定一工作内容如下: " + data['label'] + " " + data['mc'] + " " + data['tz'] + ", 计量单位为" + data['dw'] + ", 请问该工作内容中包括了块料面层施工吗?"},
  227. ],
  228. # Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
  229. # 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
  230. #extra_body={"enable_thinking": False},
  231. extra_body={"thinking": {"type": "disabled"}},
  232. )
  233. json_string = completion.choices[0].message.content
  234. print(json_string)
  235. time.sleep(1)
  236. completion = simpleclient.chat.completions.create(
  237. # 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
  238. model=simplemodel(),
  239. messages=[
  240. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  241. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了关于是否包括块料面层施工的判断,请将该判断输出。 例如:"+'''
  242. {
  243. '判断':'不包括'
  244. }
  245. '''},
  246. ],
  247. # Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
  248. # 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
  249. #extra_body={"enable_thinking": False},
  250. extra_body={"thinking": {"type": "disabled"}},
  251. )
  252. json_string = completion.choices[0].message.content
  253. print(json_string)
  254. return json_string
  255. def youqi_(tz):
  256. completion = aiclient.chat.completions.create(
  257. # 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
  258. model="glm-4.5-air",
  259. #model="qwen3-4b",
  260. messages=[
  261. {"role": "system", "content": "You are a helpful assistant.请将结果以json格式输出"},
  262. {"role": "user", "content": " 金属结构的油漆一般是多层涂刷,常规的是包括底漆跟面漆。也可能是底漆,中间漆再加面漆。金属结构有时需要涂刷防火涂料。但是防火涂料跟油漆不是一回事。现在给定一工作内容如下: " + tz + ", 请将该工作内容中的油漆相关内容原封不动地抽取出来。请勿抽取防火涂料相关内容。如果工作内容中完全没有提到油漆,则返回”无“"},
  263. ],
  264. # Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
  265. # 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
  266. #extra_body={"enable_thinking": False},
  267. extra_body={"thinking": {"type": "disabled"}},
  268. )
  269. json_string = completion.choices[0].message.content
  270. print(json_string)
  271. return json_string
  272. def callzaiclarify(data):
  273. completion = aiclient.chat.completions.create(
  274. # 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
  275. model="glm-4.5-air",
  276. #model="qwen3-4b",
  277. messages=[
  278. {"role": "system", "content": "You are a helpful assistant."},
  279. {"role": "user", "content": " 管桩的清单工作内容描述可以分成两类,一类是打桩、压桩,属于桩基工程的一种,其工作内容计量的单位一般是米(m)或根。另一类是填芯,一般是向桩芯内浇混凝土,属于土建工程的一种,其配套的计量单位一般是立方米(m3),即浇混凝土的体积量。现在给定一工作内容如下: " + data['label'] + " " + data['mc'] + " " + data['tz'] + ", 计量单位为" + data['dw'] + ", 请问该工作内容属于填芯吗?"},
  280. ],
  281. # Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
  282. # 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
  283. #extra_body={"enable_thinking": False},
  284. extra_body={"thinking": {"type": "disabled"}},
  285. )
  286. json_string = completion.choices[0].message.content
  287. print(json_string)
  288. completion = simpleclient.chat.completions.create(
  289. # 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
  290. model=simplemodel(),
  291. messages=[
  292. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  293. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了关于是不是填芯的判断,请将该判断输出。请输出是或者否"},
  294. ],
  295. # Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
  296. # 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
  297. #extra_body={"enable_thinking": False},
  298. extra_body={"thinking": {"type": "disabled"}},
  299. )
  300. json_string = completion.choices[0].message.content
  301. print(json_string)
  302. return json_string
  303. def callzaidw(A,B):
  304. time.sleep(1)
  305. completion = aiclient.chat.completions.create(
  306. model='glm-4.5-air',
  307. ##stream=True,
  308. messages=[
  309. {"role": "system", "content": "You are a helpful assistant."},
  310. {"role": "user", "content": " 计量单位可以用名称或者符号表示,常用的符号包括表示米的符号m,表示千米的符号km,表示吨的符号t,表示千克的符号kg,表示平方米的符号m2,表示立方米的符号m3。也有计量单位很宽泛,比如“项”、“次”. 给定一个工作量计量单位,内容为" + A + ",记作A,再给定一个工作量计量单位,内容为" + B + ",记作B。若两个单位相等,请返回A=B。例如,“项”跟“次”是等价的,应返回A=B。若两个单位不相等,但是存在比例换算关系,请返回比例换算关系,例如A单位是m,B单位是10m, 则返回A=0.1*B。再例如,A单位是10m2,B单位是m2,则返回A=10*B。再例如,A单位是m3, B单位是1000m3,则返回A=0.001*B。若两个单位不相等,且不存在比例换算关系,请返回A<>B,例如A单位是m,B单位是m2,一个表示长度,一个表示面积,不存在比例关系,则返回A<>B。 "},
  311. ],
  312. #extra_body={"enable_thinking": False},
  313. extra_body={"thinking": {"type": "disabled"}},
  314. )
  315. json_string = completion.choices[0].message.content
  316. print(json_string)
  317. time.sleep(1)
  318. completion = simpleclient.chat.completions.create(
  319. # 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
  320. #model="THUDM/GLM-4-9B-0414",
  321. model=simplemodel(),
  322. #model="glm-4.5-flash",
  323. messages=expression(json_string),
  324. # Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
  325. # 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
  326. #extra_body={"enable_thinking": False},
  327. extra_body={"thinking": {"type": "disabled"}},
  328. )
  329. json_string = completion.choices[0].message.content
  330. print(json_string)
  331. return json_string
  332. def callzai(A,B,C):
  333. completion = qwclient.chat.completions.create(
  334. # 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
  335. #model="glm-4.5-flash",
  336. model="Qwen/Qwen3-32B",
  337. messages=[
  338. {"role": "system", "content": "You are a helpful assistant."},
  339. {"role": "user", "content": " 给定一条主定额,内容为" + A + ",记作A,再给定一条配套定额,内容为" + B + ",记作B。可以通过简单的组合,来表达对应的工作内容的数量,比如A+B可以表达,主定额的工作量加上配套定额的工作量;再比如,A+B*2可以表达, 主定额的工作量加上两倍的配套定额的工作量;再比如,A+B*(-2)可以表达, 主定额减去两倍的配套定额的工作量;再比如,A可以表示,不使用配套定额,仅表示主定额的工作量。现在给你一条工程量清单,内容为" + C + ",该条清单包含了主定额描述的工作内容,但是数量并不一定一致。请你找到清单中对应的描述(不需要考虑龙骨类型是否完全一致,不需要考虑混凝土强度等级是否完全一致,需要区分面层和找平找坡层),辨识出工作数量(砂浆保护层厚度跟砂浆找平层厚度不可合并),并组合A与B,表示出清单描述的对应工作数量。请给出分析过程,并请最终输出类似A+B、A+B*2、A-B*2的格式,不要输出A+2*B、A-2*B的格式。如果清单里相应工作量的描述不明确,请输出A作为答案 "},
  340. ],
  341. # Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
  342. # 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
  343. extra_body={"enable_thinking": False},
  344. #extra_body={"thinking": {"type": "disabled"}},
  345. )
  346. json_string = completion.choices[0].message.content
  347. print(json_string)
  348. if len(json_string) < 4:
  349. return "result:" + json_string
  350. completion = simpleclient.chat.completions.create(
  351. # 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
  352. model=simplemodel(),
  353. #model="THUDM/GLM-4-9B-0414",
  354. messages=[
  355. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  356. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个类似于A+B的表达式作为答案,请将该最终答案输出.如果文字中指出可能有两种答案,则只需要输出其中一种。例如" +'''
  357. [
  358. 'result' : 'A+B*-2'
  359. }
  360. 注意,只需要输出最终答案,不需要中间过程或者其他细节,只需要输出一种答案
  361. '''
  362. },
  363. ],
  364. # Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
  365. # 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
  366. #extra_body={"enable_thinking": False},
  367. extra_body={"thinking": {"type": "disabled"}},
  368. )
  369. json_string = completion.choices[0].message.content
  370. return json_string
  371. def transform(answer, input, entry):
  372. answers = answer.split("\n")
  373. answers = [x for x in answers if ':' in x and "A" in x]
  374. if len(answers) == 0:
  375. return input
  376. answers[0] = answers[0].split(',')[0]
  377. answer2 = answers[0].split(":")[1].replace(" ", "")
  378. if 'B' in answer2:
  379. answer2 = answer2.replace("B", 'BBB')
  380. answer2 = answer2.replace("A", input)
  381. answer2 = answer2.replace("BBB", "["+entry+"]")
  382. else:
  383. answer2 = answer2.replace("A", input)
  384. answer2 = answer2.replace("\'", "")
  385. answer2 = answer2.replace("\"", "")
  386. return answer2
  387. def zuhe(input, content, bianma):
  388. if bianma.startswith('01') and input in incremental and input != '17-176' and input != '17-177' and input != '17-179' and input != '17-180' and input != '17-181' and input != '15-33' and input != '1534' and input != '15-35' and input != '15-36' and input != '15-37' and input != '15-38' and input != '15-39' and input != '15-40' and input != '15-41':
  389. option = incremental[input]
  390. for entry in option:
  391. answer = callzai(name_label[input], name_label[entry], content)
  392. print("answer of callai for zuhe")
  393. print(answer)
  394. if 'B' in answer:
  395. return transform(answer, input, entry)
  396. return input
  397. else:
  398. return input
  399. def huansuan_highlevel(bianma, label, input,dw, tz):
  400. time.sleep(1)
  401. t = huansuan(input, dw, label)
  402. if t == 0 or bianma.startswith('030901013'):## 灭火器
  403. dw1 = input
  404. dw1 = dw1.lower()
  405. dw1 = dw1.replace("水平投影面积", "")
  406. dw1 = dw1.replace("每1m2建筑面积", "m2")
  407. dw2 = label_dw[label]
  408. dw2 = dw2.lower()
  409. dw2 = dw2.replace("水平投影面积", "")
  410. dw2 = dw2.replace("每1m2建筑面积", "m2")
  411. answer = callzaihuansuan(bianma, label, dw1,dw2,tz, aiclient, qwclient, simpleclient)
  412. answers = answer.split("\n")
  413. answers = [x for x in answers if ':' in x and "A" in x]
  414. answers = [x for x in answers if '=' in x or '<>' in x]
  415. print("answer of callzaihuansuan")
  416. print(answers)
  417. if len(answers) == 0:
  418. return 0
  419. answer2 = answers[0].split(":")[1].replace(" ", "")
  420. if "<>" in answer2:
  421. return 0
  422. answer2 = answer2.replace("\'", "")
  423. answer2 = answer2.replace("\"", "")
  424. answer2 = answer2.split("=")[1]
  425. if answer2 == "B":
  426. return 1
  427. answer2=answer2.replace("B", "")
  428. answer2=answer2.replace("*", "")
  429. answer2=answer2.replace("x", "")
  430. answer2=answer2.replace(",", "")
  431. answer2=answer2.replace(",", "")
  432. answer2=answer2.replace("×", "")
  433. print(answer2)
  434. return float(answer2)
  435. else:
  436. if '人工修边坡' in label:
  437. return t * 0.1
  438. else:
  439. return t
  440. def huansuan(input, dw, label):
  441. dw1 = input
  442. dw1 = dw1.lower()
  443. dw1 = dw1.replace("水平投影面积", "")
  444. dw1 = dw1.replace("每1m2建筑面积", "m2")
  445. dw2 = label_dw[label]
  446. dw2 = dw2.lower()
  447. dw2 = dw2.replace("水平投影面积", "")
  448. dw2 = dw2.replace("每1m2建筑面积", "m2")
  449. if dw1 == dw2:
  450. return 1
  451. if dw1 == 'm2' and dw2 == '10m2':
  452. return 0.1
  453. if dw1 == 'm2' and dw2 == '100m2':
  454. return 0.01
  455. if dw1 == 'm2' and dw2 == '1000m2':
  456. return 0.001
  457. if dw1 == 'm' and dw2 == '10m':
  458. return 0.1
  459. if dw1 == 'm' and dw2 == '100m':
  460. return 0.01
  461. if dw1 == 'm3' and dw2 == '10m3':
  462. return 0.1
  463. if dw1 == 'm3' and dw2 == '100m3':
  464. return 0.01
  465. if dw1 == 'm3' and dw2 == '1000m3':
  466. return 0.001
  467. if dw1 == '个' and dw2 == '10个':
  468. return 0.1
  469. if dw1 == '套' and dw2 == '10套':
  470. return 0.1
  471. if dw1 == '具' and dw2 == '10具':
  472. return 0.1
  473. if dw1 == 'kg' and dw2 == '100kg':
  474. return 0.01
  475. if dw1 == '个' and dw2 == '套':
  476. return 1
  477. if dw1 == '个' and dw2 == '10套':
  478. return 0.1
  479. if dw1 == '个' and dw2 == '台':
  480. return 1
  481. if dw1 == '个' and dw2 == '10台':
  482. return 0.1
  483. if dw1 == '台' and dw2 == '个':
  484. return 1
  485. if dw1 == '台' and dw2 == '10个':
  486. return 0.1
  487. if dw1 == '台' and dw2 == '套':
  488. return 1
  489. if dw1 == '台' and dw2 == '10套':
  490. return 0.1
  491. if dw1 == '组' and dw2 == '10组':
  492. return 0.1
  493. if dw1 == '组' and dw2 == '套':
  494. return 1
  495. if dw1 == '组' and dw2 == '10套':
  496. return 0.1
  497. if dw1 == 'm' and dw2 == '100m单线':
  498. return 0.01
  499. else:
  500. answer = callzaidw(dw1,dw2)
  501. answers = answer.split("\n")
  502. answers = [x for x in answers if ':' in x and "A" in x]
  503. answers = [x for x in answers if '=' in x or '<>' in x]
  504. answers = [x for x in answers if not has_chinese(x)]
  505. print(answers)
  506. if len(answers) == 0:
  507. return 0
  508. answer2 = answers[0].split(":")[1].replace(" ", "")
  509. if "<>" in answer2:
  510. return 0
  511. answer2 = answer2.replace("\'", "")
  512. answer2 = answer2.replace("\"", "")
  513. answer2 = answer2.replace(",", "")
  514. answer2 = answer2.split("=")[1]
  515. if answer2 == "B":
  516. return 1
  517. answer2=answer2.replace("B", "")
  518. answer2=answer2.replace("*", "")
  519. answer2=answer2.replace("x", "")
  520. answer2=answer2.replace("×", "")
  521. try:
  522. return float(answer2)
  523. except:
  524. return 1
  525. def clarify(data):
  526. data['tz'] = data['tz'].replace('DTG', '')
  527. data['tz'] = data['tz'].replace("聚合物水泥砂浆修补墙面", "")
  528. data['tz'] = data['tz'].replace('DTA', '')
  529. data['tz'] = data['tz'].replace('DS M15', '1:3水泥砂浆')
  530. data['tz'] = data['tz'].replace('DSM15', '1:3水泥砂浆')
  531. data['tz'] = data['tz'].replace('DP M15', '1:3水泥砂浆')
  532. data['tz'] = data['tz'].replace('DPM15', '1:3水泥砂浆')
  533. data['tz'] = data['tz'].replace('DS M20', '1:2.5水泥砂浆')
  534. data['tz'] = data['tz'].replace('DSM20', '1:2.5水泥砂浆')
  535. data['tz'] = data['tz'].replace('DP M20', '1:2.5水泥砂浆')
  536. data['tz'] = data['tz'].replace('DPM20', '1:2.5水泥砂浆')
  537. data['tz'] = data['tz'].replace('DP(DCA)M20', '1:2.5水泥砂浆')
  538. data['tz'] = data['tz'].replace('DP(DCA) M20', '1:2.5水泥砂浆')
  539. data['tz'] = data['tz'].replace('DP(DCA)M5', '1:1:6混合砂浆')
  540. data['tz'] = data['tz'].replace('DP(DCA) M5', '1:1:6混合砂浆')
  541. data['tz'] = data['tz'].replace('DP M5', '1:1:6混合砂浆')
  542. data['tz'] = data['tz'].replace('DPM5', '1:1:6混合砂浆')
  543. data['tz'] = data['tz'].replace('DP MS', '1:1:6混合砂浆')
  544. data['tz'] = data['tz'].replace('DPMS', '1:1:6混合砂浆')
  545. data['tz'] = data['tz'].replace('DP(DCA)M10', '1:0.5:3混合砂浆')
  546. data['tz'] = data['tz'].replace('DP(DCA) M10', '1:0.5:3混合砂浆')
  547. data['tz'] = data['tz'].replace('DP M10', '1:0.5:3混合砂浆')
  548. data['tz'] = data['tz'].replace('DPM10', '1:0.5:3混合砂浆')
  549. data['tz'] = data['tz'].replace("水泥基防水涂料", "水泥基渗透结晶防水涂料")
  550. data['tz'] = data['tz'].replace("回光灯带", "回光灯槽")
  551. data['mc'] = data['mc'].replace("回光灯带", "回光灯槽")
  552. data['tz'] = data['tz'].replace("自流平", "自流平地面")
  553. data['tz'] = data['tz'].replace("JS防水涂料", "聚合物水泥防水涂料")
  554. data['tz'] = data['tz'].replace("聚合物水泥砂浆", "防水砂浆")
  555. data['tz'] = data['tz'].replace("丝杆", "丝杆吊筋")
  556. data['tz_bak'] = data['tz']
  557. if data['bianma'].startswith("010301"):##打桩
  558. print("clarify")
  559. result = callzaiclarify(data)
  560. if "是" in result:
  561. data['mc'] = data['mc'] + '填芯'
  562. return data, False
  563. elif data['bianma'].startswith("010606012"): ##钢支架
  564. if '镀锌方管' in data['tz'] or '镀锌圆管' in data['tz'] or '镀锌钢管' in data['tz'] or '镀锌角钢' in data['tz']:
  565. data['tz'] = data['tz'].replace('支架', '骨架')
  566. data['tz'] = data['tz'].replace('基架', '骨架')
  567. data['mc'] = '钢骨架'
  568. return data, False
  569. elif data['bianma'].startswith("010507001"): ##散水、坡道
  570. data['tz'] = lingji(data['tz'], aiclient, qwclient)
  571. data['tz'] = dianceng(data['tz'], aiclient, qwclient)
  572. data['tz'] = mianceng(data['tz'], aiclient, qwclient)
  573. data['tz'] = jieheceng(data['tz'], aiclient, qwclient)
  574. return data, False
  575. elif data['bianma'].startswith("0109"): ##防水
  576. data['tz'] = lingji(data['tz'], aiclient, qwclient)
  577. data['tz'] = dianceng(data['tz'], aiclient, qwclient)
  578. data['tz'] = jieheceng(data['tz'], aiclient, qwclient)
  579. return data, False
  580. elif data['bianma'].startswith("0111"):
  581. data['tz'] = data['tz'].replace("卷材面层", "面层")
  582. if data['bianma'].startswith("011107"):##台阶
  583. data['mc'] = '台阶面'
  584. data['tz'] = jieheceng(data['tz'], aiclient, qwclient)
  585. result = callzaikuailiao(data)
  586. if '不' in result:
  587. return data, False
  588. return data, True
  589. elif data['bianma'].startswith("0112"):
  590. if '镀锌方管' in data['tz'] or '镀锌圆管' in data['tz'] or '镀锌钢管' in data['tz'] or '镀锌角钢' in data['tz']:
  591. data['tz'] = data['tz'].replace('支架', '骨架')
  592. data['tz'] = data['tz'].replace('基架', '骨架')
  593. data['tz'] = data['tz'].replace("铝单板", "铝单板幕墙")
  594. data['tz'] = data['tz'].replace("阻燃板", "细木工板")
  595. data['tz'] = data['tz'].replace("阻燃基层板", "细木工板")
  596. data['tz'] = data['tz'].replace("岩棉板", "岩棉吸音板")
  597. data['tz'] = data['tz'].replace("吸音材料", "岩棉吸音板")
  598. data['tz'] = data['tz'].replace("水泥纤维板", "水泥压力板")
  599. if '防潮层' in data['tz'] or '防水砂浆' in data['tz']:
  600. data['mc']='墙柱面防水(防潮)'
  601. result = callzaikuailiao_0112(data)
  602. if '不' in result:
  603. return data, False
  604. return data, True
  605. elif data['bianma'].startswith("0113"):
  606. result = callzailonggu_0113(data)
  607. if '不' in result:
  608. return data, False
  609. if not '上人' in data['tz']:
  610. data['tz']=data['tz'].replace('龙骨','不上人型龙骨')
  611. data['tz']=data['tz'].replace('铝格栅','铝格栅吊顶')
  612. data['tz']=data['tz'].replace('纸面石膏板','纸面石膏板面层')
  613. return data, True
  614. elif data['bianma'].startswith("0117"):
  615. data['mc']=data['mc'].replace('线条','檐沟')
  616. data['tz']=data['tz'].replace('线条','檐沟')
  617. return data, False
  618. elif data['bianma'].startswith('0308'):
  619. data['tz'] = data['tz'].replace('增强柔性石墨板', '增强柔性石墨板制作三通补强圈')
  620. return data, False
  621. else:
  622. return data, False
  623. from redis.exceptions import TimeoutError
  624. @celery_app.task(autoretry_for=(TimeoutError,))
  625. def process_data(data:dict)-> dict:
  626. placeholder, kuailiao = clarify(data)
  627. label = data['mc'] + ' ' + data['tz']
  628. if data['bianma'].startswith("0117"):
  629. label = data['label'] + " " + data['mc'] + " " + data['tz']
  630. sentences = [label]
  631. if data['bianma'].startswith("0117"):
  632. embeddings = cuoshi_model.encode(sentences)
  633. elif data['bianma'].startswith('03'):
  634. embeddings = azmodel.encode(sentences)
  635. else:
  636. embeddings = model.encode(sentences)
  637. if data['bianma'].startswith("0117"):
  638. result = cuoshi_collection.query(query_embeddings=embeddings,n_results=25)
  639. elif data['bianma'].startswith('030810'):
  640. result = azcollection.query(query_embeddings=embeddings, n_results=10, where_document={"$contains": "低压法兰"})
  641. elif data['bianma'].startswith('030412'):
  642. result = azcollection.query(query_embeddings=embeddings, n_results=10, where_document={"$contains": "照明器具"})
  643. elif data['bianma'].startswith('030108'):
  644. result = azcollection.query(query_embeddings=embeddings, n_results=10, where_document={"$contains": "风机"})
  645. elif data['bianma'].startswith('030502007') or data['bianma'].startswith('030502008'):
  646. result = azcollection.query(query_embeddings=embeddings, n_results=10, where_document={"$contains": "布放光缆"})
  647. elif data['bianma'].startswith('03'):
  648. result = azcollection.query(query_embeddings=embeddings,n_results=25)
  649. else:
  650. result = collection.query(query_embeddings=embeddings,n_results=25)
  651. yqspecial=[]
  652. if data['bianma'].startswith('0106'):
  653. youqi = youqi_(data['tz'])
  654. if '无' not in youqi:
  655. yqspecial= f_youqi(data, youqi,collection,model,ce,name_label)
  656. d = result['documents'][0]
  657. print(d)
  658. if data['bianma'].startswith("0117"):
  659. ranks = cuoshi_ce.rank(label, d)
  660. elif data['bianma'].startswith('03'):
  661. ranks = azce.rank(label, d)
  662. else:
  663. ranks = ce.rank(label, d)
  664. if data['bianma'].startswith("0117"):
  665. cutoff = 0.6
  666. else:
  667. cutoff = THRESHOLD
  668. ranks = ranks[:10]
  669. match = [("6.2.1.1","6.3.1.1"),
  670. ("6.2.1.2", "6.3.1.2"),
  671. ("6.2.1.3", "6.3.1.3"),
  672. ("6.2.1.4", "6.3.1.4"),
  673. ("6.2.1.5", "6.3.1.5"),
  674. ("6.2.1.6", "6.3.1.6"),
  675. ("6.2.2.1", "6.3.2.1"),
  676. ("6.2.2.2", "6.3.2.2"),
  677. ("6.2.3.1", "6.3.3.1"),
  678. ("6.2.3.2", "6.3.3.2"),
  679. ("6.2.3.3", "6.3.3.3"),
  680. ("6.2.3.4", "6.3.3.4"),
  681. ("6.2.3.5", "6.3.3.5"),
  682. ("6.2.3.6", "6.3.3.6")]
  683. match2=[
  684. ("1.1.7", "nantong1.1.7"),
  685. ("nantong2.1.2", "2.1.2"),
  686. ("nantong3.1.2", "3.1.2"),
  687. ("nantong3.1.4", "3.1.4"),
  688. ("nantong3.1.5", "3.1.5"),
  689. ("3.2.10", "nantong3.2.10"),
  690. ("nantong4.1.1", "4.1.1"),
  691. ("nantong4.1.2", "4.1.2"),
  692. ("nantong4.1.3", "4.1.3"),
  693. ("4.1.4", "nantong4.1.4"),
  694. ("4.1.5", "nantong4.1.5"),
  695. ("4.1.7", "nantong4.1.7"),
  696. ("4.4", "nantong4.4"),
  697. ("nantong6", "6"),
  698. ("7.5", "nantong7.5"),
  699. ("nantong7.8", "7.8"),
  700. ("10.1.5", "nantong10.1.5"),
  701. ("10.1.2", "nantong10.1.2"),
  702. ("10.1.1", "nantong10.1.1"),
  703. ("nantong10.1.1.2", "10.1.1.2"),
  704. ("10.1.1.3", "nantong10.1.1.3"),
  705. ("nantong11.1.2.1", "11.1.2.1"),
  706. ("nantong11.1.2.2", "11.1.2.2"),
  707. ("nantong11.1.1", "11.1.1"),
  708. ("12.7", "nantong12.7"),
  709. ("12.6", "nantong12.6"),
  710. ("nantong12.5", "12.5"),
  711. ("nantong13.1.1", "13.1.1"),
  712. ("nantong13.1.2" , "13.1.2"),
  713. ("nantong13.1.3", "13.1.3"),
  714. ("nantong13.2.2", "13.2.2"),
  715. ("nantong13.3.1", "13.3.1"),
  716. ("nantong13.3.2", "13.3.2"),
  717. ("13.3.3" ,"nantong13.3.3"),
  718. ("13.4.4", "nantong13.4.4"),
  719. ("nantong13.5.1", "13.5.1"),
  720. ("13.5.4", "nantong13.5.4"),
  721. ("nantong14.3.8", "14.3.8"),
  722. ("14.4.4", "nantong14.4.4"),
  723. ("14.4.6", "nantong14.4.6"),
  724. ("nantong15.3.1", "15.3.1"),
  725. ("16.2", "nantong16.2"),
  726. ("17.1.3.2", "nantong17.1.3.2"),
  727. ("17.1.3.3","nantong17.1.3.3"),
  728. ("17.1.3.4","nantong17.1.3.4"),
  729. ("18.3.3","nantong18.3.3"),
  730. ("18.3.2","nantong18.3.2"),
  731. ("18.5","nantong18.5"),
  732. ("18.6","nantong18.6"),
  733. ("18.15","nantong18.15"),
  734. ("20.1.1","nantong20.1.1"),
  735. ("20.1.2.1","nantong20.1.2.1"),
  736. ("20.1.2.3","nantong20.1.2.3"),
  737. ("20.1.2.5","nantong20.1.2.5"),
  738. ("21.1.1.1","nantong21.1.1.1"),
  739. ("21.1.1.2","nantong21.1.1.2"),
  740. ("21.1.3.1","nantong21.1.3.1"),
  741. ("21.1.3.2","nantong21.1.3.2"),
  742. ("21.1.3.3","nantong21.1.3.3"),
  743. ("21.1.5","nantong21.1.5"),
  744. ("21.1.6","nantong21.1.6"),
  745. ("21.1.7","nantong21.1.7"),
  746. ("23.1.2","nantong23.1.2")
  747. ]
  748. match3=[('16.1', '16.2'), ('16.1.1', '16.2.1')]
  749. selected=[]
  750. notselected=[]
  751. #if data['bianma'].startswith('0108'): ##门窗
  752. # score = -1
  753. # for rank in ranks:
  754. # if label_name[d[rank['corpus_id']]].startswith('16-') and int(label_name[d[rank['corpus_id']]].split('-')[1]) < 308:
  755. # score = rank['score']
  756. # break
  757. # if score > -1 and score < cutoff:
  758. # cutoff = score - 0.1
  759. # if cutoff < 0.3:
  760. # cutoff = 0.3
  761. if data['bianma'].startswith('0106') and '钢丝网' not in data['mc']:##金属结构
  762. score = -1
  763. for rank in ranks:
  764. if label_name[d[rank['corpus_id']]].startswith('7-') and label_name[d[rank['corpus_id']]] != '7-62' and label_name[d[rank['corpus_id']]] !='7-63':
  765. score = rank['score']
  766. break
  767. if score > -1 and score < cutoff:
  768. cutoff = score - 0.01
  769. if cutoff < 0.3:
  770. cutoff = 0.3
  771. if data['bianma'].startswith('0111'):##楼地面
  772. score = -1
  773. for rank in ranks:
  774. if ('13.4' in d[rank['corpus_id']] or '14.3' in d[rank['corpus_id']]) and '块料面层' in d[rank['corpus_id']]:
  775. score = rank['score']
  776. break
  777. if score > -1 and score < cutoff and kuailiao:
  778. cutoff = score - 0.01
  779. if cutoff < 0.3:
  780. cutoff = 0.3
  781. if data['bianma'].startswith('0112'):##墙柱面
  782. score = -1
  783. for rank in ranks:
  784. if ('14.3' in d[rank['corpus_id']]) and '块料面层' in d[rank['corpus_id']]:
  785. score = rank['score']
  786. break
  787. if score > -1 and score < cutoff and kuailiao:
  788. cutoff = score - 0.01
  789. if cutoff < 0.3:
  790. cutoff = 0.3
  791. if data['bianma'].startswith('0113'):##天棚
  792. score = -1
  793. for rank in ranks:
  794. if '15.1.1' in d[rank['corpus_id']] or '15.1.2' in d[rank['corpus_id']] or '15.1.3' in d[rank['corpus_id']] or '15.1.4' in d[rank['corpus_id']] or '15.1.5' in d[rank['corpus_id']]:
  795. score = rank['score']
  796. break
  797. if score > -1 and score < cutoff and kuailiao:
  798. cutoff = score - 0.01
  799. if cutoff < 0.3:
  800. cutoff = 0.3
  801. #if data['bianma'].startswith('030408001'):##电力电缆
  802. # score = -1
  803. # for rank in ranks:
  804. # if '电缆' in d[rank['corpus_id']]:
  805. # score = rank['score']
  806. # break
  807. # if score > -1 and score < cutoff:
  808. # cutoff = score - 0.01
  809. # if cutoff < 0.3:
  810. # cutoff = 0.3
  811. if data['bianma'].startswith('030408006'):##电力电缆头
  812. score = -1
  813. for rank in ranks:
  814. if '电缆头' in d[rank['corpus_id']]:
  815. score = rank['score']
  816. break
  817. if score > -1 and score < cutoff:
  818. cutoff = score - 0.01
  819. if cutoff < 0.3:
  820. cutoff = 0.3
  821. ranks = [x for x in ranks if '电缆头' in d[x['corpus_id']]]
  822. #if data['bianma'].startswith('030108'):##风机安装
  823. # score = -1
  824. # for rank in ranks:
  825. # if '风机' in d[rank['corpus_id']]:
  826. # score = rank['score']
  827. # break
  828. # if score > -1 and score < cutoff:
  829. # cutoff = score - 0.01
  830. # if cutoff < 0.3:
  831. # cutoff = 0.3
  832. #if data['bianma'].startswith('030411'):##配管
  833. # score = -1
  834. # for rank in ranks:
  835. # if '第四册' in d[rank['corpus_id']]:
  836. # score = rank['score']
  837. # break
  838. # if score > -1 and score < cutoff:
  839. # cutoff = score - 0.01
  840. # if cutoff < 0.3:
  841. # cutoff = 0.3
  842. #if data['bianma'].startswith('031001006'):##水管
  843. # score = -1
  844. # for rank in ranks:
  845. # if '水管' in d[rank['corpus_id']]:
  846. # score = rank['score']
  847. # break
  848. # if score > -1 and score < cutoff:
  849. # cutoff = score - 0.01
  850. # if cutoff < 0.3:
  851. # cutoff = 0.3
  852. #if data['bianma'].startswith('030502007') or data['bianma'].startswith('030502008'):##光缆
  853. # score = -1
  854. # for rank in ranks:
  855. # if '敷设光缆' in d[rank['corpus_id']]:
  856. # score = rank['score']
  857. # break
  858. # if score > -1 and score < cutoff:
  859. # cutoff = score - 0.01
  860. # if cutoff < 0.3:
  861. # cutoff = 0.3
  862. #if data['bianma'].startswith('030801'):##低压管道
  863. # score = -1
  864. # for rank in ranks:
  865. # if '低压管道' in d[rank['corpus_id']]:
  866. # score = rank['score']
  867. # break
  868. # if score > -1 and score < cutoff:
  869. # cutoff = score - 0.01
  870. # if cutoff < 0.3:
  871. # cutoff = 0.3
  872. #if data['bianma'].startswith('030804'):##低压管件
  873. # score = -1
  874. # for rank in ranks:
  875. # if '低压管件' in d[rank['corpus_id']]:
  876. # score = rank['score']
  877. # break
  878. # if score > -1 and score < cutoff:
  879. # cutoff = score - 0.01
  880. # if cutoff < 0.3:
  881. # cutoff = 0.3
  882. #if '三通补强圈' in data['tz']:##三通补强圈
  883. # score = -1
  884. # for rank in ranks:
  885. # if '三通补强圈' in d[rank['corpus_id']]:
  886. # score = rank['score']
  887. # break
  888. # if score > -1 and score < cutoff:
  889. # cutoff = score - 0.01
  890. # if cutoff < 0.3:
  891. # cutoff = 0.3
  892. print("cutoff=" + str(cutoff))
  893. for entry in incremental:
  894. notselected = notselected + incremental[entry]
  895. notselected=[name_label[x] for x in notselected]
  896. for rank in ranks:
  897. print(f"{rank['score']} {d[rank['corpus_id']]}")
  898. if rank['score']<cutoff:
  899. continue
  900. if d[rank['corpus_id']] in notselected:
  901. if d[rank['corpus_id']] != '盐城补充定额 盐城补充定额2018 平面立面及其它防水 涂刷油类 水泥基渗透结晶防水每增减0.5mm厚':
  902. continue
  903. else:
  904. d[rank['corpus_id']]= '第十章 屋面及防水工程 10.2 平面立面及其它防水 10.2.1 涂刷油类 水泥基渗透结晶 防水材料 二~三遍(厚2mm)'
  905. if d[rank['corpus_id']] in notselected:
  906. continue
  907. print(f"select {rank['score']} {d[rank['corpus_id']]}")
  908. selected.append(d[rank['corpus_id']])
  909. hunningtu_group = []
  910. for entry in obj:
  911. if d[rank['corpus_id']] in obj[entry]:
  912. hunningtu_group=[entry]
  913. if len(hunningtu_group) > 0:
  914. for entry in match:
  915. if entry[0]==hunningtu_group[0] or entry[1] == hunningtu_group[0]:
  916. notselected = notselected + obj[entry[0]]
  917. notselected = notselected + obj[entry[1]]
  918. menchuang_group = []
  919. for entry in menchuang:
  920. if d[rank['corpus_id']] in menchuang[entry]:
  921. menchuang_group=[entry]
  922. if len(menchuang_group) > 0:
  923. for entry in match3:
  924. if entry[0]==menchuang_group[0] or entry[1] == menchuang_group[0]:
  925. notselected = notselected + menchuang[entry[0]]
  926. notselected = notselected + menchuang[entry[1]]
  927. nantong_group = []
  928. for entry in obj2:
  929. if d[rank['corpus_id']] in obj2[entry]:
  930. nantong_group=[entry]
  931. if len(nantong_group) > 0:
  932. for entry in match2:
  933. if entry[0]==nantong_group[0] or entry[1] == nantong_group[0]:
  934. notselected = notselected + obj2[entry[0]]
  935. notselected = notselected + obj2[entry[1]]
  936. for entry in basic:
  937. if d[rank['corpus_id']] in basic[entry]:
  938. notselected = notselected + basic[entry]
  939. notselected = [x for x in notselected if x not in selected]
  940. selected = list(set(selected))
  941. candidates=[]
  942. notselected=[]
  943. for rank in ranks:
  944. if d[rank['corpus_id']] in notselected:
  945. continue
  946. candidates.append(d[rank['corpus_id']])
  947. for entry in basic:
  948. if d[rank['corpus_id']] in basic[entry]:
  949. notselected = notselected + basic[entry]
  950. notselected = [x for x in notselected if x not in candidates]
  951. if len(selected) == 0 and not data['bianma'].startswith('0115'):
  952. selected = fallback(candidates, data, aiclient, qwclient, simpleclient, menchuang_collection, model)
  953. selected = postprocess(selected, data, aiclient, qwclient,simpleclient, label_name, name_dw, candidates,yqspecial)
  954. print("final selected")
  955. print(selected)
  956. result = [(label_name[x], huansuan_highlevel(data['bianma'], x, data['dw'], label_name[x], data['mc']+data['tz'])) for x in selected]
  957. print("after haunsuan")
  958. print(result)
  959. result = [(zuhe(x[0], label, data['bianma']).replace(',',''), x[1]) for x in result]
  960. print("after zuhe")
  961. print(result)
  962. if data['bianma'].startswith('01'):
  963. result = [(x[0], x[1], dedata.read_singledexilie2(10, x[0])) for x in result]
  964. result = [(x[0], x[1], x[2], tihuan(x[0], x[2], label, aiclient, qwclient, simpleclient, data)) for x in result]
  965. else:
  966. result = [(x[0], x[1], buchong(aiclient, dedata.read_singledexilie2(30, x[0]), x[0], data['tz'])) for x in result]
  967. result = [(x[0], x[1], x[2], tihuan_az(x[0], x[2], label, aiclient, qwclient, simpleclient, data)) for x in result]
  968. fuzhu = [analyze(x[2]) for x in result]
  969. fuzhu = zip(selected, fuzhu)
  970. fuzhu = [x for x in fuzhu]
  971. if data['bianma'].startswith('01'):
  972. fuzhu_selected = [select_fuzhu(x, label, aiclient, qwclient, simpleclient) for x in fuzhu]
  973. else:
  974. fuzhu_selected = [select_fuzhu_az(x, label, aiclient, qwclient, simpleclient) for x in fuzhu]
  975. need = need_extra(data, aiclient, qwclient, simpleclient, result, name_label)
  976. replace={}
  977. if need:
  978. extra_info = extra(data, aiclient, qwclient, simpleclient, menchuang_collection, model, qita_collection)
  979. replace['04290241']=extra_info##桩
  980. replace['04290303']=extra_info
  981. else:
  982. extra_info = "无"
  983. fy=[]
  984. if data['bianma'].startswith('03') and '超高' in data['tz']:
  985. fy=feiyong_chaogao(data, [label_name[x] for x in selected], aiclient, qwclient, simpleclient)
  986. if len(fy) > 0:
  987. fy = dedata.read_singledexilie2(30, fy[0])
  988. else:
  989. fy = '{}'
  990. if data['bianma'].startswith('031301017'):##安装脚手架搭拆
  991. print(data['bh'])
  992. print(data['name'])
  993. qd=anzhuangjsj(data['name'], data['bh'], dbcollection)
  994. response = requests.post("http://localhost:3000/api/transform", json={'bianma': data['bianma'], 'mc': data['mc'], 'tz': data['tz'], 'dw': data['dw'], 'sl': data['sl'], 'n': data['n'], "extra": extra_info, 'result':qd, 'fuzhu': [], 'replace': replace, 'fy': fy})
  995. return {"result": response.json()}
  996. if '高强螺栓' in extra_info:
  997. response = requests.post("http://localhost:3000/api/transform", json={'bianma': data['bianma'], 'mc': data['mc'], 'tz': data['tz'], 'dw': data['dw'], 'sl': data['sl'], 'n': data['n'], "extra": extra_info, 'result': [], 'fuzhu': fuzhu_selected, 'replace': replace, 'fy': '{}'})
  998. return {"result": response.json()}
  999. else:
  1000. response = requests.post("http://localhost:3000/api/transform", json={'bianma': data['bianma'], 'mc': data['mc'], 'tz': data['tz'], 'dw': data['dw'], 'sl': data['sl'], 'n': data['n'], "extra": extra_info, 'result': result, 'fuzhu': fuzhu_selected, 'replace': replace, 'fy': fy})
  1001. return {"result": response.json()}